|
|
|
@ -78,14 +78,13 @@ TEST_F(AuthorizationMatchersTest, AndAuthorizationMatcherFailedMatch) { |
|
|
|
|
TEST_F(AuthorizationMatchersTest, NotAndAuthorizationMatcher) { |
|
|
|
|
args_.AddPairToMetadata(":path", "/expected/foo"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
StringMatcher string_matcher = |
|
|
|
|
std::vector<std::unique_ptr<Rbac::Permission>> ids; |
|
|
|
|
ids.push_back(absl::make_unique<Rbac::Permission>( |
|
|
|
|
Rbac::Permission::RuleType::kPath, |
|
|
|
|
StringMatcher::Create(StringMatcher::Type::kExact, |
|
|
|
|
/*matcher=*/"/expected/foo", |
|
|
|
|
/*case_sensitive=*/false) |
|
|
|
|
.value(); |
|
|
|
|
std::vector<std::unique_ptr<Rbac::Permission>> ids; |
|
|
|
|
ids.push_back(absl::make_unique<Rbac::Permission>( |
|
|
|
|
Rbac::Permission::RuleType::kPath, std::move(string_matcher))); |
|
|
|
|
.value())); |
|
|
|
|
AndAuthorizationMatcher matcher(std::move(ids), /*not_rule=*/true); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
@ -94,13 +93,12 @@ TEST_F(AuthorizationMatchersTest, OrAuthorizationMatcherSuccessfulMatch) { |
|
|
|
|
args_.AddPairToMetadata("foo", "bar"); |
|
|
|
|
args_.SetLocalEndpoint("ipv4:255.255.255.255:123"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
HeaderMatcher header_matcher = |
|
|
|
|
HeaderMatcher::Create(/*name=*/"foo", HeaderMatcher::Type::kExact, |
|
|
|
|
/*matcher=*/"bar") |
|
|
|
|
.value(); |
|
|
|
|
std::vector<std::unique_ptr<Rbac::Permission>> rules; |
|
|
|
|
rules.push_back(absl::make_unique<Rbac::Permission>( |
|
|
|
|
Rbac::Permission::RuleType::kHeader, header_matcher)); |
|
|
|
|
Rbac::Permission::RuleType::kHeader, |
|
|
|
|
HeaderMatcher::Create(/*name=*/"foo", HeaderMatcher::Type::kExact, |
|
|
|
|
/*matcher=*/"bar") |
|
|
|
|
.value())); |
|
|
|
|
rules.push_back(absl::make_unique<Rbac::Permission>( |
|
|
|
|
Rbac::Permission::RuleType::kDestPort, /*port=*/456)); |
|
|
|
|
OrAuthorizationMatcher matcher(std::move(rules)); |
|
|
|
@ -211,7 +209,9 @@ TEST_F(AuthorizationMatchersTest, NotPathAuthorizationMatcher) { |
|
|
|
|
args_.AddPairToMetadata(":path", "expected/path"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
PathAuthorizationMatcher matcher( |
|
|
|
|
StringMatcher::Create(StringMatcher::Type::kExact, "expected/path", false) |
|
|
|
|
StringMatcher::Create(StringMatcher::Type::kExact, |
|
|
|
|
/*matcher=*/"expected/path", |
|
|
|
|
/*case_sensitive=*/false) |
|
|
|
|
.value(), |
|
|
|
|
/*not_rule=*/true); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
@ -281,6 +281,60 @@ TEST_F(AuthorizationMatchersTest, NotHeaderAuthorizationMatcher) { |
|
|
|
|
EXPECT_TRUE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, |
|
|
|
|
IpAuthorizationMatcherLocalIpSuccessfulMatch) { |
|
|
|
|
args_.SetLocalEndpoint("ipv4:1.2.3.4:123"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
IpAuthorizationMatcher matcher( |
|
|
|
|
IpAuthorizationMatcher::Type::kDestIp, |
|
|
|
|
Rbac::CidrRange(/*address_prefix=*/"1.7.8.9", /*prefix_len=*/8)); |
|
|
|
|
EXPECT_TRUE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, IpAuthorizationMatcherLocalIpFailedMatch) { |
|
|
|
|
args_.SetLocalEndpoint("ipv4:1.2.3.4:123"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
IpAuthorizationMatcher matcher( |
|
|
|
|
IpAuthorizationMatcher::Type::kDestIp, |
|
|
|
|
Rbac::CidrRange(/*address_prefix=*/"1.2.3.9", /*prefix_len=*/32)); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, IpAuthorizationMatcherPeerIpSuccessfulMatch) { |
|
|
|
|
args_.SetPeerEndpoint("ipv6:[1:2:3::]:456"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
IpAuthorizationMatcher matcher( |
|
|
|
|
IpAuthorizationMatcher::Type::kSourceIp, |
|
|
|
|
Rbac::CidrRange(/*address_prefix=*/"1:2:4::", /*prefix_len=*/32)); |
|
|
|
|
EXPECT_TRUE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, IpAuthorizationMatcherPeerIpFailedMatch) { |
|
|
|
|
args_.SetPeerEndpoint("ipv6:[1:2::]:456"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
IpAuthorizationMatcher matcher( |
|
|
|
|
IpAuthorizationMatcher::Type::kSourceIp, |
|
|
|
|
Rbac::CidrRange(/*address_prefix=*/"1:3::", /*prefix_len=*/32)); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, |
|
|
|
|
IpAuthorizationMatcherUnsupportedIpFailedMatch) { |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
IpAuthorizationMatcher matcher(IpAuthorizationMatcher::Type::kRemoteIp, {}); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, NotIpAuthorizationMatcherSuccessfulMatch) { |
|
|
|
|
args_.SetLocalEndpoint("ipv4:1.2.3.4:123"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
IpAuthorizationMatcher matcher( |
|
|
|
|
IpAuthorizationMatcher::Type::kDestIp, |
|
|
|
|
Rbac::CidrRange(/*address_prefix=*/"1.7.8.9", /*prefix_len=*/8), |
|
|
|
|
/*not_rule=*/true); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, PortAuthorizationMatcherSuccessfulMatch) { |
|
|
|
|
args_.SetLocalEndpoint("ipv4:255.255.255.255:123"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
@ -355,6 +409,36 @@ TEST_F(AuthorizationMatchersTest, AuthenticatedMatcherFailedSpiffeIdMatches) { |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, AuthenticatedMatcherSuccessfulDnsSanMatches) { |
|
|
|
|
args_.AddPropertyToAuthContext(GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, |
|
|
|
|
GRPC_SSL_TRANSPORT_SECURITY_TYPE); |
|
|
|
|
args_.AddPropertyToAuthContext(GRPC_PEER_DNS_PROPERTY_NAME, |
|
|
|
|
"foo.test.domain.com"); |
|
|
|
|
args_.AddPropertyToAuthContext(GRPC_PEER_DNS_PROPERTY_NAME, |
|
|
|
|
"bar.test.domain.com"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
AuthenticatedAuthorizationMatcher matcher( |
|
|
|
|
StringMatcher::Create(StringMatcher::Type::kExact, |
|
|
|
|
/*matcher=*/"bar.test.domain.com", |
|
|
|
|
/*case_sensitive=*/false) |
|
|
|
|
.value()); |
|
|
|
|
EXPECT_TRUE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, AuthenticatedMatcherFailedDnsSanMatches) { |
|
|
|
|
args_.AddPropertyToAuthContext(GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, |
|
|
|
|
GRPC_SSL_TRANSPORT_SECURITY_TYPE); |
|
|
|
|
args_.AddPropertyToAuthContext(GRPC_PEER_DNS_PROPERTY_NAME, |
|
|
|
|
"foo.test.domain.com"); |
|
|
|
|
EvaluateArgs args = args_.MakeEvaluateArgs(); |
|
|
|
|
AuthenticatedAuthorizationMatcher matcher( |
|
|
|
|
StringMatcher::Create(StringMatcher::Type::kExact, |
|
|
|
|
/*matcher=*/"bar.test.domain.com", |
|
|
|
|
/*case_sensitive=*/false) |
|
|
|
|
.value()); |
|
|
|
|
EXPECT_FALSE(matcher.Matches(args)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(AuthorizationMatchersTest, AuthenticatedMatcherFailedNothingMatches) { |
|
|
|
|
args_.AddPropertyToAuthContext(GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, |
|
|
|
|
GRPC_SSL_TRANSPORT_SECURITY_TYPE); |
|
|
|
|