Skip to content

Commit

Permalink
Unable to use < as part of a password (admin-cli)
Browse files Browse the repository at this point in the history
* escaped angle bracket characters in password

Closes keycloak#21951

Signed-off-by: Peter Zaoral <[email protected]>
  • Loading branch information
Pepo48 committed Dec 6, 2023
1 parent f5dc034 commit 6b971db
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,14 @@ public static void main(String [] args) {
StringBuilder b = new StringBuilder();
for (String s : args) {
// quote if necessary
boolean needQuote = false;
needQuote = s.indexOf(' ') != -1 || s.indexOf('\"') != -1 || s.indexOf('\'') != -1;
b.append(' ');
if (needQuote) {
b.append('\'');
}
s = s.replace("'", "\\'");
b.append('\'');
b.append(s);
if (needQuote) {
b.append('\'');
}
b.append('\'');
}
console.setEcho(false);

console.execute("kcadm" + b.toString());

console.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ public void testUserLoginWithDefaultConfig() {
Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as user admin of realm master", exe.stderrLines().get(0));
}

@Test
public void testUserLoginWithAngleBrackets() {
KcAdmExec exe = KcAdmExec.execute("config credentials --server " + serverUrl + " --realm test --user 'special>>character' --password '<password>'");

assertExitCodeAndStreamSizes(exe, 0, 0, 1);
Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as user special>>character of realm test", exe.stderrLines().get(0));
}

@Test
public void testUserLoginWithDefaultConfigInteractive() throws IOException {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ public void testDirRealmExportImport() throws Throwable {
RealmResource testRealmRealm = adminClient.realm(TEST_REALM);
ExportImportUtil.assertDataImportedInRealm(adminClient, testingClient, testRealmRealm.toRepresentation());

// There should be 4 files in target directory (1 realm, 12 users, 5 users per file)
// There should be 5 files in target directory (1 realm, 16 users, 5 users per file)
// (+ additional user service-account-test-app-authz that should not be there ???)
File[] files = new File(targetDirPath).listFiles();
assertEquals(4, files.length);
assertEquals(5, files.length);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@
"credentialData" : "{\"digits\":6,\"counter\":0,\"period\":30,\"algorithm\":\"HmacSHA1\",\"subType\":\"totp\"}"
}
]
},
{
"username" : "special>>character",
"enabled": true,
"email" : "special-character@localhost",
"firstName": "Special",
"lastName": "Character",
"credentials" : [
{ "type" : "password",
"value" : "<password>" }
],
"realmRoles": ["user", "offline_access"]
}
],
"scopeMappings": [
Expand Down

0 comments on commit 6b971db

Please sign in to comment.