@@ -576,21 +576,20 @@ public void testReasonerSpecificity() {
576576
577577 for (ReasonerTestCase tc : testCases ) {
578578 var attributeService = mock (AttributesServiceClient .class );
579- when (attributeService .getAttributeValuesByFqnsBlocking (any (), any ())).thenReturn (
580- new UnaryBlockingCall <>() {
581- @ Override
582- public ResponseMessage <GetAttributeValuesByFqnsResponse > execute () {
583- return new ResponseMessage .Success <>(
584- getResponse (GetAttributeValuesByFqnsRequest .newBuilder ()
585- .addAllFqns (tc .getPolicy ().stream ().map (AttributeValueFQN ::toString ).collect (Collectors .toList ()))
586- .build ()), Collections .emptyMap (), Collections .emptyMap ());
587- }
588-
589- @ Override
590- public void cancel () {
591- }
579+ when (attributeService .getAttributeValuesByFqnsBlocking (any (), any ())).thenAnswer (invocation -> {
580+ var request = (GetAttributeValuesByFqnsRequest ) invocation .getArgument (0 );
581+ return new UnaryBlockingCall <GetAttributeValuesByFqnsResponse >() {
582+ @ Override
583+ public ResponseMessage <GetAttributeValuesByFqnsResponse > execute () {
584+ return new ResponseMessage .Success <>(getResponse (request ), Collections .emptyMap (), Collections .emptyMap ());
592585 }
593- );
586+
587+ @ Override
588+ public void cancel () {
589+ }
590+ };
591+ });
592+
594593
595594 Granter reasoner = Autoconfigure .newGranterFromService (attributeService , new KASKeyCache (),
596595 tc .getPolicy ().toArray (new AttributeValueFQN [0 ]));
@@ -900,49 +899,38 @@ void testKeyCacheFromGrants() throws InterruptedException, ExecutionException {
900899 .setUri ("https://example.com/kas" )
901900 .build ();
902901
903- // AttributesServiceGrpc.AttributesServiceFutureStub attributeGrpcStub = mock(
904- // AttributesServiceGrpc.AttributesServiceFutureStub.class);
905- // lenient().when(attributeGrpcStub.getAttributeValuesByFqns(any(GetAttributeValuesByFqnsRequest.class)))
906- // .thenAnswer(
907- // invocation -> {
908- // GetAttributeValuesByFqnsResponse resp = getResponseWithGrants(
909- // (GetAttributeValuesByFqnsRequest) invocation.getArguments()[0], List.of(kas1));
910- // SettableFuture<GetAttributeValuesByFqnsResponse> future = SettableFuture.create();
911- // future.set(resp); // Set the request as the future's result
912- // return future;
913- // });
914- // AttributesServiceClient attributeGrpcStub = mock(AttributesServiceClient.class);
915- // lenient().when(attributeGrpcStub.getAttributeValuesByFqns(any(), any()))
916- // .thenAnswer(
917- // invocation -> {
918- // GetAttributeValuesByFqnsResponse resp = getResponseWithGrants(
919- // (GetAttributeValuesByFqnsRequest) invocation.getArguments()[0], List.of(kas1));
920- // SettableFuture<GetAttributeValuesByFqnsResponse> future = SettableFuture.create();
921- // future.set(resp); // Set the request as the future's result
922- // return future;
923- // });
924-
925- // KASKeyCache keyCache = new KASKeyCache();
926- //
927- // Granter reasoner = Autoconfigure.newGranterFromService(attributeGrpcStub, keyCache,
928- // List.of(clsS, rel2gbr, rel2usa, n2kHCS, n2kSI).toArray(new AttributeValueFQN[0]));
929- // assertThat(reasoner).isNotNull();
930- //
931- // // Verify that the key was stored in the cache
932- // Config.KASInfo storedKASInfo = keyCache.get("https://example.com/kas", "ec:secp256r1");
933- // assertNotNull(storedKASInfo);
934- // assertEquals("https://example.com/kas", storedKASInfo.URL);
935- // assertEquals("test-kid", storedKASInfo.KID);
936- // assertEquals("ec:secp256r1", storedKASInfo.Algorithm);
937- // assertEquals("public-key-pem", storedKASInfo.PublicKey);
938- //
939- // Config.KASInfo storedKASInfo2 = keyCache.get("https://example.com/kas", "rsa:2048");
940- // assertNotNull(storedKASInfo2);
941- // assertEquals("https://example.com/kas", storedKASInfo2.URL);
942- // assertEquals("test-kid-2", storedKASInfo2.KID);
943- // assertEquals("rsa:2048", storedKASInfo2.Algorithm);
944- // assertEquals("public-key-pem-2", storedKASInfo2.PublicKey);
945- //
902+ AttributesServiceClient attributesServiceClient = mock (AttributesServiceClient .class );
903+ when (attributesServiceClient .getAttributeValuesByFqnsBlocking (any (), any ())).thenAnswer (invocation -> {
904+ var request = (GetAttributeValuesByFqnsRequest )invocation .getArgument (0 );
905+ return new UnaryBlockingCall <GetAttributeValuesByFqnsResponse >(){
906+ @ Override
907+ public ResponseMessage <GetAttributeValuesByFqnsResponse > execute () {
908+ return new ResponseMessage .Success <>(getResponseWithGrants (request , List .of (kas1 )), Collections .emptyMap (), Collections .emptyMap ());
909+ }
910+ @ Override public void cancel () {}
911+ };
912+ });
913+
914+ KASKeyCache keyCache = new KASKeyCache ();
915+
916+ Granter reasoner = Autoconfigure .newGranterFromService (attributesServiceClient , keyCache ,
917+ List .of (clsS , rel2gbr , rel2usa , n2kHCS , n2kSI ).toArray (new AttributeValueFQN [0 ]));
918+ assertThat (reasoner ).isNotNull ();
919+
920+ // Verify that the key was stored in the cache
921+ Config .KASInfo storedKASInfo = keyCache .get ("https://example.com/kas" , "ec:secp256r1" );
922+ assertNotNull (storedKASInfo );
923+ assertEquals ("https://example.com/kas" , storedKASInfo .URL );
924+ assertEquals ("test-kid" , storedKASInfo .KID );
925+ assertEquals ("ec:secp256r1" , storedKASInfo .Algorithm );
926+ assertEquals ("public-key-pem" , storedKASInfo .PublicKey );
927+
928+ Config .KASInfo storedKASInfo2 = keyCache .get ("https://example.com/kas" , "rsa:2048" );
929+ assertNotNull (storedKASInfo2 );
930+ assertEquals ("https://example.com/kas" , storedKASInfo2 .URL );
931+ assertEquals ("test-kid-2" , storedKASInfo2 .KID );
932+ assertEquals ("rsa:2048" , storedKASInfo2 .Algorithm );
933+ assertEquals ("public-key-pem-2" , storedKASInfo2 .PublicKey );
946934 }
947935
948936}
0 commit comments