Search in sources :

Example 1 with KeyService

use of org.apache.nifi.admin.service.KeyService in project nifi by apache.

the class JwtServiceTest method testShouldNotGenerateTokenWithMissingKey.

@Test(expected = JwtException.class)
public void testShouldNotGenerateTokenWithMissingKey() throws Exception {
    // Arrange
    final int EXPIRATION_MILLIS = 60000;
    LoginAuthenticationToken loginAuthenticationToken = new LoginAuthenticationToken("alopresto", EXPIRATION_MILLIS, "MockIdentityProvider");
    logger.debug("Generating token for " + loginAuthenticationToken);
    // Set up the bad key service
    KeyService missingKeyService = Mockito.mock(KeyService.class);
    when(missingKeyService.getOrCreateKey(anyString())).thenThrow(new AdministrationException("Could not find a " + "key for that user"));
    jwtService = new JwtService(missingKeyService);
    // Act
    jwtService.generateSignedToken(loginAuthenticationToken);
// Assert
// Should throw exception
}
Also used : LoginAuthenticationToken(org.apache.nifi.web.security.token.LoginAuthenticationToken) KeyService(org.apache.nifi.admin.service.KeyService) AdministrationException(org.apache.nifi.admin.service.AdministrationException) Test(org.junit.Test)

Aggregations

AdministrationException (org.apache.nifi.admin.service.AdministrationException)1 KeyService (org.apache.nifi.admin.service.KeyService)1 LoginAuthenticationToken (org.apache.nifi.web.security.token.LoginAuthenticationToken)1 Test (org.junit.Test)1