11package org .keycloak .it .cli .dist ;
22
3+ import io .quarkus .test .junit .main .Launch ;
4+ import io .quarkus .test .junit .main .LaunchResult ;
5+ import org .junit .jupiter .api .Assertions ;
36import org .junit .jupiter .api .Test ;
47import org .keycloak .it .junit5 .extension .CLIResult ;
58import org .keycloak .it .junit5 .extension .DistributionTest ;
69import org .keycloak .it .junit5 .extension .RawDistOnly ;
10+ import org .keycloak .it .junit5 .extension .WithEnvVars ;
711import org .keycloak .it .utils .KeycloakDistribution ;
12+ import org .keycloak .quarkus .runtime .cli .command .ShowConfig ;
13+ import org .keycloak .quarkus .runtime .configuration .mappers .PropertyMappers ;
14+
15+ import java .nio .file .Paths ;
16+
17+ import static org .hamcrest .MatcherAssert .assertThat ;
18+ import static org .hamcrest .Matchers .containsString ;
19+ import static org .hamcrest .Matchers .not ;
20+ import static org .keycloak .quarkus .runtime .cli .command .Main .CONFIG_FILE_LONG_NAME ;
821
922@ DistributionTest
1023public class ShowConfigCommandDistTest {
@@ -28,4 +41,54 @@ void testShowConfigPicksUpRightConfigDependingOnCurrentMode(KeycloakDistribution
2841 resetResult .assertMessage ("Current Mode: production" );
2942 resetResult .assertMessage ("kc.db = dev-file" );
3043 }
44+
45+ @ Test
46+ @ Launch ({ ShowConfig .NAME })
47+ void testShowConfigCommandShowsRuntimeConfig (LaunchResult result ) {
48+ Assertions .assertTrue (result .getOutput ()
49+ .contains ("Current Configuration" ));
50+ }
51+
52+ @ Test
53+ @ Launch ({ ShowConfig .NAME , "all" })
54+ void testShowConfigCommandWithAllShowsAllProfiles (LaunchResult result ) {
55+ Assertions .assertTrue (result .getOutput ()
56+ .contains ("Current Configuration" ));
57+ Assertions .assertTrue (result .getOutput ()
58+ .contains ("Quarkus Configuration" ));
59+ }
60+
61+ @ Test
62+ @ RawDistOnly (reason = "Containers are immutable" )
63+ void testShowConfigCommandHidesCredentialsInProfiles (KeycloakDistribution distribution ) {
64+ CLIResult result = distribution .run (String .format ("%s=%s" , CONFIG_FILE_LONG_NAME , Paths .get ("src/test/resources/ShowConfigCommandTest/keycloak.conf" ).toAbsolutePath ().normalize ()), ShowConfig .NAME , "all" );
65+ String output = result .getOutput ();
66+ Assertions .assertFalse (output .contains ("testpw1" ));
67+ Assertions .assertFalse (output .contains ("testpw2" ));
68+ Assertions .assertFalse (output .contains ("testpw3" ));
69+ Assertions .assertTrue (output .contains ("kc.db-password = " + PropertyMappers .VALUE_MASK ));
70+ }
71+
72+ @ Test
73+ @ RawDistOnly (reason = "Containers are immutable" )
74+ void testSmallRyeKeyStoreConfigSource (KeycloakDistribution distribution ) {
75+ // keystore is shared with QuarkusPropertiesDistTest#testSmallRyeKeyStoreConfigSource
76+ CLIResult result = distribution .run (String .format ("%s=%s" , CONFIG_FILE_LONG_NAME , Paths .get ("src/test/resources/ShowConfigCommandTest/keycloak-keystore.conf" ).toAbsolutePath ().normalize ()), ShowConfig .NAME , "all" );
77+ String output = result .getOutput ();
78+ assertThat (output , containsString ("kc.config-keystore-password = " + PropertyMappers .VALUE_MASK ));
79+ assertThat (output , containsString ("kc.log-level = " + PropertyMappers .VALUE_MASK ));
80+
81+ assertThat (output , not (containsString ("secret" )));
82+ assertThat (output , not (containsString ("debug" )));
83+ }
84+
85+ @ Test
86+ @ Launch ({ ShowConfig .NAME })
87+ @ WithEnvVars ({"KC_DB_PASSWORD" , "secret-pass" })
88+ void testNoDuplicitEnvVarEntries (LaunchResult result ) {
89+ String output = result .getOutput ();
90+ assertThat (output , containsString ("kc.db-password = " + PropertyMappers .VALUE_MASK ));
91+ assertThat (output , not (containsString ("kc.db.password" )));
92+ assertThat (output , not (containsString ("secret-pass" )));
93+ }
3194}
0 commit comments