Compare commits

...

3 Commits

Author SHA1 Message Date
DevelopmentCats af829e4083 fix(windows-rdp): update test assertions for username and password handling
- Modified regex to use JSON.parse for extracting username and password values.
- Updated test assertions to compare against JSON.stringify for proper value matching.
- Added a backslash to the custom admin password for testing purposes.
2025-05-22 19:33:10 +00:00
DevelopmentCats 5ca7450349 fix(windows-rdp): parse username and password values in patch file
- Updated the `value` fields for `CODER_USERNAME` and `CODER_PASSWORD` to use `JSON.parse` for proper handling of JSON strings.
2025-05-22 19:32:56 +00:00
DevelopmentCats 02b5ae42f1 fix(windows-rdp): properly escape username and password in patch file (#xxx)
- Updated the `patch_file_contents` to use `jsonencode` for `CODER_USERNAME` and `CODER_PASSWORD` to preserve special characters.
2025-05-22 19:32:42 +00:00
3 changed files with 17 additions and 10 deletions
@@ -59,7 +59,7 @@ const formFieldEntries = {
querySelector: "web-client-username-control input",
/** @readonly */
value: "${CODER_USERNAME}",
value: JSON.parse("${CODER_USERNAME}"),
},
/** @readonly */
@@ -68,7 +68,7 @@ const formFieldEntries = {
querySelector: "web-client-password-control input",
/** @readonly */
value: "${CODER_PASSWORD}",
value: JSON.parse("${CODER_PASSWORD}"),
},
};
@@ -89,7 +89,7 @@ describe("Web RDP", async () => {
* @see {@link https://regex101.com/r/UMgQpv/2}
*/
const formEntryValuesRe =
/^const formFieldEntries = \{$.*?^\s+username: \{$.*?^\s*?querySelector.*?,$.*?^\s*value: "(?<username>.+?)",$.*?password: \{$.*?^\s+querySelector: .*?,$.*?^\s*value: "(?<password>.+?)",$.*?^};$/ms;
/^const formFieldEntries = \{$.*?^\s+username: \{$.*?^\s*?querySelector.*?,$.*?^\s*value: JSON\.parse\("(?<username>.+?)"\),$.*?password: \{$.*?^\s+querySelector: .*?,$.*?^\s*value: JSON\.parse\("(?<password>.+?)"\),$.*?^};$/ms;
// Test that things work with the default username/password
const defaultState = await runTerraformApply<TestVariables>(
@@ -106,12 +106,13 @@ describe("Web RDP", async () => {
const defaultResultsGroup =
formEntryValuesRe.exec(defaultRdpScript ?? "")?.groups ?? {};
expect(defaultResultsGroup.username).toBe("Administrator");
expect(defaultResultsGroup.password).toBe("coderRDP!");
// Should match the escaped JSON values
expect(defaultResultsGroup.username).toBe(JSON.stringify("Administrator"));
expect(defaultResultsGroup.password).toBe(JSON.stringify("coderRDP!"));
// Test that custom usernames/passwords are also forwarded correctly
const customAdminUsername = "crouton";
const customAdminPassword = "VeryVeryVeryVeryVerySecurePassword97!";
const customAdminPassword = "VeryVeryVeryVeryVerySecurePassword97!\\"; // Added a backslash for testing
const customizedState = await runTerraformApply<TestVariables>(
import.meta.dir,
{
@@ -128,7 +129,12 @@ describe("Web RDP", async () => {
const customResultsGroup =
formEntryValuesRe.exec(customRdpScript ?? "")?.groups ?? {};
expect(customResultsGroup.username).toBe(customAdminUsername);
expect(customResultsGroup.password).toBe(customAdminPassword);
// Should match the escaped JSON values
expect(customResultsGroup.username).toBe(
JSON.stringify(customAdminUsername),
);
expect(customResultsGroup.password).toBe(
JSON.stringify(customAdminPassword),
);
});
});
+3 -2
View File
@@ -52,8 +52,9 @@ resource "coder_script" "windows-rdp" {
# doesn't allow recursive calls to the templatefile function. Have to feed
# results of the JS template replace into the powershell template
patch_file_contents = templatefile("${path.module}/devolutions-patch.js", {
CODER_USERNAME = var.admin_username
CODER_PASSWORD = var.admin_password
# Properly escape the username and password to preserve special characters
CODER_USERNAME = jsonencode(var.admin_username)
CODER_PASSWORD = jsonencode(var.admin_password)
})
})