-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
electron-code-aad.spec.ts
89 lines (68 loc) · 2.96 KB
/
electron-code-aad.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as path from 'path';
import { ElectronApplication, Page, _electron as electron, test, expect } from "@playwright/test";
import { setupCredentials } from "../../../e2eTestUtils/TestUtils";
import { NodeCacheTestUtils } from "../../../e2eTestUtils/NodeCacheTestUtils";
import { LabClient } from "../../../e2eTestUtils/LabClient";
import { LabApiQueryParams } from "../../../e2eTestUtils/LabApiQueryParams";
import { AppTypes, AzureEnvironments } from "../../../e2eTestUtils/Constants";
import {
Screenshot,
clickSignIn,
enterCredentials,
} from '../../../e2eTestUtils/ElectronPlaywrightTestUtils';
import {
SCREENSHOT_BASE_FOLDER_NAME,
validateCacheLocation,
} from '../../testUtils'
import config from '../src/config/AAD.json';
// Set test cache name/location
const TEST_CACHE_LOCATION = `${__dirname}/../data/aad.cache.json`;
test.describe('Electron Auth Code AAD PPE Tests ', () => {
let electronApp: ElectronApplication;
let page: Page;
let username: string;
let accountPwd: string;
const screenshotFolder = `${SCREENSHOT_BASE_FOLDER_NAME}/ElectronTestApp/aad`;
test.beforeAll(async () => {
await validateCacheLocation(TEST_CACHE_LOCATION);
const labApiParams: LabApiQueryParams = {
azureEnvironment: AzureEnvironments.PPE,
appType: AppTypes.CLOUD
};
const labClient = new LabClient();
const envResponse = await labClient.getVarsByCloudEnvironment(labApiParams);
[username, accountPwd] = await setupCredentials(envResponse[0], labClient);
electronApp = await electron.launch({
args: [path.join(__dirname, "../dist/App.js"),
'--enable-logging',
'--skip-welcome',
'--disable-telemetry',
'--no-cached-data',
],
env: {
automation: "1",
authConfig: JSON.stringify(config),
}
});
await NodeCacheTestUtils.resetCache(TEST_CACHE_LOCATION);
});
test.describe('Acquire token', () => {
test.beforeEach(async () => {
page = await electronApp.firstWindow();
});
test.afterEach(async () => {
await page.close();
await NodeCacheTestUtils.resetCache(TEST_CACHE_LOCATION);
});
test('Acquire token by auth code', async () => {
const screenshot = new Screenshot(`${screenshotFolder}/AcquireTokenAuthCode`);
const popupPage = await clickSignIn(electronApp, page, screenshot);
await enterCredentials(popupPage, screenshot, username, accountPwd);
const cachedTokens = await NodeCacheTestUtils.waitForTokens(TEST_CACHE_LOCATION, 2000);
expect(cachedTokens.accessTokens.length).toBe(1);
expect(cachedTokens.idTokens.length).toBe(1);
expect(cachedTokens.refreshTokens.length).toBe(1);
await expect(page.locator(`text=${username}`).first()).toBeVisible();
});
});
});