Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 5869eb8

Browse files
committed
chore: finish all initial tests
1 parent 25c9000 commit 5869eb8

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

windows-rdp/main.test.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { describe, expect, it, test } from "bun:test";
1+
import { describe, expect, it } from "bun:test";
22
import {
33
TerraformState,
4-
executeScriptInContainer,
54
runTerraformApply,
65
runTerraformInit,
76
testRequiredVariables,
@@ -14,6 +13,25 @@ type TestVariables = Readonly<{
1413
admin_password?: string;
1514
}>;
1615

16+
function findWindowsRpdScript(state: TerraformState): string | null {
17+
for (const resource of state.resources) {
18+
const isRdpScriptResource =
19+
resource.type === "coder_script" && resource.name === "windows-rdp";
20+
21+
if (!isRdpScriptResource) {
22+
continue;
23+
}
24+
25+
for (const instance of resource.instances) {
26+
if (instance.attributes.display_name === "windows-rdp") {
27+
return instance.attributes.script;
28+
}
29+
}
30+
}
31+
32+
return null;
33+
}
34+
1735
/**
1836
* @todo It would be nice if we had a way to verify that the Devolutions root
1937
* HTML file is modified to include the import for the patched Coder script,
@@ -26,32 +44,28 @@ describe("Web RDP", async () => {
2644
resource_id: "bar",
2745
});
2846

29-
it("Installs the Devolutions Gateway Angular app locally on the machine", async () => {
47+
it("Has the PowerShell script install Devolutions Gateway", async () => {
3048
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
3149
agent_id: "foo",
3250
resource_id: "bar",
3351
});
3452

35-
throw new Error("Not implemented yet");
53+
const lines = findWindowsRpdScript(state)
54+
.split("\n")
55+
.filter(Boolean)
56+
.map((line) => line.trimStart());
57+
58+
expect(lines).toEqual(
59+
expect.arrayContaining<string>([
60+
'$moduleName = "DevolutionsGateway"',
61+
// Devolutions does versioning in the format year.minor.patch
62+
expect.stringMatching(/^\$moduleVersion = "\d{4}\.\d+\.\d+"$/),
63+
"Install-Module -Name $moduleName -RequiredVersion $moduleVersion -Force",
64+
]),
65+
);
3666
});
3767

3868
it("Injects Terraform's username and password into the JS patch file", async () => {
39-
const findInstancesScript = (state: TerraformState): string | null => {
40-
for (const resource of state.resources) {
41-
if (resource.type !== "coder_script") {
42-
continue;
43-
}
44-
45-
for (const instance of resource.instances) {
46-
if (instance.attributes.display_name === "windows-rdp") {
47-
return instance.attributes.script as string;
48-
}
49-
}
50-
}
51-
52-
return null;
53-
};
54-
5569
/**
5670
* Using a regex as a quick-and-dirty way to get at the username and
5771
* password values.
@@ -82,35 +96,35 @@ describe("Web RDP", async () => {
8296
},
8397
);
8498

85-
const defaultInstancesScript = findInstancesScript(defaultState);
86-
expect(defaultInstancesScript).toBeString();
99+
const defaultRdpScript = findWindowsRpdScript(defaultState);
100+
expect(defaultRdpScript).toBeString();
87101

88102
const { username: defaultUsername, password: defaultPassword } =
89-
formEntryValuesRe.exec(defaultInstancesScript)?.groups ?? {};
103+
formEntryValuesRe.exec(defaultRdpScript)?.groups ?? {};
90104

91105
expect(defaultUsername).toBe("Administrator");
92106
expect(defaultPassword).toBe("coderRDP!");
93107

94108
// Test that custom usernames/passwords are also forwarded correctly
95-
const userDefinedUsername = "crouton";
96-
const userDefinedPassword = "VeryVeryVeryVeryVerySecurePassword97!";
109+
const customAdminUsername = "crouton";
110+
const customAdminPassword = "VeryVeryVeryVeryVerySecurePassword97!";
97111
const customizedState = await runTerraformApply<TestVariables>(
98112
import.meta.dir,
99113
{
100114
agent_id: "foo",
101115
resource_id: "bar",
102-
admin_username: userDefinedUsername,
103-
admin_password: userDefinedPassword,
116+
admin_username: customAdminUsername,
117+
admin_password: customAdminPassword,
104118
},
105119
);
106120

107-
const customInstancesScript = findInstancesScript(customizedState);
108-
expect(customInstancesScript).toBeString();
121+
const customRdpScript = findWindowsRpdScript(customizedState);
122+
expect(customRdpScript).toBeString();
109123

110124
const { username: customUsername, password: customPassword } =
111-
formEntryValuesRe.exec(customInstancesScript)?.groups ?? {};
125+
formEntryValuesRe.exec(customRdpScript)?.groups ?? {};
112126

113-
expect(customUsername).toBe(userDefinedUsername);
114-
expect(customPassword).toBe(userDefinedPassword);
127+
expect(customUsername).toBe(customAdminUsername);
128+
expect(customPassword).toBe(customAdminPassword);
115129
});
116130
});

0 commit comments

Comments
 (0)