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
This commit is contained in:
Priya Patel authored and Dharini committed 2025-11-19 14:22:07 -08:00
1 parent fb0020c395
commit d2cf82b85c
2 files changed
+99 -1

No files matched your search

+39 -1
View File
@@ -6,6 +6,12 @@
import { expect, test } from '../fixtures/baseTest.js';
import * as boundaryHttp from '../../helpers/boundary-http.js';
import { textToMatch } from '../fixtures/tesseractTest.js';
import {
isRdpClientInstalled,
isRdpRunning,
killRdpProcesses,
isOSForRdpSupported,
} from '../../helpers/rdp.js';
const hostName = 'Host name for test';
let org;
@@ -117,7 +123,6 @@ test.beforeEach(
});
// Create an RDP target and add host source and credential sources
// TODO: A test for RDP target connection will be added later when the Proxy is in place.
rdpTarget = await boundaryHttp.createTarget(request, {
scopeId: project.id,
type: 'rdp',
@@ -285,4 +290,37 @@ test.describe('Targets tests', () => {
authedPage.getByRole('link', { name: targetWithHost.name }),
).toBeVisible();
});
test('Launches RDP client when connecting to an RDP target', async ({
authedPage,
}) => {
const isRdpClientInstalledCheck = await isRdpClientInstalled();
const isOSForRdpSupportedCheck = await isOSForRdpSupported();
test.skip(
!isRdpClientInstalledCheck || !isOSForRdpSupportedCheck,
'RDP client is not installed/supported on this system',
);
const beforeLaunchRunning = await isRdpRunning();
expect(beforeLaunchRunning).toBe(false);
await authedPage.getByRole('link', { name: rdpTarget.name }).click();
await authedPage.getByRole('button', { name: 'Open' }).click();
await expect(
authedPage.getByRole('heading', { name: 'Sessions' }),
).toBeVisible();
const afterLaunchRunning = await isRdpRunning();
expect(afterLaunchRunning).toBe(true);
await authedPage.getByRole('button', { name: 'End Session' }).click();
await expect(authedPage.getByText('Canceled successfully.')).toBeVisible();
killRdpProcesses();
const afterKillRunning = await isRdpRunning();
expect(afterKillRunning).toBe(false);
});
});
+60
View File
@@ -0,0 +1,60 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { execSync } from 'node:child_process';
export async function isOSForRdpSupported() {
return process.platform === 'win32' || process.platform === 'darwin';
}
export async function isRdpRunning() {
try {
let result;
if (process.platform === 'win32') {
result = execSync('tasklist /FI "IMAGENAME eq mstsc.exe" /FO CSV /NH', {
encoding: 'utf-8',
});
return result && result.includes('mstsc.exe');
} else if (process.platform === 'darwin') {
result = execSync('pgrep -x "Windows App"', {
encoding: 'utf-8',
});
return result && result.trim().length > 0;
}
return false;
} catch {
return false;
}
}
export async function isRdpClientInstalled() {
try {
if (process.platform === 'win32') {
execSync('where mstsc', { stdio: 'ignore' });
return true;
} else if (process.platform === 'darwin') {
const result = execSync(
'mdfind "kMDItemCFBundleIdentifier == \'com.microsoft.rdc.macos\'"',
{ encoding: 'utf-8' },
);
return result && result.trim().length > 0;
}
return false;
} catch {
return false;
}
}
export function killRdpProcesses() {
try {
if (process.platform === 'win32') {
execSync('taskkill /F /IM mstsc.exe', { stdio: 'ignore' });
} else if (process.platform === 'darwin') {
execSync('pkill -x "Windows App"', { stdio: 'ignore' });
}
} catch {
// no op
}
}