-
Notifications
You must be signed in to change notification settings - Fork 126
/
AuthFlowNormalizationServiceConfigIT.java
81 lines (60 loc) · 4.57 KB
/
AuthFlowNormalizationServiceConfigIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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]");
}
}