Compare commits
3 Commits
main
...
cat/window
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af829e4083 | ||
|
|
5ca7450349 | ||
|
|
02b5ae42f1 |
@ -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),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user