/** * Returns {@link #getCognitoIdentityId()}. * * @return name */ @Override default String getName() { return getCognitoIdentityId(); } }
@Test public void createPrincipal_AllDateGiven_ShouldCreatePrincipal() { GatewayRequest request = createRequestMock("cognitoAuthenticationType", "cognitoIdentityId", "cognitoIdentityPoolId", "cognitoAuthenticationProvider", "userArn", "user", "accessKey", "caller"); CognitoIdentityPrincipal principal = (CognitoIdentityPrincipal) createSecurityContextFactory(request) .createPrincipal(); assertEquals("cognitoIdentityId", principal.getName()); assertEquals("cognitoIdentityId", principal.getCognitoIdentityId()); assertEquals("cognitoAuthenticationType", principal.getCognitoAuthenticationType()); assertEquals("cognitoAuthenticationProvider", principal.getCognitoAuthenticationProvider()); assertEquals("cognitoIdentityPoolId", principal.getCognitoIdentityPoolId()); assertEquals("userArn", principal.getUserArn()); assertEquals("user", principal.getUser()); assertEquals("accessKey", principal.getAccessKey()); assertEquals("caller", principal.getCaller()); }
@Test public void testNameReturnsCognitoIdentityId() { CognitoIdentityPrincipal principal = mock(CognitoIdentityPrincipal.class); when(principal.getName()).thenCallRealMethod(); when(principal.getCognitoIdentityId()).thenReturn("cognitoIdentityId"); assertEquals("cognitoIdentityId", principal.getName()); }
private static void assertCognitoIdentityPrincipal(Principal principal) { CognitoIdentityPrincipal cognitoIdentityPrincipal = (CognitoIdentityPrincipal) principal; assertEquals(TEST_COGNITO_IDENTITY_AUTH_TYPE, cognitoIdentityPrincipal.getCognitoAuthenticationType()); assertEquals(TEST_COGNITO_IDENTITY_IDENTITY_ID, cognitoIdentityPrincipal.getCognitoIdentityId()); }
@Test public void createPrincipal_MinimalDateGiven_ShouldCreatePrincipal() { GatewayRequest request = createRequestMock("cognitoAuthenticationType", "cognitoIdentityId", null, null, null, null, null, null); CognitoIdentityPrincipal principal = (CognitoIdentityPrincipal) createSecurityContextFactory(request) .createPrincipal(); assertEquals("cognitoIdentityId", principal.getName()); assertEquals("cognitoIdentityId", principal.getCognitoIdentityId()); assertEquals("cognitoAuthenticationType", principal.getCognitoAuthenticationType()); assertNull(principal.getCognitoAuthenticationProvider()); assertNull(principal.getCognitoIdentityPoolId()); assertNull(principal.getUserArn()); assertNull(principal.getUser()); assertNull(principal.getAccessKey()); assertNull(principal.getCaller()); }