@appsemble/e2e 0.40.4 → 0.40.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/fixtures/test/accessibility/index.d.ts +75 -0
- package/fixtures/test/accessibility/index.js +73 -0
- package/fixtures/test/index.d.ts +4 -2
- package/fixtures/test/index.js +19 -2
- package/fixtures/test/live-app/index.js +1 -1
- package/package.json +7 -5
- package/playwright.config.js +2 -1
- package/tests/demo-apps/accessibility.spec.d.ts +1 -0
- package/tests/demo-apps/accessibility.spec.js +42 -0
- package/tests/demo-apps/mail.spec.d.ts +1 -0
- package/tests/demo-apps/mail.spec.js +31 -0
- package/tests/static-ui/apps.spec.js +3 -3
- package/tests/studio/logins/keycloak-entra-broker.spec.d.ts +1 -0
- package/tests/studio/logins/keycloak-entra-broker.spec.js +219 -0
- package/tests/studio/logins/keycloak-oidc.spec.js +17 -98
- package/tests/studio/logins/keycloak-saml.spec.js +17 -118
- package/tests/studio/organizations.spec.js +4 -0
- package/utils/keycloak-admin.d.ts +115 -0
- package/utils/keycloak-admin.js +272 -0
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#  Appsemble End 2 End Tests
|
|
2
2
|
|
|
3
3
|
> Run end 2 end tests on an Appsemble environment and provide Appsemble fixtures
|
|
4
4
|
|
|
5
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.40.6)
|
|
6
6
|
[](https://prettier.io)
|
|
7
7
|
|
|
8
8
|
## Table of Contents
|
|
@@ -102,5 +102,5 @@ When writing end-to-end tests, have a look at the
|
|
|
102
102
|
|
|
103
103
|
## License
|
|
104
104
|
|
|
105
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.40.
|
|
105
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.40.6/LICENSE.md) ©
|
|
106
106
|
[Appsemble](https://appsemble.com)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AxeBuilder } from '@axe-core/playwright';
|
|
2
|
+
type ImpactValue = NonNullable<Awaited<ReturnType<AxeBuilder['analyze']>>['violations'][number]['impact']>;
|
|
3
|
+
export interface AccessibilityViolation {
|
|
4
|
+
/**
|
|
5
|
+
* The ID of the failing axe-core rule.
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* How severely the violation affects users.
|
|
10
|
+
*/
|
|
11
|
+
impact: ImpactValue | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A short description of the rule.
|
|
14
|
+
*/
|
|
15
|
+
help: string;
|
|
16
|
+
/**
|
|
17
|
+
* A link to the documentation of the rule.
|
|
18
|
+
*/
|
|
19
|
+
helpUrl: string;
|
|
20
|
+
/**
|
|
21
|
+
* The number of elements on the page that fail the rule.
|
|
22
|
+
*/
|
|
23
|
+
nodes: number;
|
|
24
|
+
}
|
|
25
|
+
export interface PageAccessibilityReport {
|
|
26
|
+
/**
|
|
27
|
+
* The URL of the scanned page.
|
|
28
|
+
*/
|
|
29
|
+
url: string;
|
|
30
|
+
/**
|
|
31
|
+
* The accessibility score of the page, from 0 to 100.
|
|
32
|
+
*/
|
|
33
|
+
score: number;
|
|
34
|
+
/**
|
|
35
|
+
* The WCAG rules the page fails.
|
|
36
|
+
*/
|
|
37
|
+
violations: AccessibilityViolation[];
|
|
38
|
+
}
|
|
39
|
+
export interface AppAccessibilityReport {
|
|
40
|
+
/**
|
|
41
|
+
* The average score of the scanned pages, from 0 to 100.
|
|
42
|
+
*/
|
|
43
|
+
score: number;
|
|
44
|
+
/**
|
|
45
|
+
* The reports of the scanned pages, lowest score first.
|
|
46
|
+
*/
|
|
47
|
+
pages: PageAccessibilityReport[];
|
|
48
|
+
}
|
|
49
|
+
export interface AccessibilityFixtures {
|
|
50
|
+
/**
|
|
51
|
+
* Crawl the app that is open in the page and score the accessibility of every page.
|
|
52
|
+
*
|
|
53
|
+
* Starting at the current page, the crawl follows links to other pages of the same app. Paths
|
|
54
|
+
* that only differ in numeric or UUID segments, such as resource detail pages, are scanned once.
|
|
55
|
+
*
|
|
56
|
+
* Each page is checked against WCAG 2.2 level A and AA using axe-core. A page scores 100 minus a
|
|
57
|
+
* penalty per failing rule, regardless of how many elements fail it: 10 for critical, 7 for
|
|
58
|
+
* serious, 3 for moderate and 1 for minor violations, with a minimum of 0.
|
|
59
|
+
*
|
|
60
|
+
* The report is attached to the test as `accessibility.json`, and the app score is added as the
|
|
61
|
+
* `accessibility score` annotation, which the JUnit reporter writes as a test case property. The
|
|
62
|
+
* score is also written as the metric `accessibility_<name>` to `accessibility-metrics.txt` in
|
|
63
|
+
* the output directory of the project, in the format of a GitLab metrics report.
|
|
64
|
+
*
|
|
65
|
+
* @param options Options for the crawl. `name` identifies the app in the metrics report.
|
|
66
|
+
* `maxPages` limits the number of scanned pages, 50 by default.
|
|
67
|
+
* @returns The accessibility report of the app.
|
|
68
|
+
*/
|
|
69
|
+
scanAppAccessibility: (options: {
|
|
70
|
+
name: string;
|
|
71
|
+
maxPages?: number;
|
|
72
|
+
}) => Promise<AppAccessibilityReport>;
|
|
73
|
+
}
|
|
74
|
+
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & AccessibilityFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { appendFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { AxeBuilder } from '@axe-core/playwright';
|
|
4
|
+
import { test as base } from '@playwright/test';
|
|
5
|
+
const wcagTags = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa'];
|
|
6
|
+
const penalties = {
|
|
7
|
+
critical: 10,
|
|
8
|
+
serious: 7,
|
|
9
|
+
moderate: 3,
|
|
10
|
+
minor: 1,
|
|
11
|
+
};
|
|
12
|
+
const dynamicSegment = /^(\d+|[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})$/i;
|
|
13
|
+
function getRoutePattern(url) {
|
|
14
|
+
return url.pathname
|
|
15
|
+
.split('/')
|
|
16
|
+
.map((segment) => (dynamicSegment.test(segment) ? ':id' : segment))
|
|
17
|
+
.join('/');
|
|
18
|
+
}
|
|
19
|
+
export const test = base.extend({
|
|
20
|
+
async scanAppAccessibility({ page }, use, testInfo) {
|
|
21
|
+
await use(async ({ maxPages = 50, name }) => {
|
|
22
|
+
const { origin } = new URL(page.url());
|
|
23
|
+
const queue = [page.url()];
|
|
24
|
+
const seen = new Set(queue.map((url) => getRoutePattern(new URL(url))));
|
|
25
|
+
const pages = [];
|
|
26
|
+
while (queue.length && pages.length < maxPages) {
|
|
27
|
+
const url = queue.shift();
|
|
28
|
+
await page.goto(url);
|
|
29
|
+
await page.waitForLoadState('networkidle');
|
|
30
|
+
const { violations } = await new AxeBuilder({ page }).withTags(wcagTags).analyze();
|
|
31
|
+
pages.push({
|
|
32
|
+
url,
|
|
33
|
+
score: Math.max(0, 100 - violations.reduce((sum, { impact }) => sum + (impact ? penalties[impact] : 0), 0)),
|
|
34
|
+
violations: violations.map(({ help, helpUrl, id, impact, nodes }) => ({
|
|
35
|
+
id,
|
|
36
|
+
impact: impact ?? undefined,
|
|
37
|
+
help,
|
|
38
|
+
helpUrl,
|
|
39
|
+
nodes: nodes.length,
|
|
40
|
+
})),
|
|
41
|
+
});
|
|
42
|
+
const hrefs = await page
|
|
43
|
+
.locator('a[href]')
|
|
44
|
+
.evaluateAll((links) => links.map((link) => link.href));
|
|
45
|
+
for (const href of hrefs) {
|
|
46
|
+
const link = new URL(href);
|
|
47
|
+
link.hash = '';
|
|
48
|
+
link.search = '';
|
|
49
|
+
const pattern = getRoutePattern(link);
|
|
50
|
+
if (link.origin === origin && !seen.has(pattern)) {
|
|
51
|
+
seen.add(pattern);
|
|
52
|
+
queue.push(String(link));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
pages.sort((a, b) => a.score - b.score);
|
|
57
|
+
const report = {
|
|
58
|
+
score: Math.round(pages.reduce((sum, { score }) => sum + score, 0) / pages.length),
|
|
59
|
+
pages,
|
|
60
|
+
};
|
|
61
|
+
const reportPath = testInfo.outputPath('accessibility.json');
|
|
62
|
+
await writeFile(reportPath, JSON.stringify(report, null, 2));
|
|
63
|
+
await testInfo.attach('accessibility.json', {
|
|
64
|
+
path: reportPath,
|
|
65
|
+
contentType: 'application/json',
|
|
66
|
+
});
|
|
67
|
+
testInfo.annotations.push({ type: 'accessibility score', description: String(report.score) });
|
|
68
|
+
await appendFile(join(testInfo.project.outputDir, 'accessibility-metrics.txt'), `accessibility_${name} ${report.score}\n`);
|
|
69
|
+
return report;
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
package/fixtures/test/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { MailpitClient } from 'mailpit-api';
|
|
1
2
|
/**
|
|
2
3
|
* Base test object with all utility fixtures
|
|
3
4
|
*/
|
|
4
|
-
export declare const baseTest: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & import("./app/index.js").AppFixtures & import("./app-collection/index.js").AppCollectionFixtures & import("./demo-app/index.js").DemoAppFixtures & import("./group/index.js").GroupFixtures & import("./live-app/index.js").LiveAppFixtures & import("./organization/index.js").OrganizationFixtures & import("./resource/index.js").ResourceFixtures & import("./studio/index.js").StudioFixtures & import("./test-utils/index.js").TestUtilsFixtures & import("./training/index.js").TrainingFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
5
|
+
export declare const baseTest: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & import("./accessibility/index.js").AccessibilityFixtures & import("./app/index.js").AppFixtures & import("./app-collection/index.js").AppCollectionFixtures & import("./demo-app/index.js").DemoAppFixtures & import("./group/index.js").GroupFixtures & import("./live-app/index.js").LiveAppFixtures & import("./organization/index.js").OrganizationFixtures & import("./resource/index.js").ResourceFixtures & import("./studio/index.js").StudioFixtures & import("./test-utils/index.js").TestUtilsFixtures & import("./training/index.js").TrainingFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
5
6
|
/**
|
|
6
7
|
* Test object with the worker's storage state saved
|
|
7
8
|
*
|
|
8
9
|
* Used for tests that require a logged in user
|
|
9
10
|
*/
|
|
10
|
-
export declare const authenticatedTest: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & import("./app/index.js").AppFixtures & import("./app-collection/index.js").AppCollectionFixtures & import("./demo-app/index.js").DemoAppFixtures & import("./group/index.js").GroupFixtures & import("./live-app/index.js").LiveAppFixtures & import("./organization/index.js").OrganizationFixtures & import("./resource/index.js").ResourceFixtures & import("./studio/index.js").StudioFixtures & import("./test-utils/index.js").TestUtilsFixtures & import("./training/index.js").TrainingFixtures & object, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
11
|
+
export declare const authenticatedTest: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & import("./accessibility/index.js").AccessibilityFixtures & import("./app/index.js").AppFixtures & import("./app-collection/index.js").AppCollectionFixtures & import("./demo-app/index.js").DemoAppFixtures & import("./group/index.js").GroupFixtures & import("./live-app/index.js").LiveAppFixtures & import("./organization/index.js").OrganizationFixtures & import("./resource/index.js").ResourceFixtures & import("./studio/index.js").StudioFixtures & import("./test-utils/index.js").TestUtilsFixtures & import("./training/index.js").TrainingFixtures & object, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
11
12
|
workerStorageState: string;
|
|
13
|
+
mailpit: MailpitClient;
|
|
12
14
|
}>;
|
package/fixtures/test/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { expect, mergeTests, request } from '@playwright/test';
|
|
5
|
+
import { test as accessibilityFixtures } from './accessibility/index.js';
|
|
5
6
|
import { test as appFixtures } from './app/index.js';
|
|
6
7
|
import { test as appCollectionFixtures } from './app-collection/index.js';
|
|
7
8
|
import { test as demoAppFixtures } from './demo-app/index.js';
|
|
@@ -12,10 +13,12 @@ import { test as resourceFixtures } from './resource/index.js';
|
|
|
12
13
|
import { test as studioFixtures } from './studio/index.js';
|
|
13
14
|
import { test as testUtilsFixtures } from './test-utils/index.js';
|
|
14
15
|
import { test as trainingFixtures } from './training/index.js';
|
|
16
|
+
import { MailpitClient } from 'mailpit-api';
|
|
15
17
|
/**
|
|
16
18
|
* Base test object with all utility fixtures
|
|
17
19
|
*/
|
|
18
|
-
export const baseTest = mergeTests(appFixtures, appCollectionFixtures, demoAppFixtures, groupFixtures, liveAppFixtures, organizationFixtures, resourceFixtures, studioFixtures, testUtilsFixtures, trainingFixtures);
|
|
20
|
+
export const baseTest = mergeTests(accessibilityFixtures, appFixtures, appCollectionFixtures, demoAppFixtures, groupFixtures, liveAppFixtures, organizationFixtures, resourceFixtures, studioFixtures, testUtilsFixtures, trainingFixtures);
|
|
21
|
+
const mailpitURL = process.env.MAILPIT_URL ?? 'http://localhost:8025';
|
|
19
22
|
/**
|
|
20
23
|
* Test object with the worker's storage state saved
|
|
21
24
|
*
|
|
@@ -40,7 +43,7 @@ export const authenticatedTest = baseTest.extend({
|
|
|
40
43
|
await page.getByTestId('password').fill(password);
|
|
41
44
|
await page.getByTestId('login').click();
|
|
42
45
|
// Wait until auth state is saved in browser storage
|
|
43
|
-
await expect(page.getByText('My
|
|
46
|
+
await expect(page.getByText('My apps')).toBeVisible();
|
|
44
47
|
await page.context().storageState({ path: fileName });
|
|
45
48
|
await page.close();
|
|
46
49
|
await use(fileName);
|
|
@@ -59,5 +62,19 @@ export const authenticatedTest = baseTest.extend({
|
|
|
59
62
|
await use(newRequest);
|
|
60
63
|
await newRequest.dispose();
|
|
61
64
|
},
|
|
65
|
+
mailpit: [
|
|
66
|
+
async ({}, use, testInfo) => {
|
|
67
|
+
const mailpit = new MailpitClient(mailpitURL);
|
|
68
|
+
const queryEmailsToThisWorker = `to:worker-${testInfo.parallelIndex}@appsemble.com`;
|
|
69
|
+
await mailpit.deleteMessagesBySearch({ query: queryEmailsToThisWorker });
|
|
70
|
+
try {
|
|
71
|
+
await use(mailpit);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await mailpit.deleteMessagesBySearch({ query: queryEmailsToThisWorker });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{ scope: 'worker' },
|
|
78
|
+
],
|
|
62
79
|
});
|
|
63
80
|
//# sourceMappingURL=index.js.map
|
|
@@ -43,7 +43,7 @@ export const test = base.extend({
|
|
|
43
43
|
const response = await request.post(`/api/users/current/auth/oauth2/apps/${appId}/consent/agree`, {
|
|
44
44
|
data: {
|
|
45
45
|
redirectUri: url,
|
|
46
|
-
scope: 'openid',
|
|
46
|
+
scope: 'email groups:read groups:write openid profile resources:manage',
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
expect(response.status()).toBe(201);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/e2e",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.6",
|
|
4
4
|
"description": "End-to-end tests used for testing Appsemble apps in an existing environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -40,10 +40,12 @@
|
|
|
40
40
|
"@playwright/test": "Pinned exact and kept in sync with the mcr.microsoft.com/playwright:v<version>-noble tags of the `mermaid svgs`, `e2e node`, and `e2e keycloak` jobs in .gitlab-ci.yml; Renovate bumps them all together (see renovate.json)."
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@appsemble/lang-sdk": "0.40.
|
|
44
|
-
"@appsemble/node-utils": "0.40.
|
|
45
|
-
"@appsemble/types": "0.40.
|
|
46
|
-
"@playwright
|
|
43
|
+
"@appsemble/lang-sdk": "0.40.6",
|
|
44
|
+
"@appsemble/node-utils": "0.40.6",
|
|
45
|
+
"@appsemble/types": "0.40.6",
|
|
46
|
+
"@axe-core/playwright": "4.14.0",
|
|
47
|
+
"@playwright/test": "1.64.1",
|
|
48
|
+
"mailpit-api": "^2.1.0",
|
|
47
49
|
"strip-indent": "^4.0.0"
|
|
48
50
|
},
|
|
49
51
|
"engines": {
|
package/playwright.config.js
CHANGED
|
@@ -14,7 +14,8 @@ export default defineConfig({
|
|
|
14
14
|
// Amount of workers to run tests with
|
|
15
15
|
workers: CI ? 2 : 1,
|
|
16
16
|
// Reporter to use. See https://playwright.dev/docs/test-reporters
|
|
17
|
-
|
|
17
|
+
// Written to the repository root, so attachment paths resolve against the CI job artifacts
|
|
18
|
+
reporter: [['junit', { outputFile: '../../junit.xml' }]],
|
|
18
19
|
// Prevent the pipeline from timing out
|
|
19
20
|
maxFailures: 6,
|
|
20
21
|
// Overall test timeout - increased for CI stability with cold server starts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { expect, authenticatedTest as test } from '../../index.js';
|
|
3
|
+
const minimumScore = 85;
|
|
4
|
+
let organizationId;
|
|
5
|
+
const appIds = [];
|
|
6
|
+
test.describe('Accessibility', () => {
|
|
7
|
+
test.beforeAll(async ({ createOrganization, randomTestId }) => {
|
|
8
|
+
organizationId = (await createOrganization({ id: randomTestId() })).id;
|
|
9
|
+
});
|
|
10
|
+
test.afterAll(async ({ deleteApp, deleteOrganization }) => {
|
|
11
|
+
for (const appId of appIds) {
|
|
12
|
+
await deleteApp(appId);
|
|
13
|
+
}
|
|
14
|
+
await deleteOrganization(organizationId);
|
|
15
|
+
});
|
|
16
|
+
test.beforeEach(({ browserName }) => {
|
|
17
|
+
test.skip(browserName !== 'chromium', 'The axe-core results do not depend on the browser');
|
|
18
|
+
});
|
|
19
|
+
test('person app scores at least the minimum', async ({ createApp, page, scanAppAccessibility, uploadAppMessages, visitApp, }) => {
|
|
20
|
+
const appDefinition = await readFile('../../apps/person/app-definition.yaml', 'utf8');
|
|
21
|
+
const messages = JSON.parse(await readFile('../../apps/person/i18n/en.json', 'utf8'));
|
|
22
|
+
const appId = (await createApp(organizationId, appDefinition)).id;
|
|
23
|
+
appIds.push(appId);
|
|
24
|
+
await uploadAppMessages(appId, 'en', messages);
|
|
25
|
+
await visitApp(appId);
|
|
26
|
+
await page.waitForURL('**/person-registration-form');
|
|
27
|
+
const { pages, score } = await scanAppAccessibility({ name: 'person' });
|
|
28
|
+
expect(score, JSON.stringify(pages, null, 2)).toBeGreaterThanOrEqual(minimumScore);
|
|
29
|
+
});
|
|
30
|
+
test('notes app scores at least the minimum', async ({ createApp, giveAppConsent, loginAppAppsembleOAuth, page, scanAppAccessibility, visitApp, }) => {
|
|
31
|
+
const appDefinition = await readFile('../../apps/notes/app-definition.yaml', 'utf8');
|
|
32
|
+
const appId = (await createApp(organizationId, appDefinition)).id;
|
|
33
|
+
appIds.push(appId);
|
|
34
|
+
await giveAppConsent(appId);
|
|
35
|
+
await visitApp(appId);
|
|
36
|
+
await loginAppAppsembleOAuth();
|
|
37
|
+
await page.waitForURL('**/notes');
|
|
38
|
+
const { pages, score } = await scanAppAccessibility({ name: 'notes' });
|
|
39
|
+
expect(score, JSON.stringify(pages, null, 2)).toBeGreaterThanOrEqual(minimumScore);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=accessibility.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { expect, authenticatedTest as test } from '../../index.js';
|
|
3
|
+
let appId;
|
|
4
|
+
let organizationId;
|
|
5
|
+
test.describe('Mail', () => {
|
|
6
|
+
test.beforeAll(async ({ createApp, createOrganization, randomTestId, giveAppConsent }) => {
|
|
7
|
+
const appDefinition = await readFile('../../apps/mail/app-definition.yaml', 'utf8');
|
|
8
|
+
organizationId = (await createOrganization({ id: randomTestId() })).id;
|
|
9
|
+
appId = (await createApp(organizationId, appDefinition)).id;
|
|
10
|
+
await giveAppConsent(appId);
|
|
11
|
+
});
|
|
12
|
+
test.beforeEach(async ({ visitApp, loginAppAppsembleOAuth }) => {
|
|
13
|
+
await visitApp(appId);
|
|
14
|
+
await loginAppAppsembleOAuth();
|
|
15
|
+
});
|
|
16
|
+
test.afterAll(async ({ deleteApp, deleteOrganization }) => {
|
|
17
|
+
await deleteApp(appId);
|
|
18
|
+
await deleteOrganization(organizationId);
|
|
19
|
+
});
|
|
20
|
+
test('should send an email when pressing the email button', async ({ page, mailpit, }, testInfo) => {
|
|
21
|
+
await page.locator('[data-block="@appsemble/action-button"]').getByRole('button').click();
|
|
22
|
+
await page.waitForResponse('**/actions/pages.0.blocks.0.actions.onClick');
|
|
23
|
+
const message = await mailpit.waitForMessage({
|
|
24
|
+
query: `to:worker-${testInfo.parallelIndex}@appsemble.com from:Appsemble Mail App`,
|
|
25
|
+
});
|
|
26
|
+
expect(message.Subject).toBe('Test Email');
|
|
27
|
+
expect(message.From.Name).toBe('Appsemble Mail App');
|
|
28
|
+
expect(message.Text.trim()).toBe('This is a test email.');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=mail.spec.js.map
|
|
@@ -13,16 +13,16 @@ test.describe('Apps', () => {
|
|
|
13
13
|
await page.goto('/en/apps');
|
|
14
14
|
});
|
|
15
15
|
test('should show the page header', async ({ page }) => {
|
|
16
|
-
await expect(page.getByRole('heading', { name: 'All
|
|
16
|
+
await expect(page.getByRole('heading', { name: 'All apps', exact: true })).toBeVisible();
|
|
17
17
|
});
|
|
18
|
-
test('should display “My
|
|
18
|
+
test('should display “My apps” when logged in', async ({ browser, loginUserOnPage, randomTestId, }) => {
|
|
19
19
|
const name = 'Test user';
|
|
20
20
|
const email = `${randomTestId()}@test.com`;
|
|
21
21
|
const password = '1';
|
|
22
22
|
await createUser(name, email, password);
|
|
23
23
|
const page = await browser.newPage({ storageState: undefined });
|
|
24
24
|
await loginUserOnPage(email, password, page);
|
|
25
|
-
await expect(page.getByRole('heading', { name: 'My
|
|
25
|
+
await expect(page.getByRole('heading', { name: 'My apps', exact: true })).toBeVisible();
|
|
26
26
|
await deleteUser(email);
|
|
27
27
|
});
|
|
28
28
|
test('should render list of apps', async ({ page }) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { expect, authenticatedTest as test } from '../../../index.js';
|
|
2
|
+
import pkg from '../../../package.json' with { type: 'json' };
|
|
3
|
+
import { createGroup, createIdpGroupMapper, createOidcIdentityProvider, createRealm, createUpstreamOidcClient, createUser, getAdminToken, joinGroup, requestKc, } from '../../../utils/keycloak-admin.js';
|
|
4
|
+
const { KEYCLOAK_BASE_URL } = process.env;
|
|
5
|
+
// Realm that plays the role of Microsoft Entra ID (the upstream identity provider).
|
|
6
|
+
const upstreamRealm = 'entra-upstream';
|
|
7
|
+
// Realm Appsemble points at; it federates to the upstream realm through Keycloak brokering.
|
|
8
|
+
const brokerRealm = 'appsemble-broker';
|
|
9
|
+
const idpAlias = 'entra-upstream';
|
|
10
|
+
const idpDisplayName = 'Entra';
|
|
11
|
+
const upstreamClientId = 'appsemble-upstream';
|
|
12
|
+
const upstreamClientSecret = 'appsemble-upstream-secret';
|
|
13
|
+
const brokerClientId = 'appsemble-oidc';
|
|
14
|
+
const brokerClientSecret = 'appsemble-oidc-secret';
|
|
15
|
+
const memberEmail = 'entra-member@appsemble.com';
|
|
16
|
+
const outsiderEmail = 'entra-outsider@appsemble.com';
|
|
17
|
+
const userPassword = 'password';
|
|
18
|
+
const upstreamOidcUrl = `${KEYCLOAK_BASE_URL}/realms/${upstreamRealm}/protocol/openid-connect`;
|
|
19
|
+
const brokerOidcUrl = `${KEYCLOAK_BASE_URL}/realms/${brokerRealm}/protocol/openid-connect`;
|
|
20
|
+
// The upstream client redirects the broker hop back to this Keycloak identity broker endpoint.
|
|
21
|
+
const brokerEndpoint = `${KEYCLOAK_BASE_URL}/realms/${brokerRealm}/broker/${idpAlias}/endpoint`;
|
|
22
|
+
let app;
|
|
23
|
+
let organizationId;
|
|
24
|
+
let secret;
|
|
25
|
+
/**
|
|
26
|
+
* Create the Appsemble OIDC client in the broker realm.
|
|
27
|
+
*
|
|
28
|
+
* The brokered user is not a member of any Keycloak group in the broker realm, so this client
|
|
29
|
+
* re-emits the `groups` user attribute imported by the identity provider mapper as a `groups`
|
|
30
|
+
* claim, keeping the upstream group paths intact for Appsemble's role mappings.
|
|
31
|
+
*
|
|
32
|
+
* @param token A Keycloak admin bearer token.
|
|
33
|
+
*/
|
|
34
|
+
async function createBrokerClient(token) {
|
|
35
|
+
await requestKc(`/admin/realms/${brokerRealm}/clients`, {
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
clientAuthenticatorType: 'client-secret',
|
|
38
|
+
clientId: brokerClientId,
|
|
39
|
+
directAccessGrantsEnabled: true,
|
|
40
|
+
enabled: true,
|
|
41
|
+
protocol: 'openid-connect',
|
|
42
|
+
protocolMappers: [
|
|
43
|
+
{
|
|
44
|
+
config: {
|
|
45
|
+
'access.token.claim': 'true',
|
|
46
|
+
'claim.name': 'groups',
|
|
47
|
+
'id.token.claim': 'true',
|
|
48
|
+
'jsonType.label': 'String',
|
|
49
|
+
multivalued: 'true',
|
|
50
|
+
'user.attribute': 'groups',
|
|
51
|
+
'userinfo.token.claim': 'true',
|
|
52
|
+
},
|
|
53
|
+
name: 'groups',
|
|
54
|
+
protocol: 'openid-connect',
|
|
55
|
+
protocolMapper: 'oidc-usermodel-attribute-mapper',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
publicClient: false,
|
|
59
|
+
redirectUris: ['http://appsemble:9999/callback'],
|
|
60
|
+
secret: brokerClientSecret,
|
|
61
|
+
standardFlowEnabled: true,
|
|
62
|
+
webOrigins: ['+'],
|
|
63
|
+
}),
|
|
64
|
+
expectedStatuses: [201],
|
|
65
|
+
method: 'POST',
|
|
66
|
+
token,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function configureRealms() {
|
|
70
|
+
const token = await getAdminToken();
|
|
71
|
+
// Upstream realm: groups, an OIDC client emitting full group paths, and two users.
|
|
72
|
+
await createRealm(token, upstreamRealm);
|
|
73
|
+
const parentGroupId = await createGroup(token, upstreamRealm, 'Appsemble');
|
|
74
|
+
const managersGroupId = await createGroup(token, upstreamRealm, 'Managers', parentGroupId);
|
|
75
|
+
const editorsGroupId = await createGroup(token, upstreamRealm, 'Editors', parentGroupId);
|
|
76
|
+
await createUpstreamOidcClient(token, upstreamRealm, {
|
|
77
|
+
clientId: upstreamClientId,
|
|
78
|
+
clientSecret: upstreamClientSecret,
|
|
79
|
+
redirectUris: [brokerEndpoint],
|
|
80
|
+
});
|
|
81
|
+
const memberId = await createUser(token, upstreamRealm, {
|
|
82
|
+
email: memberEmail,
|
|
83
|
+
firstName: 'Entra',
|
|
84
|
+
lastName: 'Member',
|
|
85
|
+
password: userPassword,
|
|
86
|
+
});
|
|
87
|
+
await joinGroup(token, upstreamRealm, memberId, managersGroupId);
|
|
88
|
+
await joinGroup(token, upstreamRealm, memberId, editorsGroupId);
|
|
89
|
+
// Outsider authenticates against the upstream realm but belongs to no mapped group.
|
|
90
|
+
await createUser(token, upstreamRealm, {
|
|
91
|
+
email: outsiderEmail,
|
|
92
|
+
firstName: 'Entra',
|
|
93
|
+
lastName: 'Outsider',
|
|
94
|
+
password: userPassword,
|
|
95
|
+
});
|
|
96
|
+
// Broker realm: the OIDC identity provider federating to the upstream realm, the group mapper
|
|
97
|
+
// importing the upstream `groups` claim, and the Appsemble client.
|
|
98
|
+
await createRealm(token, brokerRealm);
|
|
99
|
+
await createOidcIdentityProvider(token, brokerRealm, {
|
|
100
|
+
alias: idpAlias,
|
|
101
|
+
authorizationUrl: `${upstreamOidcUrl}/auth`,
|
|
102
|
+
clientId: upstreamClientId,
|
|
103
|
+
clientSecret: upstreamClientSecret,
|
|
104
|
+
displayName: idpDisplayName,
|
|
105
|
+
jwksUrl: `${upstreamOidcUrl}/certs`,
|
|
106
|
+
tokenUrl: `${upstreamOidcUrl}/token`,
|
|
107
|
+
userInfoUrl: `${upstreamOidcUrl}/userinfo`,
|
|
108
|
+
});
|
|
109
|
+
await createIdpGroupMapper(token, brokerRealm, idpAlias);
|
|
110
|
+
await createBrokerClient(token);
|
|
111
|
+
}
|
|
112
|
+
test.describe('App Keycloak brokered Entra OIDC login', () => {
|
|
113
|
+
test.skip(!KEYCLOAK_BASE_URL, 'Keycloak brokered login requires KEYCLOAK_BASE_URL');
|
|
114
|
+
// The scenarios share two fixed Keycloak realms, so their setup and login flows must not race.
|
|
115
|
+
test.describe.configure({ mode: 'serial' });
|
|
116
|
+
test.beforeAll(async ({ createApp, createOrganization, randomTestId, request }) => {
|
|
117
|
+
await configureRealms();
|
|
118
|
+
organizationId = (await createOrganization({ id: randomTestId() })).id;
|
|
119
|
+
app = await createApp(organizationId, `
|
|
120
|
+
name: Keycloak Entra Broker App
|
|
121
|
+
defaultPage: Manager Page
|
|
122
|
+
security:
|
|
123
|
+
default:
|
|
124
|
+
role: Viewer
|
|
125
|
+
policy: everyone
|
|
126
|
+
roles:
|
|
127
|
+
Viewer: {}
|
|
128
|
+
Manager: {}
|
|
129
|
+
Editor: {}
|
|
130
|
+
Auditor: {}
|
|
131
|
+
pages:
|
|
132
|
+
- name: Manager Page
|
|
133
|
+
roles:
|
|
134
|
+
- Manager
|
|
135
|
+
blocks:
|
|
136
|
+
- type: html
|
|
137
|
+
version: ${pkg.version}
|
|
138
|
+
parameters:
|
|
139
|
+
content: <h1>Manager content</h1>
|
|
140
|
+
- name: Editor Page
|
|
141
|
+
roles:
|
|
142
|
+
- Editor
|
|
143
|
+
blocks:
|
|
144
|
+
- type: html
|
|
145
|
+
version: ${pkg.version}
|
|
146
|
+
parameters:
|
|
147
|
+
content: <h1>Editor content</h1>
|
|
148
|
+
- name: Auditor Page
|
|
149
|
+
roles:
|
|
150
|
+
- Auditor
|
|
151
|
+
blocks:
|
|
152
|
+
- type: html
|
|
153
|
+
version: ${pkg.version}
|
|
154
|
+
parameters:
|
|
155
|
+
content: <h1>Auditor content</h1>
|
|
156
|
+
`);
|
|
157
|
+
const response = await request.post(`/api/apps/${app.id}/secrets/oauth2`, {
|
|
158
|
+
data: {
|
|
159
|
+
name: 'Keycloak Entra Broker',
|
|
160
|
+
icon: 'key',
|
|
161
|
+
authorizationUrl: `${brokerOidcUrl}/auth`,
|
|
162
|
+
tokenUrl: `${brokerOidcUrl}/token`,
|
|
163
|
+
clientId: brokerClientId,
|
|
164
|
+
clientSecret: brokerClientSecret,
|
|
165
|
+
userInfoUrl: `${brokerOidcUrl}/userinfo`,
|
|
166
|
+
scope: 'email openid profile',
|
|
167
|
+
roleMappings: [
|
|
168
|
+
{ group: '/Appsemble/Managers', role: 'Manager' },
|
|
169
|
+
{ group: '/Appsemble/Editors', role: 'Editor' },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
expect(response.status()).toBe(201);
|
|
174
|
+
secret = (await response.json());
|
|
175
|
+
});
|
|
176
|
+
test.afterAll(async ({ deleteApp, deleteOrganization }) => {
|
|
177
|
+
if (app?.id != null) {
|
|
178
|
+
await deleteApp(app.id);
|
|
179
|
+
}
|
|
180
|
+
if (organizationId) {
|
|
181
|
+
await deleteOrganization(organizationId);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
test('should map brokered Entra groups to cumulative app roles', async ({ page, visitApp }) => {
|
|
185
|
+
const appUrl = await visitApp(app.id);
|
|
186
|
+
await page.goto(`${appUrl}/Login`);
|
|
187
|
+
await page.getByRole('button', { name: `Login with ${secret.name}` }).click();
|
|
188
|
+
// Broker realm login page: follow the upstream identity provider.
|
|
189
|
+
await page.getByRole('link', { name: idpDisplayName }).click();
|
|
190
|
+
// Upstream realm login form.
|
|
191
|
+
await page.getByRole('textbox', { name: /username or email/i }).fill(memberEmail);
|
|
192
|
+
await page.getByRole('textbox', { exact: true, name: 'Password' }).fill(userPassword);
|
|
193
|
+
await page.getByRole('button', { name: /sign in/i }).click();
|
|
194
|
+
await expect(page.getByRole('heading', { name: 'Manager content' })).toBeVisible();
|
|
195
|
+
await expect(page.getByRole('link', { name: 'Manager Page' })).toBeVisible();
|
|
196
|
+
await expect(page.getByRole('link', { name: 'Editor Page' })).toBeVisible();
|
|
197
|
+
await expect(page.getByRole('link', { name: 'Auditor Page' })).toBeHidden();
|
|
198
|
+
await page.getByRole('link', { name: 'Editor Page' }).click();
|
|
199
|
+
await expect(page.getByRole('heading', { name: 'Editor content' })).toBeVisible();
|
|
200
|
+
await page.goto(`${appUrl}/Auditor%20Page`);
|
|
201
|
+
await expect(page.getByRole('heading', { name: 'Auditor content' })).toBeHidden();
|
|
202
|
+
});
|
|
203
|
+
test('should deny login when no brokered group maps to an app role', async ({ page, visitApp, }) => {
|
|
204
|
+
const appUrl = await visitApp(app.id);
|
|
205
|
+
const verifyResponse = page.waitForResponse((response) => response.request().method() === 'POST' &&
|
|
206
|
+
new URL(response.url()).pathname ===
|
|
207
|
+
`/api/apps/${app.id}/secrets/oauth2/${secret.id}/verify`);
|
|
208
|
+
await page.goto(`${appUrl}/Login`);
|
|
209
|
+
await page.getByRole('button', { name: `Login with ${secret.name}` }).click();
|
|
210
|
+
await page.getByRole('link', { name: idpDisplayName }).click();
|
|
211
|
+
await page.getByRole('textbox', { name: /username or email/i }).fill(outsiderEmail);
|
|
212
|
+
await page.getByRole('textbox', { exact: true, name: 'Password' }).fill(userPassword);
|
|
213
|
+
await page.getByRole('button', { name: /sign in/i }).click();
|
|
214
|
+
expect((await verifyResponse).status()).toBe(403);
|
|
215
|
+
await expect(page.getByText('An unexpected error occurred while logging in')).toBeVisible();
|
|
216
|
+
await expect(page.getByRole('heading', { name: 'Manager content' })).toBeHidden();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
//# sourceMappingURL=keycloak-entra-broker.spec.js.map
|