Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Rose
committed
Jun 5, 2023
1 parent
87e968e
commit fe9de52
Showing
5 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...va/de/adorsys/keycloak/config/service/normalize/AuthFlowNormalizationServiceConfigIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package de.adorsys.keycloak.config.service.normalize; | ||
|
||
import de.adorsys.keycloak.config.normalize.AbstractNormalizeTest; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.keycloak.representations.idm.AuthenticationExecutionExportRepresentation; | ||
import org.keycloak.representations.idm.AuthenticationFlowRepresentation; | ||
import org.keycloak.representations.idm.AuthenticatorConfigRepresentation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.system.CapturedOutput; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
class AuthFlowNormalizationServiceConfigIT extends AbstractNormalizeTest { | ||
|
||
@Autowired | ||
AuthFlowNormalizationService service; | ||
|
||
@Test | ||
public void testNormalizeAuthConfigsWithEmptyListsIsNull() { | ||
var resultingAuthConfig = service.normalizeAuthConfig(new ArrayList<>(), new ArrayList<>()); | ||
Assertions.assertThat(resultingAuthConfig).isNull(); | ||
} | ||
|
||
@Test | ||
public void testNormalizeAuthConfigsAreRemovedWithoutAliasReference(CapturedOutput output) { | ||
AuthenticatorConfigRepresentation authenticatorConfigRepresentation = new AuthenticatorConfigRepresentation(); | ||
authenticatorConfigRepresentation.setAlias("config2"); | ||
|
||
AuthenticationFlowRepresentation authenticationFlowRepresentation = new AuthenticationFlowRepresentation(); | ||
|
||
AuthenticationExecutionExportRepresentation authenticationExecutionExportRepresentation = new AuthenticationExecutionExportRepresentation(); | ||
authenticationExecutionExportRepresentation.setAuthenticatorConfig("config1"); | ||
authenticationFlowRepresentation.setAuthenticationExecutions(List.of(authenticationExecutionExportRepresentation)); | ||
|
||
var resultingAuthConfig = service.normalizeAuthConfig(List.of(authenticatorConfigRepresentation), List.of(authenticationFlowRepresentation)); | ||
|
||
Assertions.assertThat(resultingAuthConfig).isNull(); | ||
Assertions.assertThat(output.getOut()).contains("Some authenticator configs are unused."); | ||
} | ||
|
||
@Test | ||
public void testNormalizeAuthConfigsRemainWithAliasReference() { | ||
AuthenticatorConfigRepresentation authenticatorConfigRepresentation = new AuthenticatorConfigRepresentation(); | ||
authenticatorConfigRepresentation.setAlias("config1"); | ||
|
||
AuthenticationFlowRepresentation authenticationFlowRepresentation = new AuthenticationFlowRepresentation(); | ||
|
||
AuthenticationExecutionExportRepresentation authenticationExecutionExportRepresentation = new AuthenticationExecutionExportRepresentation(); | ||
authenticationExecutionExportRepresentation.setAuthenticatorConfig("config1"); | ||
authenticationFlowRepresentation.setAuthenticationExecutions(List.of(authenticationExecutionExportRepresentation)); | ||
|
||
var resultingAuthConfig = service.normalizeAuthConfig(List.of(authenticatorConfigRepresentation), List.of(authenticationFlowRepresentation)); | ||
|
||
Assertions.assertThat(resultingAuthConfig).containsExactlyInAnyOrder(authenticatorConfigRepresentation); | ||
} | ||
|
||
@Test | ||
public void testNormalizeAuthConfigsCheckedForDuplicates(CapturedOutput output) { | ||
AuthenticatorConfigRepresentation authenticatorConfigRepresentation1 = new AuthenticatorConfigRepresentation(); | ||
authenticatorConfigRepresentation1.setId(UUID.randomUUID().toString()); | ||
authenticatorConfigRepresentation1.setAlias("config1"); | ||
|
||
AuthenticatorConfigRepresentation authenticatorConfigRepresentation2 = new AuthenticatorConfigRepresentation(); | ||
authenticatorConfigRepresentation2.setId(UUID.randomUUID().toString()); | ||
authenticatorConfigRepresentation2.setAlias("config1"); | ||
|
||
AuthenticationFlowRepresentation authenticationFlowRepresentation = new AuthenticationFlowRepresentation(); | ||
|
||
AuthenticationExecutionExportRepresentation authenticationExecutionExportRepresentation = new AuthenticationExecutionExportRepresentation(); | ||
authenticationExecutionExportRepresentation.setAuthenticatorConfig("config1"); | ||
authenticationFlowRepresentation.setAuthenticationExecutions(List.of(authenticationExecutionExportRepresentation)); | ||
|
||
var resultingAuthConfig = service.normalizeAuthConfig(List.of(authenticatorConfigRepresentation1, authenticatorConfigRepresentation2), List.of(authenticationFlowRepresentation)); | ||
|
||
Assertions.assertThat(resultingAuthConfig).containsExactlyInAnyOrder(authenticatorConfigRepresentation1, authenticatorConfigRepresentation2); | ||
Assertions.assertThat(output.getOut()).contains("The following authenticator configs are duplicates: [config1]"); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...java/de/adorsys/keycloak/config/service/normalize/AuthFlowNormalizationServiceFlowIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.adorsys.keycloak.config.service.normalize; | ||
|
||
import de.adorsys.keycloak.config.normalize.AbstractNormalizeTest; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.keycloak.representations.idm.AuthenticationFlowRepresentation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.system.CapturedOutput; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
class AuthFlowNormalizationServiceFlowIT extends AbstractNormalizeTest { | ||
|
||
@Autowired | ||
AuthFlowNormalizationService service; | ||
|
||
|
||
@Test | ||
public void testNormalizeAuthFlows() { | ||
var resultingAuthFlows = service.normalizeAuthFlows(new ArrayList<>(), new ArrayList<>()); | ||
Assertions.assertThat(resultingAuthFlows).isNull(); | ||
} | ||
|
||
@Test | ||
public void testNormalizeAuthFlowsIgnoreBuiltInTrue() { | ||
AuthenticationFlowRepresentation authenticationFlowRepresentation = new AuthenticationFlowRepresentation(); | ||
authenticationFlowRepresentation.setBuiltIn(true); | ||
|
||
AuthenticationFlowRepresentation authenticationFlowRepresentationBaseline = new AuthenticationFlowRepresentation(); | ||
authenticationFlowRepresentationBaseline.setBuiltIn(true); | ||
|
||
var resultingAuthFlows = service.normalizeAuthFlows(List.of(authenticationFlowRepresentation), List.of(authenticationFlowRepresentationBaseline)); | ||
|
||
Assertions.assertThat(resultingAuthFlows).isNull(); | ||
} | ||
|
||
@Test | ||
public void testNormalizeAuthFlowsIgnoreBuiltInTrueButBaselineHasEntryCreatesRecreationWarning(CapturedOutput output) { | ||
AuthenticationFlowRepresentation authenticationFlowRepresentation = new AuthenticationFlowRepresentation(); | ||
authenticationFlowRepresentation.setBuiltIn(true); | ||
|
||
AuthenticationFlowRepresentation authenticationFlowRepresentationBaseline = new AuthenticationFlowRepresentation(); | ||
authenticationFlowRepresentationBaseline.setBuiltIn(false); | ||
authenticationFlowRepresentationBaseline.setAlias("flow1"); | ||
|
||
var resultingAuthFlows = service.normalizeAuthFlows(List.of(authenticationFlowRepresentation), List.of(authenticationFlowRepresentationBaseline)); | ||
|
||
Assertions.assertThat(resultingAuthFlows).isNull(); | ||
Assertions.assertThat(output.getOut()).contains("Default realm authentication flow 'flow1' was deleted in exported realm. It may be reintroduced during import"); | ||
|
||
} | ||
} |