exceptionfactory commented on code in PR #11463:
URL: https://github.com/apache/nifi/pull/11463#discussion_r3722487597


##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/test/java/org/apache/nifi/oauth2/JWTBearerOAuth2AccessTokenProviderTest.java:
##########
@@ -275,6 +276,56 @@ void testEdvsOctet() throws Exception {
         runner.assertValid(provider);
     }
 
+    @Test
+    void testValidationFailsWhenSelfSignedStrategyMissingPrivateKeyService() {
+        // default strategy is Self-Signed; without a Private Key Service 
configured, validation must fail
+        final Collection<ValidationResult> validations = 
runner.validate(provider);
+        assertTrue(validations.stream().anyMatch(validation -> 
validation.getSubject().equals(JWTBearerOAuth2AccessTokenProvider.PRIVATE_KEY_SERVICE.getDisplayName())));
+    }
+
+    @Test
+    void 
testValidationFailsWhenExternalProviderStrategyMissingExternalAssertionProvider()
 {
+        runner.setProperty(provider, 
JWTBearerOAuth2AccessTokenProvider.ASSERTION_STRATEGY, 
AssertionStrategy.EXTERNAL_PROVIDER.name());
+
+        final Collection<ValidationResult> validations = 
runner.validate(provider);
+        assertTrue(validations.stream().anyMatch(validation -> 
validation.getSubject().equals(JWTBearerOAuth2AccessTokenProvider.EXTERNAL_ASSERTION_PROVIDER.getDisplayName())));
+    }
+
+    @Test
+    void testExternalAssertionProviderTokenIsUsedAsAssertion() throws 
Exception {
+        setExternalAssertionProviderMock("external-token-value");
+
+        runner.enableControllerService(provider);
+        provider.getAccessDetails();
+
+        // the external provider's token is used directly as the assertion, no 
local JWT is built or signed
+        assertNull(provider.getJwsHeader());
+        assertNull(provider.getJwtClaimsSet());
+
+        final Map<String, String> formParams = provider.getFormParams();
+        assertEquals("external-token-value", 
formParams.get("customAssertionField"));
+        assertEquals("urn:ietf:params:oauth:grant-type:jwt-bearer", 
formParams.get("grant_type"));
+    }
+
+    @Test
+    void testVerifySurfacesExternalProviderFailureCause() throws Exception {
+        runner.setProperty(provider, 
JWTBearerOAuth2AccessTokenProvider.ASSERTION_STRATEGY, 
AssertionStrategy.EXTERNAL_PROVIDER.name());
+
+        final OAuth2AccessTokenProvider externalProvider = 
mock(OAuth2AccessTokenProvider.class);
+        lenient().when(externalProvider.getAccessDetails()).thenThrow(new 
IllegalStateException("external provider unavailable"));
+        
lenient().when(externalProvider.getIdentifier()).thenReturn("externalAssertionProvider");

Review Comment:
   It would also be helpful to declare a static value for 
`externalAssertionProvider` and reuse across methods



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to