@appsemble/e2e 0.40.16 → 0.41.0

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 CHANGED
@@ -1,8 +1,8 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.40.16/config/assets/logo.svg) Appsemble End 2 End Tests
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.41.0/config/assets/logo.svg) 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
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.40.16/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.40.16)
5
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.41.0/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.41.0)
6
6
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
7
7
 
8
8
  ## Table of Contents
@@ -124,5 +124,5 @@ When writing end-to-end tests, have a look at the
124
124
 
125
125
  ## License
126
126
 
127
- [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.40.16/LICENSE.md) ©
127
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.41.0/LICENSE.md) ©
128
128
  [Appsemble](https://appsemble.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/e2e",
3
- "version": "0.40.16",
3
+ "version": "0.41.0",
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,9 @@
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.16",
44
- "@appsemble/node-utils": "0.40.16",
45
- "@appsemble/types": "0.40.16",
43
+ "@appsemble/lang-sdk": "0.41.0",
44
+ "@appsemble/node-utils": "0.41.0",
45
+ "@appsemble/types": "0.41.0",
46
46
  "@axe-core/playwright": "4.14.0",
47
47
  "@playwright/test": "1.64.1",
48
48
  "mailpit-api": "^2.1.0",
@@ -107,7 +107,9 @@ test.describe('App Collections', () => {
107
107
  await page.click('#app-options-menu');
108
108
  await page.getByRole('button', { name: 'Add to collection' }).click();
109
109
  await page.getByRole('combobox').selectOption({ label: appCollectionName });
110
+ const addResponse = page.waitForResponse(`**/api/app-collections/${appCollectionId}/apps`);
110
111
  await page.locator('form').getByRole('button', { name: 'Add to collection' }).click();
112
+ await addResponse;
111
113
  await page.goto(`/en/collections/${appCollectionId}`);
112
114
  await expect(page.getByRole('link', { name: appName })).toBeVisible();
113
115
  await deleteApp(id);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,261 @@
1
+ import { createUser as createStudioUser, deleteUser as deleteStudioUser, } from '@appsemble/node-utils';
2
+ import { PredefinedOrganizationRole } from '@appsemble/types';
3
+ import { authenticatedTest as test, expect } from '../../../index.js';
4
+ import { createGroup, createRealm, createUpstreamOidcClient, createUser, getAdminToken, joinGroup, requestKc, } from '../../../utils/keycloak-admin.js';
5
+ const { KEYCLOAK_BASE_URL, KEYCLOAK_REALM = 'appsemble-e2e' } = process.env;
6
+ const clientId = 'appsemble-studio';
7
+ const clientSecret = 'studio-e2e-secret';
8
+ const password = 'studio-e2e-password';
9
+ async function signInWithPassword(page, email) {
10
+ await page.goto('/en/login');
11
+ await page.getByRole('textbox', { name: 'Email', exact: true }).fill(email);
12
+ await page.getByLabel('Password').fill(password);
13
+ const response = page.waitForResponse('**/api/auth/email/login');
14
+ await page.getByRole('button', { name: 'Login', exact: true }).click();
15
+ const login = await response;
16
+ expect(login.status()).toBe(200);
17
+ await expect(page.getByText('My apps', { exact: true })).toBeVisible();
18
+ return (await login.json()).access_token;
19
+ }
20
+ async function submitKeycloakPassword(page, organizationId) {
21
+ const callback = page.waitForResponse(`**/api/organizations/${organizationId}/sso/callback`);
22
+ await page.getByRole('textbox', { name: 'Password', exact: true }).fill(password);
23
+ await page.getByRole('button', { name: /sign in/i }).click();
24
+ const response = await callback;
25
+ expect(response.status()).toBe(200);
26
+ return (await response.json()).access_token;
27
+ }
28
+ async function signInAtKeycloak(page, email, organizationId) {
29
+ await page.getByRole('textbox', { name: /username or email/i }).fill(email);
30
+ return submitKeycloakPassword(page, organizationId);
31
+ }
32
+ test.describe('Studio organization Keycloak OIDC', () => {
33
+ test.skip(!KEYCLOAK_BASE_URL, 'Studio OIDC login requires KEYCLOAK_BASE_URL');
34
+ test('Owners configure SSO and staff manage their group access and linked identity', async ({ baseURL, browser, createOrganization, page, randomTestId, request, }, testInfo) => {
35
+ test.setTimeout(180000);
36
+ if (!baseURL) {
37
+ throw new Error('The Studio OIDC test requires a base URL');
38
+ }
39
+ const token = await getAdminToken();
40
+ await createRealm(token, KEYCLOAK_REALM);
41
+ const parent = await createGroup(token, KEYCLOAK_REALM, 'Appsemble');
42
+ const owners = await createGroup(token, KEYCLOAK_REALM, 'Owners', parent);
43
+ const translators = await createGroup(token, KEYCLOAK_REALM, 'Translators', parent);
44
+ const contentManagers = await createGroup(token, KEYCLOAK_REALM, 'ContentManagers', parent);
45
+ await createUpstreamOidcClient(token, KEYCLOAK_REALM, {
46
+ clientId,
47
+ clientSecret,
48
+ redirectUris: [new URL('/callback', baseURL).href],
49
+ requirePkce: true,
50
+ });
51
+ const ownerEmail = `worker-${testInfo.parallelIndex}@appsemble.com`;
52
+ const owner = await createUser(token, KEYCLOAK_REALM, {
53
+ email: ownerEmail,
54
+ firstName: 'Studio',
55
+ lastName: 'Owner',
56
+ password,
57
+ });
58
+ await joinGroup(token, KEYCLOAK_REALM, owner, owners);
59
+ const staffEmail = `staff-${randomTestId()}@appsemble.com`;
60
+ const staff = await createUser(token, KEYCLOAK_REALM, {
61
+ email: staffEmail,
62
+ firstName: 'Studio',
63
+ lastName: 'Staff',
64
+ password,
65
+ });
66
+ await joinGroup(token, KEYCLOAK_REALM, staff, translators);
67
+ await joinGroup(token, KEYCLOAK_REALM, staff, contentManagers);
68
+ const unlinkEmail = `unlink-${randomTestId()}@appsemble.com`;
69
+ const unlinkUser = await createUser(token, KEYCLOAK_REALM, {
70
+ email: unlinkEmail,
71
+ firstName: 'Studio',
72
+ lastName: 'Unlink',
73
+ password,
74
+ });
75
+ await joinGroup(token, KEYCLOAK_REALM, unlinkUser, translators);
76
+ const organization = await createOrganization({
77
+ id: randomTestId(),
78
+ name: 'Studio SSO Integration',
79
+ });
80
+ let ownerAccessToken;
81
+ let cleanupFailure;
82
+ try {
83
+ await createStudioUser('Studio Unlink', unlinkEmail, password);
84
+ await page.goto(`/en/organizations/${organization.id}/sso`);
85
+ await page
86
+ .getByRole('textbox', { name: 'Provider name', exact: true })
87
+ .fill('Staff Keycloak');
88
+ await page
89
+ .getByRole('textbox', { name: 'Issuer URL', exact: true })
90
+ .fill(`${KEYCLOAK_BASE_URL}/realms/${KEYCLOAK_REALM}`);
91
+ await page.getByRole('textbox', { name: 'Client ID', exact: true }).fill(clientId);
92
+ await page.getByLabel('Client secret', { exact: true }).fill(clientSecret);
93
+ for (const [index, group, role] of [
94
+ [1, '/Appsemble/Owners', PredefinedOrganizationRole.Owner],
95
+ [2, '/Appsemble/Translators', PredefinedOrganizationRole.AppTranslator],
96
+ [3, '/Appsemble/ContentManagers', PredefinedOrganizationRole.AppContentsManager],
97
+ ]) {
98
+ await page.getByRole('button', { name: 'Add group mapping', exact: true }).click();
99
+ const mapping = page.getByRole('group', { name: `Group mapping ${index}`, exact: true });
100
+ await mapping.getByRole('textbox', { name: 'Group', exact: true }).fill(group);
101
+ await mapping
102
+ .getByRole('combobox', { name: 'Organization role', exact: true })
103
+ .selectOption(role);
104
+ }
105
+ await page.getByRole('button', { name: 'Verify connection and save', exact: true }).click();
106
+ ownerAccessToken = await signInAtKeycloak(page, ownerEmail, organization.id);
107
+ await expect(page).toHaveURL(new RegExp(`/organizations/${organization.id}(?:/|$)`));
108
+ await page.goto(`/en/organizations/${organization.id}/sso`);
109
+ await page
110
+ .getByRole('combobox', { name: 'Organization sign-in policy', exact: true })
111
+ .selectOption('required');
112
+ await page.getByRole('button', { name: 'Save single sign-on settings', exact: true }).click();
113
+ await expect(page.getByText('Single sign-on settings saved.', { exact: true })).toBeVisible();
114
+ expect((await request.get(`/api/organizations/${organization.id}/members`)).status()).toBe(403);
115
+ const firstContext = await browser.newContext({
116
+ baseURL,
117
+ ignoreHTTPSErrors: true,
118
+ storageState: { cookies: [], origins: [] },
119
+ });
120
+ const firstStaffPage = await firstContext.newPage();
121
+ const returningContext = await browser.newContext({
122
+ baseURL,
123
+ ignoreHTTPSErrors: true,
124
+ storageState: { cookies: [], origins: [] },
125
+ });
126
+ const personalContext = await browser.newContext({
127
+ baseURL,
128
+ ignoreHTTPSErrors: true,
129
+ storageState: { cookies: [], origins: [] },
130
+ });
131
+ try {
132
+ await firstStaffPage.goto(`/en/login?organization=${organization.id}`);
133
+ await expect(firstStaffPage.getByRole('textbox', { name: 'Password', exact: true })).toBeHidden();
134
+ await firstStaffPage
135
+ .getByRole('button', { name: 'Login with Staff Keycloak', exact: true })
136
+ .click();
137
+ await signInAtKeycloak(firstStaffPage, staffEmail, organization.id);
138
+ await expect(firstStaffPage).toHaveURL(new RegExp(`/organizations/${organization.id}(?:/|$)`));
139
+ await firstStaffPage.goto(`/en/organizations/${organization.id}/members`);
140
+ const firstStaffRow = firstStaffPage.getByRole('row', { name: /Studio Staff/ });
141
+ await expect(firstStaffRow).toContainText('AppTranslator');
142
+ await expect(firstStaffRow).toContainText('AppContentsManager');
143
+ await requestKc(`/admin/realms/${KEYCLOAK_REALM}/users/${staff}/groups/${contentManagers}`, {
144
+ expectedStatuses: [204],
145
+ method: 'DELETE',
146
+ token: await getAdminToken(),
147
+ });
148
+ const returningPage = await returningContext.newPage();
149
+ await returningPage.goto(`/en/login?organization=${organization.id}`);
150
+ await returningPage
151
+ .getByRole('button', { name: 'Login with Staff Keycloak', exact: true })
152
+ .click();
153
+ await signInAtKeycloak(returningPage, staffEmail, organization.id);
154
+ await expect(returningPage).toHaveURL(new RegExp(`/organizations/${organization.id}(?:/|$)`));
155
+ await returningPage.goto(`/en/organizations/${organization.id}/members`);
156
+ const returningStaffRow = returningPage.getByRole('row', { name: /Studio Staff/ });
157
+ await expect(returningStaffRow).toContainText('AppTranslator');
158
+ await expect(returningStaffRow).not.toContainText('AppContentsManager');
159
+ await firstStaffPage.reload();
160
+ await expect(firstStaffRow).not.toContainText('AppContentsManager');
161
+ const personalPage = await personalContext.newPage();
162
+ const personalToken = await signInWithPassword(personalPage, unlinkEmail);
163
+ const before = await request.get('/api/users/current', {
164
+ headers: { authorization: `Bearer ${personalToken}` },
165
+ });
166
+ expect(before.status()).toBe(200);
167
+ const account = (await before.json());
168
+ await personalPage.goto(`/en/login?organization=${organization.id}`);
169
+ await personalPage
170
+ .getByRole('button', { name: 'Link organization single sign-on', exact: true })
171
+ .click();
172
+ const linkedToken = await signInAtKeycloak(personalPage, unlinkEmail, organization.id);
173
+ await expect(personalPage).toHaveURL(new RegExp(`/organizations/${organization.id}(?:/|$)`));
174
+ const linkedIdentity = await request.get('/api/users/current/auth/oidc/identities', {
175
+ headers: { authorization: `Bearer ${linkedToken}` },
176
+ });
177
+ expect(await linkedIdentity.json()).toEqual([
178
+ expect.objectContaining({
179
+ issuer: `${KEYCLOAK_BASE_URL}/realms/${KEYCLOAK_REALM}`,
180
+ subject: unlinkUser,
181
+ }),
182
+ ]);
183
+ await personalPage.goto('/en/settings/user');
184
+ await personalPage.getByRole('link', { name: 'Social login', exact: true }).click();
185
+ await expect(personalPage.getByRole('heading', { name: 'Organization single sign-on', exact: true })).toBeVisible();
186
+ const unlinkButton = personalPage.getByRole('button', {
187
+ name: 'Unlink single sign-on',
188
+ exact: true,
189
+ });
190
+ await expect(unlinkButton).toBeVisible();
191
+ await unlinkButton.click();
192
+ await personalPage
193
+ .getByRole('dialog')
194
+ .getByRole('button', { name: 'Unlink single sign-on', exact: true })
195
+ .click();
196
+ await expect(personalPage).toHaveURL(/\/login(?:\?|$)/);
197
+ expect((await request.get('/api/users/current', {
198
+ headers: { authorization: `Bearer ${linkedToken}` },
199
+ })).status()).toBe(401);
200
+ const recoveredToken = await signInWithPassword(personalPage, unlinkEmail);
201
+ const remaining = await request.get('/api/users/current/auth/oidc/identities', {
202
+ headers: { authorization: `Bearer ${recoveredToken}` },
203
+ });
204
+ expect(await remaining.json()).toStrictEqual([]);
205
+ expect((await request.get(`/api/organizations/${organization.id}/members`, {
206
+ headers: { authorization: `Bearer ${recoveredToken}` },
207
+ })).status()).toBe(403);
208
+ await personalPage.goto(`/en/login?organization=${organization.id}`);
209
+ await personalPage
210
+ .getByRole('button', { name: 'Link organization single sign-on', exact: true })
211
+ .click();
212
+ const relinkedToken = await submitKeycloakPassword(personalPage, organization.id);
213
+ const after = await request.get('/api/users/current', {
214
+ headers: { authorization: `Bearer ${relinkedToken}` },
215
+ });
216
+ expect((await after.json()).sub).toBe(account.sub);
217
+ const relinkedIdentity = await request.get('/api/users/current/auth/oidc/identities', {
218
+ headers: { authorization: `Bearer ${relinkedToken}` },
219
+ });
220
+ expect(await relinkedIdentity.json()).toEqual([
221
+ expect.objectContaining({
222
+ issuer: `${KEYCLOAK_BASE_URL}/realms/${KEYCLOAK_REALM}`,
223
+ subject: unlinkUser,
224
+ }),
225
+ ]);
226
+ }
227
+ finally {
228
+ await Promise.allSettled([
229
+ firstContext.close(),
230
+ returningContext.close(),
231
+ personalContext.close(),
232
+ ]);
233
+ }
234
+ }
235
+ finally {
236
+ try {
237
+ const cleanup = await request.delete(`/api/organizations/${organization.id}`, {
238
+ ...(ownerAccessToken ? { headers: { authorization: `Bearer ${ownerAccessToken}` } } : {}),
239
+ });
240
+ expect(cleanup.status()).toBe(200);
241
+ await deleteStudioUser(unlinkEmail);
242
+ await requestKc(`/admin/realms/${KEYCLOAK_REALM}`, {
243
+ expectedStatuses: [204],
244
+ method: 'DELETE',
245
+ token: await getAdminToken(),
246
+ });
247
+ }
248
+ catch (cleanupError) {
249
+ cleanupFailure = cleanupError;
250
+ await testInfo.attach('cleanup-error', {
251
+ body: String(cleanupError),
252
+ contentType: 'text/plain',
253
+ });
254
+ }
255
+ }
256
+ if (cleanupFailure) {
257
+ throw cleanupFailure;
258
+ }
259
+ });
260
+ });
261
+ //# sourceMappingURL=keycloak-studio-oidc.spec.js.map
@@ -70,20 +70,18 @@ export declare function joinGroup(token: string, realm: string, userId: string,
70
70
  */
71
71
  export declare function getSigningCertificate(token: string, realm: string): Promise<string>;
72
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.
73
+ * Create a confidential OIDC client with group claims for app, Studio, or broker sign-in.
77
74
  *
78
75
  * @param token A Keycloak admin bearer token.
79
- * @param realm The upstream realm name.
76
+ * @param realm The realm name.
80
77
  * @param client The client to create: `clientId`, `clientSecret`, and the allowed `redirectUris`
81
- * (typically the broker endpoint).
78
+ * and whether PKCE S256 is required.
82
79
  */
83
- export declare function createUpstreamOidcClient(token: string, realm: string, { clientId, clientSecret, redirectUris, }: {
80
+ export declare function createUpstreamOidcClient(token: string, realm: string, { clientId, clientSecret, redirectUris, requirePkce, }: {
84
81
  clientId: string;
85
82
  clientSecret: string;
86
83
  redirectUris: string[];
84
+ requirePkce?: boolean;
87
85
  }): Promise<void>;
88
86
  /**
89
87
  * Create an OIDC identity provider that federates a broker realm to an upstream realm.
@@ -164,21 +164,19 @@ export async function getSigningCertificate(token, realm) {
164
164
  return wrapCertificate(certificate);
165
165
  }
166
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.
167
+ * Create a confidential OIDC client with group claims for app, Studio, or broker sign-in.
171
168
  *
172
169
  * @param token A Keycloak admin bearer token.
173
- * @param realm The upstream realm name.
170
+ * @param realm The realm name.
174
171
  * @param client The client to create: `clientId`, `clientSecret`, and the allowed `redirectUris`
175
- * (typically the broker endpoint).
172
+ * and whether PKCE S256 is required.
176
173
  */
177
- export async function createUpstreamOidcClient(token, realm, { clientId, clientSecret, redirectUris, }) {
174
+ export async function createUpstreamOidcClient(token, realm, { clientId, clientSecret, redirectUris, requirePkce, }) {
178
175
  await requestKc(`/admin/realms/${realm}/clients`, {
179
176
  body: JSON.stringify({
180
177
  clientAuthenticatorType: 'client-secret',
181
178
  clientId,
179
+ ...(requirePkce ? { attributes: { 'pkce.code.challenge.method': 'S256' } } : {}),
182
180
  directAccessGrantsEnabled: true,
183
181
  enabled: true,
184
182
  protocol: 'openid-connect',