Skip to content

Commit 92be47c

Browse files
e2e Rdp client tests (#3055)
* test: πŸ’ e2e test for rdp client launch * test: πŸ’ added rdp test helper * refactor: πŸ’‘ misc * refactor: πŸ’‘ addressed comments * refactor: πŸ’‘ removed similar test
1 parent 2677dd8 commit 92be47c

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

β€Že2e-tests/desktop/tests/targets.spec.jsβ€Ž

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import { expect, test } from '../fixtures/baseTest.js';
77
import * as boundaryHttp from '../../helpers/boundary-http.js';
88
import { textToMatch } from '../fixtures/tesseractTest.js';
9+
import {
10+
isRdpClientInstalled,
11+
isRdpRunning,
12+
killRdpProcesses,
13+
isOSForRdpSupported,
14+
} from '../../helpers/rdp.js';
915

1016
const hostName = 'Host name for test';
1117
let org;
@@ -117,7 +123,6 @@ test.beforeEach(
117123
});
118124

119125
// Create an RDP target and add host source and credential sources
120-
// TODO: A test for RDP target connection will be added later when the Proxy is in place.
121126
rdpTarget = await boundaryHttp.createTarget(request, {
122127
scopeId: project.id,
123128
type: 'rdp',
@@ -285,4 +290,37 @@ test.describe('Targets tests', () => {
285290
authedPage.getByRole('link', { name: targetWithHost.name }),
286291
).toBeVisible();
287292
});
293+
294+
test('Launches RDP client when connecting to an RDP target', async ({
295+
authedPage,
296+
}) => {
297+
const isRdpClientInstalledCheck = await isRdpClientInstalled();
298+
const isOSForRdpSupportedCheck = await isOSForRdpSupported();
299+
300+
test.skip(
301+
!isRdpClientInstalledCheck || !isOSForRdpSupportedCheck,
302+
'RDP client is not installed/supported on this system',
303+
);
304+
305+
const beforeLaunchRunning = await isRdpRunning();
306+
expect(beforeLaunchRunning).toBe(false);
307+
308+
await authedPage.getByRole('link', { name: rdpTarget.name }).click();
309+
await authedPage.getByRole('button', { name: 'Open' }).click();
310+
311+
await expect(
312+
authedPage.getByRole('heading', { name: 'Sessions' }),
313+
).toBeVisible();
314+
315+
const afterLaunchRunning = await isRdpRunning();
316+
expect(afterLaunchRunning).toBe(true);
317+
318+
await authedPage.getByRole('button', { name: 'End Session' }).click();
319+
await expect(authedPage.getByText('Canceled successfully.')).toBeVisible();
320+
321+
killRdpProcesses();
322+
323+
const afterKillRunning = await isRdpRunning();
324+
expect(afterKillRunning).toBe(false);
325+
});
288326
});

β€Že2e-tests/helpers/rdp.jsβ€Ž

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: BUSL-1.1
4+
*/
5+
6+
import { execSync } from 'node:child_process';
7+
8+
export async function isOSForRdpSupported() {
9+
return process.platform === 'win32' || process.platform === 'darwin';
10+
}
11+
12+
export async function isRdpRunning() {
13+
try {
14+
let result;
15+
if (process.platform === 'win32') {
16+
result = execSync('tasklist /FI "IMAGENAME eq mstsc.exe" /FO CSV /NH', {
17+
encoding: 'utf-8',
18+
});
19+
return result && result.includes('mstsc.exe');
20+
} else if (process.platform === 'darwin') {
21+
result = execSync('pgrep -x "Windows App"', {
22+
encoding: 'utf-8',
23+
});
24+
return result && result.trim().length > 0;
25+
}
26+
return false;
27+
} catch {
28+
return false;
29+
}
30+
}
31+
32+
export async function isRdpClientInstalled() {
33+
try {
34+
if (process.platform === 'win32') {
35+
execSync('where mstsc', { stdio: 'ignore' });
36+
return true;
37+
} else if (process.platform === 'darwin') {
38+
const result = execSync(
39+
'mdfind "kMDItemCFBundleIdentifier == \'com.microsoft.rdc.macos\'"',
40+
{ encoding: 'utf-8' },
41+
);
42+
return result && result.trim().length > 0;
43+
}
44+
return false;
45+
} catch {
46+
return false;
47+
}
48+
}
49+
50+
export function killRdpProcesses() {
51+
try {
52+
if (process.platform === 'win32') {
53+
execSync('taskkill /F /IM mstsc.exe', { stdio: 'ignore' });
54+
} else if (process.platform === 'darwin') {
55+
execSync('pkill -x "Windows App"', { stdio: 'ignore' });
56+
}
57+
} catch {
58+
// no op
59+
}
60+
}

0 commit comments

Comments
Β (0)