@Test public void testCreateFromIdTokenClaims_EmptyClaims() throws ParseException { final ReadOnlyJWTClaimsSet claimSet = PowerMock.createMock(ReadOnlyJWTClaimsSet.class); EasyMock.expect(claimSet.getAllClaims()).andReturn(new HashMap<String, Object>()).times(1); EasyMock.replay(claimSet); Assert.assertNull(UserInfo.createFromIdTokenClaims(claimSet)); PowerMock.verifyAll(); }
@Test public void testCreateFromIdTokenClaims_HasEmailSubjectPasswordClaims() throws ParseException { final ReadOnlyJWTClaimsSet claimSet = PowerMock.createMock(ReadOnlyJWTClaimsSet.class); final Map<String, Object> map = new HashMap<String, Object>(); map.put("", ""); EasyMock.expect(claimSet.getAllClaims()).andReturn(map).times(1); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_OBJECT_ID)) .andReturn(null) .times(1); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_SUBJECT)) .andReturn("sub") .times(2); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_UPN)) .andReturn(null) .times(1); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_EMAIL)) .andReturn("*****@*****.**") .times(2); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_GIVEN_NAME)) .andReturn("test") .times(1); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_FAMILY_NAME)) .andReturn("value") .times(1); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_IDENTITY_PROVIDER)) .andReturn("idp") .times(1); EasyMock.expect(claimSet.getStringClaim(AuthenticationConstants.ID_TOKEN_PASSWORD_CHANGE_URL)) .andReturn("url") .times(2); EasyMock.expect(claimSet.getClaim(AuthenticationConstants.ID_TOKEN_PASSWORD_EXPIRES_ON)) .andReturn("5000") .times(2); EasyMock.replay(claimSet); final UserInfo ui = UserInfo.createFromIdTokenClaims(claimSet); Assert.assertNotNull(ui); Assert.assertEquals("*****@*****.**", ui.getDispayableId()); Assert.assertEquals("sub", ui.getUniqueId()); Assert.assertEquals("test", ui.getGivenName()); Assert.assertEquals("value", ui.getFamilyName()); Assert.assertEquals("idp", ui.getIdentityProvider()); Assert.assertEquals("url", ui.getPasswordChangeUrl()); Assert.assertNotNull(ui.getPasswordExpiresOn()); PowerMock.verifyAll(); }