Skip to content

Commit

Permalink
test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
strehle committed Jul 13, 2024
1 parent 68693c9 commit a6f467e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;
Expand Down Expand Up @@ -60,4 +61,19 @@ public void setMaxUsers() {
userConfig.setMaxUsers(100);
assertEquals(100, userConfig.getMaxUsers());
}

@Test
public void testDefaultOrigin() {
UserConfig userConfig = new UserConfig();
assertTrue(userConfig.isAllowOriginLoop());
assertFalse(userConfig.isCheckOriginEnabled());
}

@Test
public void testOriginLoop() {
UserConfig userConfig = new UserConfig();
assertTrue(userConfig.isAllowOriginLoop());
userConfig.setAllowOriginLoop(false);
assertFalse(userConfig.isCheckOriginEnabled());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void retrieve_by_issuer_search() throws Exception {
IdentityProvider<OIDCIdentityProviderDefinition> activeExternalOAuthProvider = configurator.retrieveByIssuer(issuer, IdentityZone.getUaaZoneId());

assertEquals(issuer, activeExternalOAuthProvider.getConfig().getIssuer());
verify(configurator, times(1)).overlay(eq(config));
verify(configurator, times(1)).overlay(config);
verify(configurator, times(1)).retrieveByExternId(anyString(), anyString(), anyString());
}

Expand All @@ -216,13 +216,13 @@ void retrieve_by_issuer_legacy() throws Exception {
IdentityProvider<OIDCIdentityProviderDefinition> activeExternalOAuthProvider = configurator.retrieveByIssuer(issuer, "customer");

assertEquals(issuer, activeExternalOAuthProvider.getConfig().getIssuer());
verify(configurator, times(1)).overlay(eq(config));
verify(configurator, times(1)).overlay(config);
verify(configurator, times(1)).retrieveByExternId(anyString(), anyString(), anyString());
verify(configurator, times(1)).retrieveAll(eq(true), anyString());
}

@Test
void retrieve_by_issuer_not_found_error() throws Exception {
void retrieve_by_issuer_not_found_error() {
when(mockIdentityProviderProvisioning.retrieveByExternId(anyString(), anyString(), anyString())).thenThrow(new EmptyResultDataAccessException(1));

String issuer = "https://accounts.google.com";
Expand All @@ -238,7 +238,7 @@ void retrieve_by_issuer_not_found_error() throws Exception {
}

@Test
void retrieve_by_issuer_null_error() throws Exception {
void retrieve_by_issuer_null_error() {
when(mockIdentityProviderProvisioning.retrieveByExternId(anyString(), anyString(), anyString())).thenReturn(null);

String issuer = "https://accounts.google.com";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,20 @@ public void testGetEntityID() throws Exception {
}

@Test
void testGetEntityIDExists() throws Exception {
void testGetEntityIDExists() {
bootstrap.setIdentityProviders(BootstrapSamlIdentityProviderDataTests.parseYaml(BootstrapSamlIdentityProviderDataTests.sampleYaml));
bootstrap.afterPropertiesSet();
for (SamlIdentityProviderDefinition def : bootstrap.getIdentityProviderDefinitions()) {
switch (def.getIdpEntityAlias()) {
case "okta-local-2": {
IdentityProvider idp2 = mock(IdentityProvider.class);
when(idp2.getType()).thenReturn(OriginKeys.SAML);
when(idp2.getConfig()).thenReturn(def.clone().setIdpEntityAlias("okta-local-1"));
when(provisioning.retrieveActive(anyString())).thenReturn(Arrays.asList(idp2));
assertThrowsWithMessageThat(
MetadataProviderException.class,
() -> configurator.validateSamlIdentityProviderDefinition(def, true),
startsWith("Duplicate entity ID:http://www.okta.com")
);
}
if ("okta-local-2".equalsIgnoreCase(def.getIdpEntityAlias())) {
IdentityProvider idp2 = mock(IdentityProvider.class);
when(idp2.getType()).thenReturn(OriginKeys.SAML);
when(idp2.getConfig()).thenReturn(def.clone().setIdpEntityAlias("okta-local-1"));
when(provisioning.retrieveActive(anyString())).thenReturn(Arrays.asList(idp2));
assertThrowsWithMessageThat(
MetadataProviderException.class,
() -> configurator.validateSamlIdentityProviderDefinition(def, true),
startsWith("Duplicate entity ID:http://www.okta.com")
);
}
}
}
Expand Down

0 comments on commit a6f467e

Please sign in to comment.