@appsemble/e2e 0.40.4 → 0.40.5
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 +2 -2
- package/fixtures/test/index.js +2 -1
- package/package.json +5 -4
- 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/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/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.5)
|
|
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.5/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,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base test object with all utility fixtures
|
|
3
3
|
*/
|
|
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>;
|
|
4
|
+
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
5
|
/**
|
|
6
6
|
* Test object with the worker's storage state saved
|
|
7
7
|
*
|
|
8
8
|
* Used for tests that require a logged in user
|
|
9
9
|
*/
|
|
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 & {
|
|
10
|
+
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
11
|
workerStorageState: string;
|
|
12
12
|
}>;
|
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';
|
|
@@ -15,7 +16,7 @@ import { test as trainingFixtures } from './training/index.js';
|
|
|
15
16
|
/**
|
|
16
17
|
* Base test object with all utility fixtures
|
|
17
18
|
*/
|
|
18
|
-
export const baseTest = mergeTests(appFixtures, appCollectionFixtures, demoAppFixtures, groupFixtures, liveAppFixtures, organizationFixtures, resourceFixtures, studioFixtures, testUtilsFixtures, trainingFixtures);
|
|
19
|
+
export const baseTest = mergeTests(accessibilityFixtures, appFixtures, appCollectionFixtures, demoAppFixtures, groupFixtures, liveAppFixtures, organizationFixtures, resourceFixtures, studioFixtures, testUtilsFixtures, trainingFixtures);
|
|
19
20
|
/**
|
|
20
21
|
* Test object with the worker's storage state saved
|
|
21
22
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/e2e",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.5",
|
|
4
4
|
"description": "End-to-end tests used for testing Appsemble apps in an existing environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -40,9 +40,10 @@
|
|
|
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.
|
|
43
|
+
"@appsemble/lang-sdk": "0.40.5",
|
|
44
|
+
"@appsemble/node-utils": "0.40.5",
|
|
45
|
+
"@appsemble/types": "0.40.5",
|
|
46
|
+
"@axe-core/playwright": "4.13.0",
|
|
46
47
|
"@playwright/test": "1.63.0",
|
|
47
48
|
"strip-indent": "^4.0.0"
|
|
48
49
|
},
|
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,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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect, authenticatedTest as test } from '../../../index.js';
|
|
2
2
|
import pkg from '../../../package.json' with { type: 'json' };
|
|
3
|
-
|
|
3
|
+
import { createGroup, createRealm, createUser, getAdminToken, joinGroup, requestKc, } from '../../../utils/keycloak-admin.js';
|
|
4
|
+
const { KEYCLOAK_BASE_URL, KEYCLOAK_REALM = 'appsemble-e2e' } = process.env;
|
|
4
5
|
const clientId = 'appsemble-oidc';
|
|
5
6
|
const clientSecret = 'appsemble-oidc-secret';
|
|
6
7
|
const userEmail = 'keycloak-user@appsemble.com';
|
|
@@ -8,99 +9,12 @@ const userPassword = 'password';
|
|
|
8
9
|
let app;
|
|
9
10
|
let organizationId;
|
|
10
11
|
let secret;
|
|
11
|
-
async function requestKc(path, { body, expectedStatuses, method, token, }) {
|
|
12
|
-
const response = await fetch(`${KEYCLOAK_BASE_URL}${path}`, {
|
|
13
|
-
body,
|
|
14
|
-
headers: {
|
|
15
|
-
authorization: `Bearer ${token}`,
|
|
16
|
-
'content-type': 'application/json',
|
|
17
|
-
},
|
|
18
|
-
method,
|
|
19
|
-
});
|
|
20
|
-
if (!expectedStatuses.includes(response.status)) {
|
|
21
|
-
throw new Error(`${method} ${path} returned ${response.status}: ${await response.text()}`);
|
|
22
|
-
}
|
|
23
|
-
return response;
|
|
24
|
-
}
|
|
25
|
-
async function getAdminToken() {
|
|
26
|
-
for (let attempt = 0; attempt < 60; attempt += 1) {
|
|
27
|
-
try {
|
|
28
|
-
const response = await fetch(`${KEYCLOAK_BASE_URL}/realms/master/protocol/openid-connect/token`, {
|
|
29
|
-
body: new URLSearchParams({
|
|
30
|
-
client_id: 'admin-cli',
|
|
31
|
-
grant_type: 'password',
|
|
32
|
-
password: KEYCLOAK_ADMIN_PASSWORD,
|
|
33
|
-
username: KEYCLOAK_ADMIN_USERNAME,
|
|
34
|
-
}),
|
|
35
|
-
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
36
|
-
method: 'POST',
|
|
37
|
-
});
|
|
38
|
-
if (response.ok) {
|
|
39
|
-
const { access_token: token } = (await response.json());
|
|
40
|
-
return token;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// The service may still be starting.
|
|
45
|
-
}
|
|
46
|
-
await new Promise((resolve) => {
|
|
47
|
-
setTimeout(resolve, 1000);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
throw new Error('Could not obtain Keycloak admin token');
|
|
51
|
-
}
|
|
52
|
-
async function createGroup(token, name, parentGroupId) {
|
|
53
|
-
const path = parentGroupId
|
|
54
|
-
? `/admin/realms/${KEYCLOAK_REALM}/groups/${parentGroupId}/children`
|
|
55
|
-
: `/admin/realms/${KEYCLOAK_REALM}/groups`;
|
|
56
|
-
const response = await requestKc(path, {
|
|
57
|
-
body: JSON.stringify({ name }),
|
|
58
|
-
expectedStatuses: [201],
|
|
59
|
-
method: 'POST',
|
|
60
|
-
token,
|
|
61
|
-
});
|
|
62
|
-
return response.headers.get('location').split('/').pop();
|
|
63
|
-
}
|
|
64
|
-
async function createUser(token) {
|
|
65
|
-
const response = await requestKc(`/admin/realms/${KEYCLOAK_REALM}/users`, {
|
|
66
|
-
body: JSON.stringify({
|
|
67
|
-
credentials: [{ temporary: false, type: 'password', value: userPassword }],
|
|
68
|
-
email: userEmail,
|
|
69
|
-
emailVerified: true,
|
|
70
|
-
enabled: true,
|
|
71
|
-
firstName: 'Keycloak',
|
|
72
|
-
lastName: 'User',
|
|
73
|
-
username: userEmail,
|
|
74
|
-
}),
|
|
75
|
-
expectedStatuses: [201],
|
|
76
|
-
method: 'POST',
|
|
77
|
-
token,
|
|
78
|
-
});
|
|
79
|
-
return response.headers.get('location').split('/').pop();
|
|
80
|
-
}
|
|
81
|
-
async function joinGroup(token, userId, groupId) {
|
|
82
|
-
await requestKc(`/admin/realms/${KEYCLOAK_REALM}/users/${userId}/groups/${groupId}`, {
|
|
83
|
-
expectedStatuses: [204],
|
|
84
|
-
method: 'PUT',
|
|
85
|
-
token,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
12
|
async function configureRealm() {
|
|
89
13
|
const token = await getAdminToken();
|
|
90
|
-
await
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
await requestKc('/admin/realms', {
|
|
96
|
-
body: JSON.stringify({ enabled: true, realm: KEYCLOAK_REALM }),
|
|
97
|
-
expectedStatuses: [201],
|
|
98
|
-
method: 'POST',
|
|
99
|
-
token,
|
|
100
|
-
});
|
|
101
|
-
const parentGroupId = await createGroup(token, 'Appsemble');
|
|
102
|
-
const managersGroupId = await createGroup(token, 'Managers', parentGroupId);
|
|
103
|
-
const editorsGroupId = await createGroup(token, 'Editors', parentGroupId);
|
|
14
|
+
await createRealm(token, KEYCLOAK_REALM);
|
|
15
|
+
const parentGroupId = await createGroup(token, KEYCLOAK_REALM, 'Appsemble');
|
|
16
|
+
const managersGroupId = await createGroup(token, KEYCLOAK_REALM, 'Managers', parentGroupId);
|
|
17
|
+
const editorsGroupId = await createGroup(token, KEYCLOAK_REALM, 'Editors', parentGroupId);
|
|
104
18
|
await requestKc(`/admin/realms/${KEYCLOAK_REALM}/clients`, {
|
|
105
19
|
body: JSON.stringify({
|
|
106
20
|
clientAuthenticatorType: 'client-secret',
|
|
@@ -132,9 +46,14 @@ async function configureRealm() {
|
|
|
132
46
|
method: 'POST',
|
|
133
47
|
token,
|
|
134
48
|
});
|
|
135
|
-
const userId = await createUser(token
|
|
136
|
-
|
|
137
|
-
|
|
49
|
+
const userId = await createUser(token, KEYCLOAK_REALM, {
|
|
50
|
+
email: userEmail,
|
|
51
|
+
firstName: 'Keycloak',
|
|
52
|
+
lastName: 'User',
|
|
53
|
+
password: userPassword,
|
|
54
|
+
});
|
|
55
|
+
await joinGroup(token, KEYCLOAK_REALM, userId, managersGroupId);
|
|
56
|
+
await joinGroup(token, KEYCLOAK_REALM, userId, editorsGroupId);
|
|
138
57
|
}
|
|
139
58
|
test.describe('App Keycloak OIDC login', () => {
|
|
140
59
|
test.skip(!KEYCLOAK_BASE_URL, 'Keycloak OIDC login requires KEYCLOAK_BASE_URL');
|
|
@@ -210,9 +129,9 @@ test.describe('App Keycloak OIDC login', () => {
|
|
|
210
129
|
const appUrl = await visitApp(app.id);
|
|
211
130
|
await page.goto(`${appUrl}/Login`);
|
|
212
131
|
await page.getByRole('button', { name: `Login with ${secret.name}` }).click();
|
|
213
|
-
await page.
|
|
214
|
-
await page.
|
|
215
|
-
await page.
|
|
132
|
+
await page.getByRole('textbox', { name: /username or email/i }).fill(userEmail);
|
|
133
|
+
await page.getByRole('textbox', { exact: true, name: 'Password' }).fill(userPassword);
|
|
134
|
+
await page.getByRole('button', { name: /sign in/i }).click();
|
|
216
135
|
await expect(page.getByRole('heading', { name: 'Manager content' })).toBeVisible();
|
|
217
136
|
await expect(page.getByRole('link', { name: 'Manager Page' })).toBeVisible();
|
|
218
137
|
await expect(page.getByRole('link', { name: 'Editor Page' })).toBeVisible();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect, authenticatedTest as test } from '../../../index.js';
|
|
2
2
|
import pkg from '../../../package.json' with { type: 'json' };
|
|
3
|
-
|
|
3
|
+
import { createGroup, createRealm, createUser, getAdminToken, getSigningCertificate, joinGroup, requestKc, } from '../../../utils/keycloak-admin.js';
|
|
4
|
+
const { KEYCLOAK_BASE_URL, KEYCLOAK_REALM = 'appsemble-e2e' } = process.env;
|
|
4
5
|
const appsembleBaseUrl = 'http://appsemble:9999';
|
|
5
6
|
const samlAttributeNameFormat = 'attribute.nameformat';
|
|
6
7
|
const samlAssertionConsumerUrlPostAttribute = 'saml_assertion_consumer_url_post';
|
|
@@ -13,123 +14,21 @@ let idpCertificate;
|
|
|
13
14
|
let organizationId;
|
|
14
15
|
let secret;
|
|
15
16
|
test.use({ timezoneId: 'Europe/Amsterdam' });
|
|
16
|
-
async function requestKc(path, { body, expectedStatuses, method, token, }) {
|
|
17
|
-
const response = await fetch(`${KEYCLOAK_BASE_URL}${path}`, {
|
|
18
|
-
body,
|
|
19
|
-
headers: {
|
|
20
|
-
authorization: `Bearer ${token}`,
|
|
21
|
-
'content-type': 'application/json',
|
|
22
|
-
},
|
|
23
|
-
method,
|
|
24
|
-
});
|
|
25
|
-
if (!expectedStatuses.includes(response.status)) {
|
|
26
|
-
throw new Error(`${method} ${path} returned ${response.status}: ${await response.text()}`);
|
|
27
|
-
}
|
|
28
|
-
return response;
|
|
29
|
-
}
|
|
30
|
-
async function getAdminToken() {
|
|
31
|
-
for (let attempt = 0; attempt < 60; attempt += 1) {
|
|
32
|
-
try {
|
|
33
|
-
const response = await fetch(`${KEYCLOAK_BASE_URL}/realms/master/protocol/openid-connect/token`, {
|
|
34
|
-
body: new URLSearchParams({
|
|
35
|
-
client_id: 'admin-cli',
|
|
36
|
-
grant_type: 'password',
|
|
37
|
-
password: KEYCLOAK_ADMIN_PASSWORD,
|
|
38
|
-
username: KEYCLOAK_ADMIN_USERNAME,
|
|
39
|
-
}),
|
|
40
|
-
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
41
|
-
method: 'POST',
|
|
42
|
-
});
|
|
43
|
-
if (response.ok) {
|
|
44
|
-
const { access_token: token } = (await response.json());
|
|
45
|
-
return token;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
// The service may still be starting.
|
|
50
|
-
}
|
|
51
|
-
await new Promise((resolve) => {
|
|
52
|
-
setTimeout(resolve, 1000);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
throw new Error('Could not obtain Keycloak admin token');
|
|
56
|
-
}
|
|
57
|
-
async function createGroup(token, name, parentGroupId) {
|
|
58
|
-
const path = parentGroupId
|
|
59
|
-
? `/admin/realms/${KEYCLOAK_REALM}/groups/${parentGroupId}/children`
|
|
60
|
-
: `/admin/realms/${KEYCLOAK_REALM}/groups`;
|
|
61
|
-
const response = await requestKc(path, {
|
|
62
|
-
body: JSON.stringify({ name }),
|
|
63
|
-
expectedStatuses: [201],
|
|
64
|
-
method: 'POST',
|
|
65
|
-
token,
|
|
66
|
-
});
|
|
67
|
-
return response.headers.get('location').split('/').pop();
|
|
68
|
-
}
|
|
69
|
-
async function createUser(token) {
|
|
70
|
-
const response = await requestKc(`/admin/realms/${KEYCLOAK_REALM}/users`, {
|
|
71
|
-
body: JSON.stringify({
|
|
72
|
-
credentials: [{ temporary: false, type: 'password', value: userPassword }],
|
|
73
|
-
email: userEmail,
|
|
74
|
-
emailVerified: true,
|
|
75
|
-
enabled: true,
|
|
76
|
-
firstName: 'Keycloak',
|
|
77
|
-
lastName: 'SAML User',
|
|
78
|
-
username: userEmail,
|
|
79
|
-
}),
|
|
80
|
-
expectedStatuses: [201],
|
|
81
|
-
method: 'POST',
|
|
82
|
-
token,
|
|
83
|
-
});
|
|
84
|
-
return response.headers.get('location').split('/').pop();
|
|
85
|
-
}
|
|
86
|
-
function wrapCertificate(certificate) {
|
|
87
|
-
const lines = certificate.match(/.{1,64}/g);
|
|
88
|
-
if (!lines) {
|
|
89
|
-
throw new Error('Could not wrap Keycloak signing certificate');
|
|
90
|
-
}
|
|
91
|
-
return `-----BEGIN CERTIFICATE-----\n${lines.join('\n')}\n-----END CERTIFICATE-----`;
|
|
92
|
-
}
|
|
93
|
-
async function getSigningCertificate(token) {
|
|
94
|
-
const response = await requestKc(`/admin/realms/${KEYCLOAK_REALM}/keys`, {
|
|
95
|
-
expectedStatuses: [200],
|
|
96
|
-
method: 'GET',
|
|
97
|
-
token,
|
|
98
|
-
});
|
|
99
|
-
const { keys } = (await response.json());
|
|
100
|
-
const certificate = keys.find((key) => key.use === 'SIG' && key.status === 'ACTIVE' && key.certificate)?.certificate;
|
|
101
|
-
if (!certificate) {
|
|
102
|
-
throw new Error('Could not find Keycloak signing certificate');
|
|
103
|
-
}
|
|
104
|
-
return wrapCertificate(certificate);
|
|
105
|
-
}
|
|
106
|
-
async function joinGroup(token, userId, groupId) {
|
|
107
|
-
await requestKc(`/admin/realms/${KEYCLOAK_REALM}/users/${userId}/groups/${groupId}`, {
|
|
108
|
-
expectedStatuses: [204],
|
|
109
|
-
method: 'PUT',
|
|
110
|
-
token,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
17
|
async function configureRealm() {
|
|
114
18
|
const token = await getAdminToken();
|
|
115
|
-
await
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
19
|
+
await createRealm(token, KEYCLOAK_REALM);
|
|
20
|
+
idpCertificate = await getSigningCertificate(token, KEYCLOAK_REALM);
|
|
21
|
+
const parentGroupId = await createGroup(token, KEYCLOAK_REALM, 'Appsemble');
|
|
22
|
+
const managersGroupId = await createGroup(token, KEYCLOAK_REALM, 'Managers', parentGroupId);
|
|
23
|
+
const editorsGroupId = await createGroup(token, KEYCLOAK_REALM, 'Editors', parentGroupId);
|
|
24
|
+
const userId = await createUser(token, KEYCLOAK_REALM, {
|
|
25
|
+
email: userEmail,
|
|
26
|
+
firstName: 'Keycloak',
|
|
27
|
+
lastName: 'SAML User',
|
|
28
|
+
password: userPassword,
|
|
125
29
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const managersGroupId = await createGroup(token, 'Managers', parentGroupId);
|
|
129
|
-
const editorsGroupId = await createGroup(token, 'Editors', parentGroupId);
|
|
130
|
-
const userId = await createUser(token);
|
|
131
|
-
await joinGroup(token, userId, managersGroupId);
|
|
132
|
-
await joinGroup(token, userId, editorsGroupId);
|
|
30
|
+
await joinGroup(token, KEYCLOAK_REALM, userId, managersGroupId);
|
|
31
|
+
await joinGroup(token, KEYCLOAK_REALM, userId, editorsGroupId);
|
|
133
32
|
}
|
|
134
33
|
async function createSamlClient(token, appId, secretId) {
|
|
135
34
|
const samlBaseUrl = `${appsembleBaseUrl}/api/apps/${appId}/saml/${secretId}`;
|
|
@@ -278,9 +177,9 @@ test.describe('App Keycloak SAML login', () => {
|
|
|
278
177
|
const appUrl = await visitApp(app.id);
|
|
279
178
|
await page.goto(`${appUrl}/Login`);
|
|
280
179
|
await page.getByRole('button', { name: `Login with ${secret.name}` }).click();
|
|
281
|
-
await page.
|
|
282
|
-
await page.
|
|
283
|
-
await page.
|
|
180
|
+
await page.getByRole('textbox', { name: /username or email/i }).fill(userEmail);
|
|
181
|
+
await page.getByRole('textbox', { exact: true, name: 'Password' }).fill(userPassword);
|
|
182
|
+
await page.getByRole('button', { name: /sign in/i }).click();
|
|
284
183
|
await expect(page.getByRole('heading', { name: 'Manager content' })).toBeVisible();
|
|
285
184
|
await expect(page.getByRole('link', { name: 'Manager Page' })).toBeVisible();
|
|
286
185
|
await expect(page.getByRole('link', { name: 'Editor Page' })).toBeVisible();
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform an authenticated request against the Keycloak admin REST API.
|
|
3
|
+
*
|
|
4
|
+
* @param path The path relative to `KEYCLOAK_BASE_URL`.
|
|
5
|
+
* @param options The request options: a serialized `body`, the `expectedStatuses` treated as
|
|
6
|
+
* successful, the HTTP `method`, and a Keycloak admin bearer `token`.
|
|
7
|
+
* @returns The raw fetch response.
|
|
8
|
+
*/
|
|
9
|
+
export declare function requestKc(path: string, { body, expectedStatuses, method, token, }: {
|
|
10
|
+
body?: string;
|
|
11
|
+
expectedStatuses: number[];
|
|
12
|
+
method: 'DELETE' | 'GET' | 'POST' | 'PUT';
|
|
13
|
+
token: string;
|
|
14
|
+
}): Promise<Response>;
|
|
15
|
+
/**
|
|
16
|
+
* Obtain a Keycloak admin token from the `master` realm.
|
|
17
|
+
*
|
|
18
|
+
* The Keycloak service may still be starting when the tests begin, so this retries for a while.
|
|
19
|
+
*
|
|
20
|
+
* @returns The `admin-cli` access token.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAdminToken(): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Recreate a realm from scratch by deleting any existing realm and creating an empty one.
|
|
25
|
+
*
|
|
26
|
+
* @param token A Keycloak admin bearer token.
|
|
27
|
+
* @param realm The realm name.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createRealm(token: string, realm: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a group, optionally nested under a parent group.
|
|
32
|
+
*
|
|
33
|
+
* @param token A Keycloak admin bearer token.
|
|
34
|
+
* @param realm The realm name.
|
|
35
|
+
* @param name The group name.
|
|
36
|
+
* @param parentGroupId The id of the parent group, when creating a nested group.
|
|
37
|
+
* @returns The id of the created group.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createGroup(token: string, realm: string, name: string, parentGroupId?: string): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Create an enabled user with a permanent password.
|
|
42
|
+
*
|
|
43
|
+
* @param token A Keycloak admin bearer token.
|
|
44
|
+
* @param realm The realm name.
|
|
45
|
+
* @param user The user to create: `email` (also used as the username), `firstName`, `lastName`,
|
|
46
|
+
* and `password`.
|
|
47
|
+
* @returns The id of the created user.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createUser(token: string, realm: string, { email, firstName, lastName, password, }: {
|
|
50
|
+
email: string;
|
|
51
|
+
firstName: string;
|
|
52
|
+
lastName: string;
|
|
53
|
+
password: string;
|
|
54
|
+
}): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Add a user to a group.
|
|
57
|
+
*
|
|
58
|
+
* @param token A Keycloak admin bearer token.
|
|
59
|
+
* @param realm The realm name.
|
|
60
|
+
* @param userId The user id.
|
|
61
|
+
* @param groupId The group id.
|
|
62
|
+
*/
|
|
63
|
+
export declare function joinGroup(token: string, realm: string, userId: string, groupId: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch the active PEM-wrapped signing certificate of a realm.
|
|
66
|
+
*
|
|
67
|
+
* @param token A Keycloak admin bearer token.
|
|
68
|
+
* @param realm The realm name.
|
|
69
|
+
* @returns The PEM-wrapped signing certificate.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getSigningCertificate(token: string, realm: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Create a confidential OIDC client whose tokens carry group memberships as a `groups` claim.
|
|
74
|
+
*
|
|
75
|
+
* This mirrors the client the plain OIDC login test uses, but points its redirect URI at a
|
|
76
|
+
* Keycloak identity broker endpoint so a broker realm can federate to this realm.
|
|
77
|
+
*
|
|
78
|
+
* @param token A Keycloak admin bearer token.
|
|
79
|
+
* @param realm The upstream realm name.
|
|
80
|
+
* @param client The client to create: `clientId`, `clientSecret`, and the allowed `redirectUris`
|
|
81
|
+
* (typically the broker endpoint).
|
|
82
|
+
*/
|
|
83
|
+
export declare function createUpstreamOidcClient(token: string, realm: string, { clientId, clientSecret, redirectUris, }: {
|
|
84
|
+
clientId: string;
|
|
85
|
+
clientSecret: string;
|
|
86
|
+
redirectUris: string[];
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Create an OIDC identity provider that federates a broker realm to an upstream realm.
|
|
90
|
+
*
|
|
91
|
+
* @param token A Keycloak admin bearer token.
|
|
92
|
+
* @param realm The broker realm name.
|
|
93
|
+
* @param config The identity provider configuration: the `alias`, the `displayName` shown on the
|
|
94
|
+
* broker login page, the upstream `authorizationUrl`, `tokenUrl`, `userInfoUrl`, and `jwksUrl`
|
|
95
|
+
* endpoints, and the `clientId` and `clientSecret` registered in the upstream realm.
|
|
96
|
+
*/
|
|
97
|
+
export declare function createOidcIdentityProvider(token: string, realm: string, { alias, authorizationUrl, clientId, clientSecret, displayName, jwksUrl, tokenUrl, userInfoUrl, }: {
|
|
98
|
+
alias: string;
|
|
99
|
+
authorizationUrl: string;
|
|
100
|
+
clientId: string;
|
|
101
|
+
clientSecret: string;
|
|
102
|
+
displayName: string;
|
|
103
|
+
jwksUrl: string;
|
|
104
|
+
tokenUrl: string;
|
|
105
|
+
userInfoUrl: string;
|
|
106
|
+
}): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Add a mapper that imports the upstream `groups` claim into a `groups` attribute on brokered
|
|
109
|
+
* users, so a downstream client in the broker realm can re-emit it as a `groups` claim.
|
|
110
|
+
*
|
|
111
|
+
* @param token A Keycloak admin bearer token.
|
|
112
|
+
* @param realm The broker realm name.
|
|
113
|
+
* @param alias The identity provider alias.
|
|
114
|
+
*/
|
|
115
|
+
export declare function createIdpGroupMapper(token: string, realm: string, alias: string): Promise<void>;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
const { KEYCLOAK_ADMIN_PASSWORD = 'password', KEYCLOAK_ADMIN_USERNAME = 'admin', KEYCLOAK_BASE_URL, } = process.env;
|
|
2
|
+
/**
|
|
3
|
+
* Perform an authenticated request against the Keycloak admin REST API.
|
|
4
|
+
*
|
|
5
|
+
* @param path The path relative to `KEYCLOAK_BASE_URL`.
|
|
6
|
+
* @param options The request options: a serialized `body`, the `expectedStatuses` treated as
|
|
7
|
+
* successful, the HTTP `method`, and a Keycloak admin bearer `token`.
|
|
8
|
+
* @returns The raw fetch response.
|
|
9
|
+
*/
|
|
10
|
+
export async function requestKc(path, { body, expectedStatuses, method, token, }) {
|
|
11
|
+
const response = await fetch(`${KEYCLOAK_BASE_URL}${path}`, {
|
|
12
|
+
body,
|
|
13
|
+
headers: {
|
|
14
|
+
authorization: `Bearer ${token}`,
|
|
15
|
+
'content-type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
method,
|
|
18
|
+
});
|
|
19
|
+
if (!expectedStatuses.includes(response.status)) {
|
|
20
|
+
throw new Error(`${method} ${path} returned ${response.status}: ${await response.text()}`);
|
|
21
|
+
}
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Obtain a Keycloak admin token from the `master` realm.
|
|
26
|
+
*
|
|
27
|
+
* The Keycloak service may still be starting when the tests begin, so this retries for a while.
|
|
28
|
+
*
|
|
29
|
+
* @returns The `admin-cli` access token.
|
|
30
|
+
*/
|
|
31
|
+
export async function getAdminToken() {
|
|
32
|
+
for (let attempt = 0; attempt < 60; attempt += 1) {
|
|
33
|
+
try {
|
|
34
|
+
const response = await fetch(`${KEYCLOAK_BASE_URL}/realms/master/protocol/openid-connect/token`, {
|
|
35
|
+
body: new URLSearchParams({
|
|
36
|
+
client_id: 'admin-cli',
|
|
37
|
+
grant_type: 'password',
|
|
38
|
+
password: KEYCLOAK_ADMIN_PASSWORD,
|
|
39
|
+
username: KEYCLOAK_ADMIN_USERNAME,
|
|
40
|
+
}),
|
|
41
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
42
|
+
method: 'POST',
|
|
43
|
+
});
|
|
44
|
+
if (response.ok) {
|
|
45
|
+
const { access_token: token } = (await response.json());
|
|
46
|
+
return token;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// The service may still be starting.
|
|
51
|
+
}
|
|
52
|
+
await new Promise((resolve) => {
|
|
53
|
+
setTimeout(resolve, 1000);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
throw new Error('Could not obtain Keycloak admin token');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Recreate a realm from scratch by deleting any existing realm and creating an empty one.
|
|
60
|
+
*
|
|
61
|
+
* @param token A Keycloak admin bearer token.
|
|
62
|
+
* @param realm The realm name.
|
|
63
|
+
*/
|
|
64
|
+
export async function createRealm(token, realm) {
|
|
65
|
+
await requestKc(`/admin/realms/${realm}`, {
|
|
66
|
+
expectedStatuses: [204, 404],
|
|
67
|
+
method: 'DELETE',
|
|
68
|
+
token,
|
|
69
|
+
});
|
|
70
|
+
await requestKc('/admin/realms', {
|
|
71
|
+
body: JSON.stringify({ enabled: true, realm }),
|
|
72
|
+
expectedStatuses: [201],
|
|
73
|
+
method: 'POST',
|
|
74
|
+
token,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a group, optionally nested under a parent group.
|
|
79
|
+
*
|
|
80
|
+
* @param token A Keycloak admin bearer token.
|
|
81
|
+
* @param realm The realm name.
|
|
82
|
+
* @param name The group name.
|
|
83
|
+
* @param parentGroupId The id of the parent group, when creating a nested group.
|
|
84
|
+
* @returns The id of the created group.
|
|
85
|
+
*/
|
|
86
|
+
export async function createGroup(token, realm, name, parentGroupId) {
|
|
87
|
+
const path = parentGroupId
|
|
88
|
+
? `/admin/realms/${realm}/groups/${parentGroupId}/children`
|
|
89
|
+
: `/admin/realms/${realm}/groups`;
|
|
90
|
+
const response = await requestKc(path, {
|
|
91
|
+
body: JSON.stringify({ name }),
|
|
92
|
+
expectedStatuses: [201],
|
|
93
|
+
method: 'POST',
|
|
94
|
+
token,
|
|
95
|
+
});
|
|
96
|
+
return response.headers.get('location').split('/').pop();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create an enabled user with a permanent password.
|
|
100
|
+
*
|
|
101
|
+
* @param token A Keycloak admin bearer token.
|
|
102
|
+
* @param realm The realm name.
|
|
103
|
+
* @param user The user to create: `email` (also used as the username), `firstName`, `lastName`,
|
|
104
|
+
* and `password`.
|
|
105
|
+
* @returns The id of the created user.
|
|
106
|
+
*/
|
|
107
|
+
export async function createUser(token, realm, { email, firstName, lastName, password, }) {
|
|
108
|
+
const response = await requestKc(`/admin/realms/${realm}/users`, {
|
|
109
|
+
body: JSON.stringify({
|
|
110
|
+
credentials: [{ temporary: false, type: 'password', value: password }],
|
|
111
|
+
email,
|
|
112
|
+
emailVerified: true,
|
|
113
|
+
enabled: true,
|
|
114
|
+
firstName,
|
|
115
|
+
lastName,
|
|
116
|
+
username: email,
|
|
117
|
+
}),
|
|
118
|
+
expectedStatuses: [201],
|
|
119
|
+
method: 'POST',
|
|
120
|
+
token,
|
|
121
|
+
});
|
|
122
|
+
return response.headers.get('location').split('/').pop();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Add a user to a group.
|
|
126
|
+
*
|
|
127
|
+
* @param token A Keycloak admin bearer token.
|
|
128
|
+
* @param realm The realm name.
|
|
129
|
+
* @param userId The user id.
|
|
130
|
+
* @param groupId The group id.
|
|
131
|
+
*/
|
|
132
|
+
export async function joinGroup(token, realm, userId, groupId) {
|
|
133
|
+
await requestKc(`/admin/realms/${realm}/users/${userId}/groups/${groupId}`, {
|
|
134
|
+
expectedStatuses: [204],
|
|
135
|
+
method: 'PUT',
|
|
136
|
+
token,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function wrapCertificate(certificate) {
|
|
140
|
+
const lines = certificate.match(/.{1,64}/g);
|
|
141
|
+
if (!lines) {
|
|
142
|
+
throw new Error('Could not wrap Keycloak signing certificate');
|
|
143
|
+
}
|
|
144
|
+
return `-----BEGIN CERTIFICATE-----\n${lines.join('\n')}\n-----END CERTIFICATE-----`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Fetch the active PEM-wrapped signing certificate of a realm.
|
|
148
|
+
*
|
|
149
|
+
* @param token A Keycloak admin bearer token.
|
|
150
|
+
* @param realm The realm name.
|
|
151
|
+
* @returns The PEM-wrapped signing certificate.
|
|
152
|
+
*/
|
|
153
|
+
export async function getSigningCertificate(token, realm) {
|
|
154
|
+
const response = await requestKc(`/admin/realms/${realm}/keys`, {
|
|
155
|
+
expectedStatuses: [200],
|
|
156
|
+
method: 'GET',
|
|
157
|
+
token,
|
|
158
|
+
});
|
|
159
|
+
const { keys } = (await response.json());
|
|
160
|
+
const certificate = keys.find((key) => key.use === 'SIG' && key.status === 'ACTIVE' && key.certificate)?.certificate;
|
|
161
|
+
if (!certificate) {
|
|
162
|
+
throw new Error('Could not find Keycloak signing certificate');
|
|
163
|
+
}
|
|
164
|
+
return wrapCertificate(certificate);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a confidential OIDC client whose tokens carry group memberships as a `groups` claim.
|
|
168
|
+
*
|
|
169
|
+
* This mirrors the client the plain OIDC login test uses, but points its redirect URI at a
|
|
170
|
+
* Keycloak identity broker endpoint so a broker realm can federate to this realm.
|
|
171
|
+
*
|
|
172
|
+
* @param token A Keycloak admin bearer token.
|
|
173
|
+
* @param realm The upstream realm name.
|
|
174
|
+
* @param client The client to create: `clientId`, `clientSecret`, and the allowed `redirectUris`
|
|
175
|
+
* (typically the broker endpoint).
|
|
176
|
+
*/
|
|
177
|
+
export async function createUpstreamOidcClient(token, realm, { clientId, clientSecret, redirectUris, }) {
|
|
178
|
+
await requestKc(`/admin/realms/${realm}/clients`, {
|
|
179
|
+
body: JSON.stringify({
|
|
180
|
+
clientAuthenticatorType: 'client-secret',
|
|
181
|
+
clientId,
|
|
182
|
+
directAccessGrantsEnabled: true,
|
|
183
|
+
enabled: true,
|
|
184
|
+
protocol: 'openid-connect',
|
|
185
|
+
protocolMappers: [
|
|
186
|
+
{
|
|
187
|
+
config: {
|
|
188
|
+
'access.token.claim': 'true',
|
|
189
|
+
'claim.name': 'groups',
|
|
190
|
+
'full.path': 'true',
|
|
191
|
+
'id.token.claim': 'true',
|
|
192
|
+
'userinfo.token.claim': 'true',
|
|
193
|
+
},
|
|
194
|
+
name: 'groups',
|
|
195
|
+
protocol: 'openid-connect',
|
|
196
|
+
protocolMapper: 'oidc-group-membership-mapper',
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
publicClient: false,
|
|
200
|
+
redirectUris,
|
|
201
|
+
secret: clientSecret,
|
|
202
|
+
standardFlowEnabled: true,
|
|
203
|
+
webOrigins: ['+'],
|
|
204
|
+
}),
|
|
205
|
+
expectedStatuses: [201],
|
|
206
|
+
method: 'POST',
|
|
207
|
+
token,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Create an OIDC identity provider that federates a broker realm to an upstream realm.
|
|
212
|
+
*
|
|
213
|
+
* @param token A Keycloak admin bearer token.
|
|
214
|
+
* @param realm The broker realm name.
|
|
215
|
+
* @param config The identity provider configuration: the `alias`, the `displayName` shown on the
|
|
216
|
+
* broker login page, the upstream `authorizationUrl`, `tokenUrl`, `userInfoUrl`, and `jwksUrl`
|
|
217
|
+
* endpoints, and the `clientId` and `clientSecret` registered in the upstream realm.
|
|
218
|
+
*/
|
|
219
|
+
export async function createOidcIdentityProvider(token, realm, { alias, authorizationUrl, clientId, clientSecret, displayName, jwksUrl, tokenUrl, userInfoUrl, }) {
|
|
220
|
+
await requestKc(`/admin/realms/${realm}/identity-provider/instances`, {
|
|
221
|
+
body: JSON.stringify({
|
|
222
|
+
alias,
|
|
223
|
+
displayName,
|
|
224
|
+
enabled: true,
|
|
225
|
+
providerId: 'oidc',
|
|
226
|
+
storeToken: false,
|
|
227
|
+
trustEmail: true,
|
|
228
|
+
config: {
|
|
229
|
+
authorizationUrl,
|
|
230
|
+
clientAuthMethod: 'client_secret_post',
|
|
231
|
+
clientId,
|
|
232
|
+
clientSecret,
|
|
233
|
+
defaultScope: 'openid email profile',
|
|
234
|
+
jwksUrl,
|
|
235
|
+
syncMode: 'FORCE',
|
|
236
|
+
tokenUrl,
|
|
237
|
+
useJwksUrl: 'true',
|
|
238
|
+
userInfoUrl,
|
|
239
|
+
validateSignature: 'true',
|
|
240
|
+
},
|
|
241
|
+
}),
|
|
242
|
+
expectedStatuses: [201],
|
|
243
|
+
method: 'POST',
|
|
244
|
+
token,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Add a mapper that imports the upstream `groups` claim into a `groups` attribute on brokered
|
|
249
|
+
* users, so a downstream client in the broker realm can re-emit it as a `groups` claim.
|
|
250
|
+
*
|
|
251
|
+
* @param token A Keycloak admin bearer token.
|
|
252
|
+
* @param realm The broker realm name.
|
|
253
|
+
* @param alias The identity provider alias.
|
|
254
|
+
*/
|
|
255
|
+
export async function createIdpGroupMapper(token, realm, alias) {
|
|
256
|
+
await requestKc(`/admin/realms/${realm}/identity-provider/instances/${alias}/mappers`, {
|
|
257
|
+
body: JSON.stringify({
|
|
258
|
+
config: {
|
|
259
|
+
claim: 'groups',
|
|
260
|
+
syncMode: 'FORCE',
|
|
261
|
+
'user.attribute': 'groups',
|
|
262
|
+
},
|
|
263
|
+
identityProviderAlias: alias,
|
|
264
|
+
identityProviderMapper: 'oidc-user-attribute-idp-mapper',
|
|
265
|
+
name: 'groups',
|
|
266
|
+
}),
|
|
267
|
+
expectedStatuses: [201],
|
|
268
|
+
method: 'POST',
|
|
269
|
+
token,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=keycloak-admin.js.map
|