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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108import { expect } from '@playwright/test';
import { getFixturePath, loadFixture } from '../../playwright/paths';
import { test } from '../../playwright/test';
test('Setup external vault and used in request', async ({ app, page }) => {
// import request collection and replace the template tag file path with the actual fixture file path
const text = (await loadFixture('template-tag-collection.yaml')).replace(
'__TEMPLATE_TAG_FILE_PATH',
getFixturePath('files/template-file.txt'),
);
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
await page.getByLabel('Import').click();
await page.locator('[data-test-id="import-from-clipboard"]').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByLabel('Template Tag Collection').click();
// Nav to cloud credentials page
await page.getByTestId('settings-button').click();
await page.getByRole('tab', { name: 'Credentials' }).click();
// create aws credential
const awsCredentialName = 'smoke-test-aws';
await page.getByRole('button', { name: 'Create Cloud Credential' }).click();
await page.getByRole('menuitemradio', { name: 'AWS' }).click();
await page.getByRole('textbox', { name: 'Credential Name:' }).fill(awsCredentialName);
await page.getByRole('radio', { name: 'Credential File' }).check();
await page.getByRole('textbox', { name: 'Section Name:' }).fill('aws-section-name');
await page.getByRole('textbox', { name: 'Region:' }).fill('aws-region');
await page.getByRole('dialog').getByRole('button', { name: 'Create', exact: true }).click();
await expect.soft(page.getByRole('cell', { name: awsCredentialName })).toBeVisible();
// create gcp credential
const gcpCredentialName = 'smoke-test-gcp';
await page.getByRole('button', { name: 'Create Cloud Credential' }).click();
await page.getByRole('menuitemradio', { name: 'GCP' }).click();
await page.getByRole('textbox', { name: 'Credential Name:' }).fill(gcpCredentialName);
await page.getByRole('textbox', { name: 'Input Service Account Key Path' }).fill('gcp-path');
await page.getByRole('dialog').getByRole('button', { name: 'Create', exact: true }).click();
await expect.soft(page.getByRole('cell', { name: gcpCredentialName })).toBeVisible();
// create hashicorp credential
const hashicorpCredentialName = 'smoke-test-hashicorp';
await page.getByRole('button', { name: 'Create Cloud Credential' }).click();
await page.getByRole('menuitemradio', { name: 'HashiCorp' }).click();
await page.getByRole('textbox', { name: 'Credential Name:' }).fill(hashicorpCredentialName);
await page.getByRole('textbox', { name: 'Server Address:' }).fill('http://127.0.0.1');
await page.getByRole('textbox', { name: 'Role Id:' }).fill('role-id');
await page.getByRole('textbox', { name: 'Secret Id:' }).fill('secret-id');
await page.getByRole('dialog').getByRole('button', { name: 'Create', exact: true }).click();
await expect.soft(page.getByRole('cell', { name: hashicorpCredentialName })).toBeVisible();
// close the settings
await page.locator('.app').press('Escape');
// used in request
await page.getByLabel('Request Collection').getByTestId('External Vault Tag').press('Enter');
await page.getByText('Body', { exact: true }).click();
const externalVaultTestCases = {
aws: {
tagPrefix: "{% vault 'aws'",
expectedResult: 'aws-secret-value',
},
gcp: {
tagPrefix: "{% vault 'gcp'",
expectedResult: 'gcp-secret-value',
},
hashicorp: {
tagPrefix: "{% vault 'hashicorp'",
expectedResult: 'hashicorp-secret-value',
},
};
// test aws vault tag
await page.locator(`[data-template^="${externalVaultTestCases.aws.tagPrefix}"]`).click();
await page.getByLabel('Credential For Vault Service').selectOption(awsCredentialName);
const previewText = page.getByRole('dialog').getByLabel('Live Preview');
await expect.soft(previewText).toHaveText(externalVaultTestCases.aws.expectedResult);
await page.getByRole('button', { name: 'Done' }).click();
// test gcp vault tag
await page.locator(`[data-template^="${externalVaultTestCases.gcp.tagPrefix}"]`).click();
await page.getByLabel('Credential For Vault Service').selectOption(gcpCredentialName);
const gcpPreviewText = page.getByRole('dialog').getByLabel('Live Preview');
await expect.soft(gcpPreviewText).toHaveText(externalVaultTestCases.gcp.expectedResult);
await page.getByRole('button', { name: 'Done' }).click();
// test hashicorp vault tag
await page.locator(`[data-template^="${externalVaultTestCases.hashicorp.tagPrefix}"]`).click();
await page.getByLabel('Credential For Vault Service').selectOption(hashicorpCredentialName);
const hashicorpPreviewText = page.getByRole('dialog').getByLabel('Live Preview');
await expect.soft(hashicorpPreviewText).toHaveText(externalVaultTestCases.hashicorp.expectedResult);
await page.getByRole('button', { name: 'Done' }).click();
await page.getByText('Params', { exact: true }).click();
await page.getByText('Body', { exact: true }).click();
// send request
await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click();
await page.getByRole('tab', { name: 'Console' }).click();
const responsePane = page.getByTestId('response-pane');
await expect.soft(responsePane).toContainText(externalVaultTestCases.aws.expectedResult);
await expect.soft(responsePane).toContainText(externalVaultTestCases.gcp.expectedResult);
await expect.soft(responsePane).toContainText(externalVaultTestCases.hashicorp.expectedResult);
// enable elevated access and execute again in renderer process
await page.getByTestId('settings-button').click();
await page.getByRole('tab', { name: 'Plugins' }).click();
await page.getByText('Allow elevated access for plugins').click();
// close the settings
await page.locator('.app').press('Escape');
// send request and execute the tags in renderer process
await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click();
await page.getByRole('tab', { name: 'Console' }).click();
await expect.soft(responsePane).toContainText(externalVaultTestCases.aws.expectedResult);
});