Skip to content

Commit 0b72bca

Browse files
authored
Merge pull request #20145 from mozilla/fxa-12624-v3
feat(fxa-auth-server): Migrate subscription & token integration tests PART 4
2 parents cf91efa + aaa978c commit 0b72bca

7 files changed

Lines changed: 955 additions & 27 deletions

File tree

packages/functional-tests/lib/pairing-helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ export async function enableTotpOnAccount(
497497

498498
/**
499499
* Enter a TOTP code on the /pair/auth/totp page via Marionette.
500+
* Waits for the page to navigate away from the TOTP page after submission.
500501
*/
501502
export async function enterTotpCodeViaMarionette(
502503
client: MarionetteClient,
@@ -505,11 +506,13 @@ export async function enterTotpCodeViaMarionette(
505506
const totpInput = await findElementBySelectors(client, SELECTORS.TOTP_INPUT);
506507
const code = await getTotpCode(secret);
507508
await client.sendKeys(totpInput, code);
509+
const preSubmitUrl = await client.getUrl();
508510
const submitBtn = await findElementBySelectors(
509511
client,
510512
SELECTORS.SUBMIT_BUTTON
511513
);
512514
await client.clickElement(submitBtn);
515+
await waitForUrlChange(client, preSubmitUrl);
513516
}
514517

515518
export function sleep(ms: number): Promise<void> {

packages/functional-tests/tests/pairing/pairingFlow.spec.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,9 @@ test.describe('severity-2 #smoke', () => {
125125
});
126126
await confirmButton.first().click();
127127

128-
await expect(async () => {
129-
const url = page.url();
130-
expect(url).not.toContain('pair/supp/allow');
131-
}).toPass({ timeout: TIMEOUTS.AUTHORITY_COMPLETE });
132-
133-
const finalSuppUrl = page.url();
134-
expect(finalSuppUrl).not.toContain('pair/failure');
135-
expect(finalSuppUrl).toContain('oauth/success');
128+
await page.waitForURL(/oauth\/success/, {
129+
timeout: TIMEOUTS.AUTHORITY_COMPLETE,
130+
});
136131

137132
// Wait for authority to advance from wait_for_supp to complete
138133
await client.setContext('content');
@@ -208,10 +203,9 @@ test.describe('severity-2 #smoke', () => {
208203
});
209204
await confirmButton.first().click();
210205

211-
await expect(async () => {
212-
expect(page.url()).not.toContain('pair/supp/allow');
213-
}).toPass({ timeout: TIMEOUTS.AUTHORITY_COMPLETE });
214-
expect(page.url()).toContain('oauth/success');
206+
await page.waitForURL(/oauth\/success/, {
207+
timeout: TIMEOUTS.AUTHORITY_COMPLETE,
208+
});
215209

216210
await client.setContext('content');
217211
const finalAuthUrl = await waitForUrlContaining(

packages/fxa-auth-server/test/remote/misc_tests.in.spec.ts

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import http from 'http';
6-
import { createTestServer, TestServerInstance } from '../support/helpers/test-server';
6+
import {
7+
createTestServer,
8+
TestServerInstance,
9+
} from '../support/helpers/test-server';
710

811
const Client = require('../client')();
912
const packageJson = require('../../package.json');
1013

1114
let server: TestServerInstance;
1215

1316
beforeAll(async () => {
14-
server = await createTestServer();
17+
server = await createTestServer({
18+
configOverrides: {
19+
corsOrigin: ['http://foo', 'http://bar'],
20+
},
21+
});
1522
}, 120000);
1623

1724
afterAll(async () => {
@@ -29,7 +36,12 @@ const testVersions = [
2936
function httpGet(
3037
url: string,
3138
options?: { headers?: Record<string, string> }
32-
): Promise<{ statusCode: number; headers: http.IncomingHttpHeaders; body: string; json: () => any }> {
39+
): Promise<{
40+
statusCode: number;
41+
headers: http.IncomingHttpHeaders;
42+
body: string;
43+
json: () => any;
44+
}> {
3345
return new Promise((resolve, reject) => {
3446
const parsed = new URL(url);
3547
const req = http.get(
@@ -41,7 +53,9 @@ function httpGet(
4153
},
4254
(res) => {
4355
let data = '';
44-
res.on('data', (chunk) => { data += chunk; });
56+
res.on('data', (chunk) => {
57+
data += chunk;
58+
});
4559
res.on('end', () => {
4660
resolve({
4761
statusCode: res.statusCode ?? 0,
@@ -60,7 +74,11 @@ function httpPost(
6074
url: string,
6175
payload: any,
6276
headers?: Record<string, string>
63-
): Promise<{ statusCode: number; headers: http.IncomingHttpHeaders; body: string }> {
77+
): Promise<{
78+
statusCode: number;
79+
headers: http.IncomingHttpHeaders;
80+
body: string;
81+
}> {
6482
return new Promise((resolve, reject) => {
6583
const parsed = new URL(url);
6684
const body = JSON.stringify(payload);
@@ -78,7 +96,9 @@ function httpPost(
7896
},
7997
(res) => {
8098
let data = '';
81-
res.on('data', (chunk) => { data += chunk; });
99+
res.on('data', (chunk) => {
100+
data += chunk;
101+
});
82102
res.on('end', () => {
83103
resolve({
84104
statusCode: res.statusCode ?? 0,
@@ -144,7 +164,9 @@ describe.each(testVersions)(
144164
const res = await httpGet(`${server.publicUrl}/`, {
145165
headers: { Origin: randomAllowedOrigin },
146166
});
147-
expect(res.headers['access-control-allow-origin']).toBe(randomAllowedOrigin);
167+
expect(res.headers['access-control-allow-origin']).toBe(
168+
randomAllowedOrigin
169+
);
148170
});
149171

150172
it('returns no Access-Control-Allow-Origin with not whitelisted Origin', async () => {
@@ -171,7 +193,11 @@ describe.each(testVersions)(
171193
const email = server.uniqueEmail();
172194
const password = 'allyourbasearebelongtous';
173195
const client = await Client.createAndVerify(
174-
server.publicUrl, email, password, server.mailbox, testOptions
196+
server.publicUrl,
197+
email,
198+
password,
199+
server.mailbox,
200+
testOptions
175201
);
176202

177203
await client.login();
@@ -181,7 +207,7 @@ describe.each(testVersions)(
181207
);
182208

183209
const res = await httpGet(url, {
184-
headers: { 'Authorization': `Hawk id="${token.id}"` },
210+
headers: { Authorization: `Hawk id="${token.id}"` },
185211
});
186212
const now = +new Date() / 1000;
187213
expect(Number(res.headers.timestamp)).toBeGreaterThan(now - 60);
@@ -226,22 +252,34 @@ describe.each(testVersions)(
226252
'GET',
227253
server.publicUrl + '/.well-known/browserid'
228254
);
229-
expect(Object.prototype.hasOwnProperty.call(doc, 'public-key')).toBe(true);
255+
expect(Object.prototype.hasOwnProperty.call(doc, 'public-key')).toBe(
256+
true
257+
);
230258
expect(/^[0-9]+$/.test(doc['public-key'].n)).toBe(true);
231259
expect(/^[0-9]+$/.test(doc['public-key'].e)).toBe(true);
232-
expect(Object.prototype.hasOwnProperty.call(doc, 'authentication')).toBe(true);
233-
expect(Object.prototype.hasOwnProperty.call(doc, 'provisioning')).toBe(true);
260+
expect(Object.prototype.hasOwnProperty.call(doc, 'authentication')).toBe(
261+
true
262+
);
263+
expect(Object.prototype.hasOwnProperty.call(doc, 'provisioning')).toBe(
264+
true
265+
);
234266
expect(doc.keys.length).toBe(1);
235267
});
236268

237269
it('ignores fail on hawk payload mismatch', async () => {
238270
const email = server.uniqueEmail();
239271
const password = 'allyourbasearebelongtous';
240272
const client = await Client.createAndVerify(
241-
server.publicUrl, email, password, server.mailbox, testOptions
273+
server.publicUrl,
274+
email,
275+
password,
276+
server.mailbox,
277+
testOptions
242278
);
243279

244-
const token = await client.api.Token.SessionToken.fromHex(client.sessionToken);
280+
const token = await client.api.Token.SessionToken.fromHex(
281+
client.sessionToken
282+
);
245283
const url = `${client.api.baseURL}/account/device`;
246284
const payload: any = {
247285
name: 'my cool device',
@@ -250,7 +288,7 @@ describe.each(testVersions)(
250288

251289
payload.name = 'my stealthily-changed device name';
252290
const res = await httpPost(url, payload, {
253-
'Authorization': `Hawk id="${token.id}"`,
291+
Authorization: `Hawk id="${token.id}"`,
254292
});
255293
expect(res.statusCode).toBe(200);
256294
});

0 commit comments

Comments
 (0)