Skip to content

Commit

Permalink
Add in a test case where a client only has a single SAML IDP.
Browse files Browse the repository at this point in the history
When redirected to the login page, this client should get automatically redirected to the SAML discovery process
Add in test case for hiding the username password field
https://www.pivotaltracker.com/story/show/91424952
[#91424952]
https://www.pivotaltracker.com/story/show/90062348
[#90062348]
  • Loading branch information
fhanik committed Apr 3, 2015
1 parent fa70dee commit f8f8966
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 72 deletions.
Expand Up @@ -37,6 +37,13 @@


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyCollection;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -116,7 +123,7 @@ public void testFilterIdpsForDefaultZone() throws Exception {
// mock IdentityProviderConfigurator // mock IdentityProviderConfigurator
List<IdentityProviderDefinition> idps = getIdps(); List<IdentityProviderDefinition> idps = getIdps();
IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class); IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class);
when(mockIDPConfigurator.getIdentityProviderDefinitionsForZone(IdentityZoneHolder.get())).thenReturn(idps); when(mockIDPConfigurator.getIdentityProviderDefinitions((List<String>) isNull(), eq(IdentityZone.getUaa()), eq(false))).thenReturn(idps);


LoginInfoEndpoint endpoint = getEndpoint(); LoginInfoEndpoint endpoint = getEndpoint();
endpoint.setIdpDefinitions(mockIDPConfigurator); endpoint.setIdpDefinitions(mockIDPConfigurator);
Expand All @@ -141,7 +148,7 @@ public void testFilterIdpsWithNoSavedRequest() throws Exception {
// mock IdentityProviderConfigurator // mock IdentityProviderConfigurator
List<IdentityProviderDefinition> idps = getIdps(); List<IdentityProviderDefinition> idps = getIdps();
IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class); IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class);
when(mockIDPConfigurator.getIdentityProviderDefinitionsForZone(IdentityZoneHolder.get())).thenReturn(idps); when(mockIDPConfigurator.getIdentityProviderDefinitions((List<String>) isNull(), eq(IdentityZone.getUaa()),eq(false))).thenReturn(idps);


LoginInfoEndpoint endpoint = getEndpoint(); LoginInfoEndpoint endpoint = getEndpoint();
endpoint.setIdpDefinitions(mockIDPConfigurator); endpoint.setIdpDefinitions(mockIDPConfigurator);
Expand All @@ -166,18 +173,19 @@ public void testFilterIDPsForAuthcodeClientInDefaultZone() throws Exception {
// mock session and saved request // mock session and saved request
MockHttpServletRequest request = getMockHttpServletRequest(); MockHttpServletRequest request = getMockHttpServletRequest();


List<String> allowedProviders = Arrays.asList("my-client-awesome-idp"); List<String> allowedProviders = Arrays.asList("my-client-awesome-idp1", "my-client-awesome-idp2");


// mock Client service // mock Client service
BaseClientDetails clientDetails = new BaseClientDetails(); BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("client-id"); clientDetails.setClientId("client-id");
clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, Arrays.asList("my-client-awesome-idp")); clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, new LinkedList<>(allowedProviders));
ClientDetailsService clientDetailsService = mock(ClientDetailsService.class); ClientDetailsService clientDetailsService = mock(ClientDetailsService.class);
when(clientDetailsService.loadClientByClientId("client-id")).thenReturn(clientDetails); when(clientDetailsService.loadClientByClientId("client-id")).thenReturn(clientDetails);


// mock IdentityProviderConfigurator // mock IdentityProviderConfigurator
List<IdentityProviderDefinition> clientIDPs = new LinkedList<>(); List<IdentityProviderDefinition> clientIDPs = new LinkedList<>();
clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp", "uaa")); clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp1", "uaa"));
clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp2", "uaa"));
IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class); IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class);
when(mockIDPConfigurator.getIdentityProviderDefinitions(allowedProviders, IdentityZoneHolder.get(), false)).thenReturn(clientIDPs); when(mockIDPConfigurator.getIdentityProviderDefinitions(allowedProviders, IdentityZoneHolder.get(), false)).thenReturn(clientIDPs);


