diff --git a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java index 3d8f0be40..4fdc6eb98 100644 --- a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java +++ b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java @@ -58,10 +58,14 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.format.annotation.DateTimeFormat.ISO; import org.springframework.format.datetime.DateFormatter; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.security.oauth2.provider.OAuth2Request; @@ -97,6 +101,8 @@ import static org.junit.Assert.fail; @RunWith(MockitoJUnitRunner.class) @SuppressWarnings(value = {"rawtypes", "unchecked"}) public class TestMITREidDataService_1_2 { + + private static Logger logger = LoggerFactory.getLogger(TestMITREidDataService_1_2.class); @Mock private OAuth2ClientRepository clientRepository; @@ -317,7 +323,7 @@ public class TestMITREidDataService_1_2 { " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); final Map fakeDb = new HashMap(); @@ -585,7 +591,7 @@ public class TestMITREidDataService_1_2 { "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -797,7 +803,7 @@ public class TestMITREidDataService_1_2 { " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -950,7 +956,7 @@ public class TestMITREidDataService_1_2 { "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -1091,7 +1097,7 @@ public class TestMITREidDataService_1_2 { " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -1316,7 +1322,7 @@ public class TestMITREidDataService_1_2 { " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -1389,7 +1395,7 @@ public class TestMITREidDataService_1_2 { OAuth2Request req1 = new OAuth2Request(new HashMap(), "client1", new ArrayList(), true, new HashSet(), new HashSet(), "http://foo.com", new HashSet(), null); - Authentication mockAuth1 = mock(Authentication.class, withSettings().serializable()); + Authentication mockAuth1 = new UsernamePasswordAuthenticationToken("user1", "pass1", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")); OAuth2Authentication auth1 = new OAuth2Authentication(req1, mockAuth1); AuthenticationHolderEntity holder1 = new AuthenticationHolderEntity(); @@ -1399,8 +1405,7 @@ public class TestMITREidDataService_1_2 { OAuth2Request req2 = new OAuth2Request(new HashMap(), "client2", new ArrayList(), true, new HashSet(), new HashSet(), "http://bar.com", new HashSet(), null); - Authentication mockAuth2 = mock(Authentication.class, withSettings().serializable()); - OAuth2Authentication auth2 = new OAuth2Authentication(req2, mockAuth2); + OAuth2Authentication auth2 = new OAuth2Authentication(req2, null); AuthenticationHolderEntity holder2 = new AuthenticationHolderEntity(); holder2.setId(2L); @@ -1408,15 +1413,15 @@ public class TestMITREidDataService_1_2 { List allAuthHolders = ImmutableList.of(holder1, holder2); - Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet()); - Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet()); - Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet()); - Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet()); - Mockito.when(authHolderRepository.getAll()).thenReturn(allAuthHolders); - Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet()); - Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet()); - Mockito.when(sysScopeRepository.getAll()).thenReturn(new HashSet()); - + when(clientRepository.getAllClients()).thenReturn(new HashSet()); + when(approvedSiteRepository.getAll()).thenReturn(new HashSet()); + when(wlSiteRepository.getAll()).thenReturn(new HashSet()); + when(blSiteRepository.getAll()).thenReturn(new HashSet()); + when(authHolderRepository.getAll()).thenReturn(allAuthHolders); + when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet()); + when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet()); + when(sysScopeRepository.getAll()).thenReturn(new HashSet()); + // do the data export StringWriter stringWriter = new StringWriter(); JsonWriter writer = new JsonWriter(stringWriter); @@ -1475,7 +1480,16 @@ public class TestMITREidDataService_1_2 { if (compare == null) { fail("Could not find matching authentication holder id: " + holder.get("id").getAsString()); } else { - assertTrue(holder.get("authentication").isJsonObject()); + assertTrue(holder.get("clientId").getAsString().equals(compare.getClientId())); + assertTrue(holder.get("approved").getAsBoolean() == compare.isApproved()); + assertTrue(holder.get("redirectUri").getAsString().equals(compare.getRedirectUri())); + if (compare.getUserAuth() != null) { + assertTrue(holder.get("savedUserAuthentication").isJsonObject()); + JsonObject savedAuth = holder.get("savedUserAuthentication").getAsJsonObject(); + assertTrue(savedAuth.get("name").getAsString().equals(compare.getUserAuth().getName())); + assertTrue(savedAuth.get("authenticated").getAsBoolean() == compare.getUserAuth().isAuthenticated()); + assertTrue(savedAuth.get("sourceClass").getAsString().equals(compare.getUserAuth().getSourceClass())); + } checked.add(compare); } } @@ -1515,14 +1529,14 @@ public class TestMITREidDataService_1_2 { "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " + "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [" + - "{\"id\":1,\"authentication\":{\"authorizationRequest\":{\"clientId\":\"client1\",\"redirectUri\":\"http://foo.com\"}," - + "\"userAuthentication\":null}}," + - "{\"id\":2,\"authentication\":{\"authorizationRequest\":{\"clientId\":\"client2\",\"redirectUri\":\"http://bar.com\"}," - + "\"userAuthentication\":null}}" + + "{\"id\":1,\"clientId\":\"client1\",\"redirectUri\":\"http://foo.com\"," + + "\"savedUserAuthentication\":null}," + + "{\"id\":2,\"clientId\":\"client2\",\"redirectUri\":\"http://bar.com\"," + + "\"savedUserAuthentication\":null}" + " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -1705,7 +1719,7 @@ public class TestMITREidDataService_1_2 { " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); @@ -1812,7 +1826,7 @@ public class TestMITREidDataService_1_2 { " ]" + "}"; - System.err.println(configJson); + logger.debug(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); final Map fakeRefreshTokenTable = new HashMap();