use of io.grpc.xds.internal.rbac.engine.GrpcAuthorizationEngine in project grpc-java by grpc.
the class RbacFilterTest method headerParser.
@Test
@SuppressWarnings({ "unchecked", "deprecation" })
public void headerParser() {
HeaderMatcher headerMatcher = HeaderMatcher.newBuilder().setName("party").setExactMatch("win").build();
List<Permission> permissionList = Arrays.asList(Permission.newBuilder().setHeader(headerMatcher).build());
List<Principal> principalList = Arrays.asList(Principal.newBuilder().setHeader(headerMatcher).build());
ConfigOrError<RbacConfig> result = parseOverride(permissionList, principalList);
assertThat(result.errorDetail).isNull();
ServerCall<Void, Void> serverCall = mock(ServerCall.class);
GrpcAuthorizationEngine engine = new GrpcAuthorizationEngine(result.config.authConfig());
AuthDecision decision = engine.evaluate(metadata("party", "win"), serverCall);
assertThat(decision.decision()).isEqualTo(GrpcAuthorizationEngine.Action.DENY);
}
use of io.grpc.xds.internal.rbac.engine.GrpcAuthorizationEngine in project grpc-java by grpc.
the class RbacFilterTest method ipPortParser.
@Test
@SuppressWarnings({ "unchecked", "deprecation" })
public void ipPortParser() {
CidrRange cidrRange = CidrRange.newBuilder().setAddressPrefix("10.10.10.0").setPrefixLen(UInt32Value.of(24)).build();
List<Permission> permissionList = Arrays.asList(Permission.newBuilder().setAndRules(Permission.Set.newBuilder().addRules(Permission.newBuilder().setDestinationIp(cidrRange).build()).addRules(Permission.newBuilder().setDestinationPort(9090).build()).build()).build());
List<Principal> principalList = Arrays.asList(Principal.newBuilder().setAndIds(Principal.Set.newBuilder().addIds(Principal.newBuilder().setDirectRemoteIp(cidrRange).build()).addIds(Principal.newBuilder().setRemoteIp(cidrRange).build()).addIds(Principal.newBuilder().setSourceIp(cidrRange).build()).build()).build());
ConfigOrError<?> result = parseRaw(permissionList, principalList);
assertThat(result.errorDetail).isNull();
ServerCall<Void, Void> serverCall = mock(ServerCall.class);
Attributes attributes = Attributes.newBuilder().set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, new InetSocketAddress("10.10.10.0", 1)).set(Grpc.TRANSPORT_ATTR_LOCAL_ADDR, new InetSocketAddress("10.10.10.0", 9090)).build();
when(serverCall.getAttributes()).thenReturn(attributes);
when(serverCall.getMethodDescriptor()).thenReturn(method().build());
GrpcAuthorizationEngine engine = new GrpcAuthorizationEngine(((RbacConfig) result.config).authConfig());
AuthDecision decision = engine.evaluate(new Metadata(), serverCall);
assertThat(decision.decision()).isEqualTo(GrpcAuthorizationEngine.Action.DENY);
}
Aggregations