Skip to content

Commit fb2f215

Browse files
authored
test: Refactor fixture to allow for multiple identities (#3644)
This PR refactors the identity fixture to allow for multiple identities, following the same design approach as seen in the recent OpenID fixture. # Changes - Refactor identity fixture to match OpenID fixture design approach. - Add manage page fixture to handle sign out across manage pages (moving this out of identity fixture). # Tests The e2e tests that used the identity fixture have been updated to match it's new syntax.
1 parent 11f62ba commit fb2f215

File tree

6 files changed

+312
-142
lines changed

6 files changed

+312
-142
lines changed

src/frontend/tests/e2e-playwright/authorize/openid.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,15 @@ test.describe("Authorize with direct OpenID", () => {
109109
// Link both OpenID provider users with identity first to ensure attributes from
110110
// both providers are available, but only one is returned through implicit consent.
111111
test.beforeEach(
112-
async ({ page, identity, signInWithOpenId, openIdUsers }) => {
112+
async ({
113+
page,
114+
identities,
115+
signInWithIdentity,
116+
signInWithOpenId,
117+
openIdUsers,
118+
}) => {
113119
await page.goto(II_URL + "/manage/access");
114-
await identity.signIn();
120+
await signInWithIdentity(page, identities[0].identityNumber);
115121

116122
for (const user of openIdUsers) {
117123
// Click "Add new" and pick OpenID provider

src/frontend/tests/e2e-playwright/dashboard/recovery.spec.ts

Lines changed: 120 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,36 @@ const test = base.extend<{
3737
});
3838

3939
test.describe("Recovery phrase", () => {
40-
test.beforeEach(async ({ manageRecoveryPage, identity }) => {
41-
await manageRecoveryPage.goto();
42-
await identity.signIn();
43-
await manageRecoveryPage.assertNotActivated();
44-
});
40+
test.beforeEach(
41+
async ({ page, manageRecoveryPage, identities, signInWithIdentity }) => {
42+
await manageRecoveryPage.goto();
43+
await signInWithIdentity(page, identities[0].identityNumber);
44+
await manageRecoveryPage.assertNotActivated();
45+
},
46+
);
4547

4648
test.describe("can be activated", () => {
4749
test.afterEach(
48-
async ({ page, manageRecoveryPage, identity, words, recoveryPage }) => {
50+
async ({
51+
page,
52+
managePage,
53+
manageRecoveryPage,
54+
identities,
55+
signInWithIdentity,
56+
words,
57+
recoveryPage,
58+
}) => {
4959
await manageRecoveryPage.assertActivated();
5060
// Assert it's still activated after signing back in
51-
await identity.signOut();
61+
await managePage.signOut();
5262
await manageRecoveryPage.goto();
53-
await identity.signIn();
63+
await signInWithIdentity(page, identities[0].identityNumber);
5464
await manageRecoveryPage.assertActivated();
5565
// Verify we can recover using `words.current`
5666
await recoveryPage.goto();
5767
await recoveryPage.start(async (wizard) => {
5868
await wizard.enterRecoveryPhrase(words.current!);
59-
await wizard.confirmFoundIdentity(identity.name);
69+
await wizard.confirmFoundIdentity(identities[0].name);
6070
});
6171
await page.waitForURL(II_URL + "/manage/access");
6272
await expect(
@@ -98,18 +108,26 @@ test.describe("Recovery phrase", () => {
98108
});
99109

100110
test.afterEach(
101-
async ({ page, manageRecoveryPage, identity, recoveryPage, words }) => {
111+
async ({
112+
page,
113+
managePage,
114+
manageRecoveryPage,
115+
identities,
116+
signInWithIdentity,
117+
recoveryPage,
118+
words,
119+
}) => {
102120
await manageRecoveryPage.assertActivated();
103121
// Assert it's still activated after signing back in
104-
await identity.signOut();
122+
await managePage.signOut();
105123
await manageRecoveryPage.goto();
106-
await identity.signIn();
124+
await signInWithIdentity(page, identities[0].identityNumber);
107125
await manageRecoveryPage.assertActivated();
108126
// Verify we can still recover using `words.current`
109127
await recoveryPage.goto();
110128
await recoveryPage.start(async (wizard) => {
111129
await wizard.enterRecoveryPhrase(words.current!);
112-
await wizard.confirmFoundIdentity(identity.name);
130+
await wizard.confirmFoundIdentity(identities[0].name);
113131
});
114132
await page.waitForURL(II_URL + "/manage/access");
115133
await expect(
@@ -137,11 +155,19 @@ test.describe("Recovery phrase", () => {
137155
});
138156

139157
test.describe("when coming back after sign out", () => {
140-
test.beforeEach(async ({ manageRecoveryPage, identity }) => {
141-
await identity.signOut();
142-
await manageRecoveryPage.goto();
143-
await identity.signIn();
144-
});
158+
test.beforeEach(
159+
async ({
160+
page,
161+
managePage,
162+
manageRecoveryPage,
163+
identities,
164+
signInWithIdentity,
165+
}) => {
166+
await managePage.signOut();
167+
await manageRecoveryPage.goto();
168+
await signInWithIdentity(page, identities[0].identityNumber);
169+
},
170+
);
145171

146172
test("on first attempt", async ({ manageRecoveryPage, words }) => {
147173
await manageRecoveryPage.verify(async (wizard) => {
@@ -159,17 +185,20 @@ test.describe("Recovery phrase", () => {
159185
});
160186

161187
test("when signed in (incorrectly) and then when coming back (correctly)", async ({
188+
page,
189+
managePage,
162190
manageRecoveryPage,
163-
identity,
191+
identities,
192+
signInWithIdentity,
164193
words,
165194
}) => {
166195
await manageRecoveryPage.verify(async (wizard) => {
167196
await wizard.verifySelecting(swapWordsAround(words.current!));
168197
await wizard.close();
169198
});
170-
await identity.signOut();
199+
await managePage.signOut();
171200
await manageRecoveryPage.goto();
172-
await identity.signIn();
201+
await signInWithIdentity(page, identities[0].identityNumber);
173202
await manageRecoveryPage.verify(async (wizard) => {
174203
await wizard.verifyTyping(words.current!);
175204
});
@@ -178,18 +207,26 @@ test.describe("Recovery phrase", () => {
178207

179208
test.describe("can be reset", () => {
180209
test.afterEach(
181-
async ({ page, manageRecoveryPage, identity, recoveryPage, words }) => {
210+
async ({
211+
page,
212+
managePage,
213+
manageRecoveryPage,
214+
identities,
215+
signInWithIdentity,
216+
recoveryPage,
217+
words,
218+
}) => {
182219
await manageRecoveryPage.assertActivated();
183220
// Assert it's still activated after signing back in
184-
await identity.signOut();
221+
await managePage.signOut();
185222
await manageRecoveryPage.goto();
186-
await identity.signIn();
223+
await signInWithIdentity(page, identities[0].identityNumber);
187224
await manageRecoveryPage.assertActivated();
188225
// Verify we can recover using the new recovery phrase (`words.current`)
189226
await recoveryPage.goto();
190227
await recoveryPage.start(async (wizard) => {
191228
await wizard.enterRecoveryPhrase(words.current!);
192-
await wizard.confirmFoundIdentity(identity.name);
229+
await wizard.confirmFoundIdentity(identities[0].name);
193230
});
194231
await page.waitForURL(II_URL + "/manage/access");
195232
await expect(
@@ -262,37 +299,47 @@ test.describe("Recovery phrase", () => {
262299
}
263300

264301
test.describe("when it is locked (legacy)", () => {
265-
test.beforeEach(async ({ identity, manageRecoveryPage, words }) => {
266-
// Use an actor to create a locked recovery phrase
267-
// since this functionality is no longer available.
268-
const { actor, identityNumber } = await identity.createActor();
269-
words.current = generateMnemonic();
270-
const recoveryIdentity = await fromMnemonicWithoutValidation(
271-
words.current.join(" "),
272-
IC_DERIVATION_PATH,
273-
);
274-
await actor.authn_method_add(identityNumber, {
275-
metadata: [
276-
["alias", { String: "Recovery phrase" }],
277-
["usage", { String: "recovery_phrase" }],
278-
],
279-
authn_method: {
280-
PubKey: {
281-
pubkey: new Uint8Array(recoveryIdentity.getPublicKey().derKey),
302+
test.beforeEach(
303+
async ({
304+
page,
305+
identities,
306+
signInWithIdentity,
307+
actorForIdentity,
308+
managePage,
309+
manageRecoveryPage,
310+
words,
311+
}) => {
312+
// Use an actor to create a locked recovery phrase
313+
// since this functionality is no longer available.
314+
const actor = await actorForIdentity(identities[0].identityNumber);
315+
words.current = generateMnemonic();
316+
const recoveryIdentity = await fromMnemonicWithoutValidation(
317+
words.current.join(" "),
318+
IC_DERIVATION_PATH,
319+
);
320+
await actor.authn_method_add(identities[0].identityNumber, {
321+
metadata: [
322+
["alias", { String: "Recovery phrase" }],
323+
["usage", { String: "recovery_phrase" }],
324+
],
325+
authn_method: {
326+
PubKey: {
327+
pubkey: new Uint8Array(recoveryIdentity.getPublicKey().derKey),
328+
},
282329
},
283-
},
284-
security_settings: {
285-
protection: { Protected: null },
286-
purpose: { Recovery: null },
287-
},
288-
last_authentication: [],
289-
});
290-
// Revisit the page to see the changes
291-
await identity.signOut();
292-
await manageRecoveryPage.goto();
293-
await identity.signIn();
294-
await manageRecoveryPage.assertLocked();
295-
});
330+
security_settings: {
331+
protection: { Protected: null },
332+
purpose: { Recovery: null },
333+
},
334+
last_authentication: [],
335+
});
336+
// Revisit the page to see the changes
337+
await managePage.signOut();
338+
await manageRecoveryPage.goto();
339+
await signInWithIdentity(page, identities[0].identityNumber);
340+
await manageRecoveryPage.assertLocked();
341+
},
342+
);
296343

297344
test("on first attempt", async ({ manageRecoveryPage, words }) => {
298345
words.current = await manageRecoveryPage.unlockAndReset(
@@ -334,9 +381,9 @@ test.describe("Recovery phrase", () => {
334381

335382
test("when resetting", async ({
336383
page,
384+
identities,
337385
manageRecoveryPage,
338386
recoveryPage,
339-
identity,
340387
}) => {
341388
const oldWords = await manageRecoveryPage.activate(async (wizard) => {
342389
await wizard.acknowledge();
@@ -353,7 +400,7 @@ test.describe("Recovery phrase", () => {
353400
await recoveryPage.goto();
354401
await recoveryPage.start(async (wizard) => {
355402
await wizard.enterRecoveryPhrase(oldWords);
356-
await wizard.confirmFoundIdentity(identity.name);
403+
await wizard.confirmFoundIdentity(identities[0].name);
357404
});
358405
await page.waitForURL(II_URL + "/manage/access");
359406
await expect(
@@ -363,14 +410,22 @@ test.describe("Recovery phrase", () => {
363410
});
364411

365412
test.describe("is not verified", () => {
366-
test.afterEach(async ({ manageRecoveryPage, identity }) => {
367-
await manageRecoveryPage.assertNotVerified();
368-
// Assert it's still not verified after signing back in
369-
await identity.signOut();
370-
await manageRecoveryPage.goto();
371-
await identity.signIn();
372-
await manageRecoveryPage.assertNotVerified();
373-
});
413+
test.afterEach(
414+
async ({
415+
page,
416+
identities,
417+
signInWithIdentity,
418+
managePage,
419+
manageRecoveryPage,
420+
}) => {
421+
await manageRecoveryPage.assertNotVerified();
422+
// Assert it's still not verified after signing back in
423+
await managePage.signOut();
424+
await manageRecoveryPage.goto();
425+
await signInWithIdentity(page, identities[0].identityNumber);
426+
await manageRecoveryPage.assertNotVerified();
427+
},
428+
);
374429

375430
test.describe("when closed during activation", () => {
376431
test("before written down", async ({ manageRecoveryPage }) => {

0 commit comments

Comments
 (0)