1
- import { describe , expect , it , test } from "bun:test" ;
1
+ import { describe , expect , it } from "bun:test" ;
2
2
import {
3
3
TerraformState ,
4
- executeScriptInContainer ,
5
4
runTerraformApply ,
6
5
runTerraformInit ,
7
6
testRequiredVariables ,
@@ -14,6 +13,25 @@ type TestVariables = Readonly<{
14
13
admin_password ?: string ;
15
14
} > ;
16
15
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
+
17
35
/**
18
36
* @todo It would be nice if we had a way to verify that the Devolutions root
19
37
* HTML file is modified to include the import for the patched Coder script,
@@ -26,32 +44,28 @@ describe("Web RDP", async () => {
26
44
resource_id : "bar" ,
27
45
} ) ;
28
46
29
- it ( "Installs the Devolutions Gateway Angular app locally on the machine " , async ( ) => {
47
+ it ( "Has the PowerShell script install Devolutions Gateway " , async ( ) => {
30
48
const state = await runTerraformApply < TestVariables > ( import . meta. dir , {
31
49
agent_id : "foo" ,
32
50
resource_id : "bar" ,
33
51
} ) ;
34
52
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 ( / ^ \$ m o d u l e V e r s i o n = " \d { 4 } \. \d + \. \d + " $ / ) ,
63
+ "Install-Module -Name $moduleName -RequiredVersion $moduleVersion -Force" ,
64
+ ] ) ,
65
+ ) ;
36
66
} ) ;
37
67
38
68
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
-
55
69
/**
56
70
* Using a regex as a quick-and-dirty way to get at the username and
57
71
* password values.
@@ -82,35 +96,35 @@ describe("Web RDP", async () => {
82
96
} ,
83
97
) ;
84
98
85
- const defaultInstancesScript = findInstancesScript ( defaultState ) ;
86
- expect ( defaultInstancesScript ) . toBeString ( ) ;
99
+ const defaultRdpScript = findWindowsRpdScript ( defaultState ) ;
100
+ expect ( defaultRdpScript ) . toBeString ( ) ;
87
101
88
102
const { username : defaultUsername , password : defaultPassword } =
89
- formEntryValuesRe . exec ( defaultInstancesScript ) ?. groups ?? { } ;
103
+ formEntryValuesRe . exec ( defaultRdpScript ) ?. groups ?? { } ;
90
104
91
105
expect ( defaultUsername ) . toBe ( "Administrator" ) ;
92
106
expect ( defaultPassword ) . toBe ( "coderRDP!" ) ;
93
107
94
108
// 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!" ;
97
111
const customizedState = await runTerraformApply < TestVariables > (
98
112
import . meta. dir ,
99
113
{
100
114
agent_id : "foo" ,
101
115
resource_id : "bar" ,
102
- admin_username : userDefinedUsername ,
103
- admin_password : userDefinedPassword ,
116
+ admin_username : customAdminUsername ,
117
+ admin_password : customAdminPassword ,
104
118
} ,
105
119
) ;
106
120
107
- const customInstancesScript = findInstancesScript ( customizedState ) ;
108
- expect ( customInstancesScript ) . toBeString ( ) ;
121
+ const customRdpScript = findWindowsRpdScript ( customizedState ) ;
122
+ expect ( customRdpScript ) . toBeString ( ) ;
109
123
110
124
const { username : customUsername , password : customPassword } =
111
- formEntryValuesRe . exec ( customInstancesScript ) ?. groups ?? { } ;
125
+ formEntryValuesRe . exec ( customRdpScript ) ?. groups ?? { } ;
112
126
113
- expect ( customUsername ) . toBe ( userDefinedUsername ) ;
114
- expect ( customPassword ) . toBe ( userDefinedPassword ) ;
127
+ expect ( customUsername ) . toBe ( customAdminUsername ) ;
128
+ expect ( customPassword ) . toBe ( customAdminPassword ) ;
115
129
} ) ;
116
130
} ) ;
0 commit comments