Expand All @@ -188,10 +196,49 @@ public void testFilterIDPsForAuthcodeClientInDefaultZone() throws Exception {
endpoint.loginForHtml(model, null, request); endpoint.loginForHtml(model, null, request);


List<IdentityProviderDefinition> idpDefinitions = (List<IdentityProviderDefinition>) model.asMap().get("idpDefinitions"); List<IdentityProviderDefinition> idpDefinitions = (List<IdentityProviderDefinition>) model.asMap().get("idpDefinitions");
assertEquals(1, idpDefinitions.size()); assertEquals(2, idpDefinitions.size());


IdentityProviderDefinition clientIdp = idpDefinitions.iterator().next(); IdentityProviderDefinition clientIdp = idpDefinitions.iterator().next();
assertEquals("my-client-awesome-idp", clientIdp.getIdpEntityAlias()); assertEquals("my-client-awesome-idp1", clientIdp.getIdpEntityAlias());
assertEquals(true, clientIdp.isShowSamlLink());
}

@Test
public void testFilterIDPsForAuthcodeClientInOtherZone() throws Exception {
// mock session and saved request
MockHttpServletRequest request = getMockHttpServletRequest();

IdentityZone zone = MultitenancyFixture.identityZone("other-zone", "other-zone");
IdentityZoneHolder.set(zone);

List<String> allowedProviders = Arrays.asList("my-client-awesome-idp1", "my-client-awesome-idp2");

// mock Client service
BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("client-id");
clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, new LinkedList<>(allowedProviders));
ClientDetailsService clientDetailsService = mock(ClientDetailsService.class);
when(clientDetailsService.loadClientByClientId("client-id")).thenReturn(clientDetails);

// mock IdentityProviderConfigurator
List<IdentityProviderDefinition> clientIDPs = new LinkedList<>();
clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp1", "uaa"));
clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp2", "uaa"));
IdentityProviderConfigurator mockIDPConfigurator = mock(IdentityProviderConfigurator.class);
when(mockIDPConfigurator.getIdentityProviderDefinitions(eq(allowedProviders), eq(zone), eq(true))).thenReturn(clientIDPs);


LoginInfoEndpoint endpoint = getEndpoint();
endpoint.setClientDetailsService(clientDetailsService);
endpoint.setIdpDefinitions(mockIDPConfigurator);
Model model = new ExtendedModelMap();
endpoint.loginForHtml(model, null, request);

List<IdentityProviderDefinition> idpDefinitions = (List<IdentityProviderDefinition>) model.asMap().get("idpDefinitions");
assertEquals(2, idpDefinitions.size());

IdentityProviderDefinition clientIdp = idpDefinitions.iterator().next();
assertEquals("my-client-awesome-idp1", clientIdp.getIdpEntityAlias());
assertEquals(true, clientIdp.isShowSamlLink()); assertEquals(true, clientIdp.isShowSamlLink());
} }


Expand Down Expand Up @@ -243,10 +290,8 @@ private LoginInfoEndpoint getEndpoint() {


private List<IdentityProviderDefinition> getIdps() { private List<IdentityProviderDefinition> getIdps() {
List<IdentityProviderDefinition> idps = new LinkedList<>(); List<IdentityProviderDefinition> idps = new LinkedList<>();

idps.add(createIdentityProviderDefinition("awesome-idp", "uaa")); idps.add(createIdentityProviderDefinition("awesome-idp", "uaa"));
idps.add(createIdentityProviderDefinition("my-client-awesome-idp", "uaa")); idps.add(createIdentityProviderDefinition("my-client-awesome-idp", "uaa"));

return idps; return idps;
} }


Expand Down

0 comments on commit f8f8966

Please sign in to comment.