Skip to content

Commit 847364e

Browse files
authored
Merge pull request #20222 from mozilla/fix-ai-slop
polish(auth): Fix ai-slop
2 parents 0244c3e + 4aa7ccd commit 847364e

4 files changed

Lines changed: 104 additions & 117 deletions

File tree

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export {};
21
/* This Source Code Form is subject to the terms of the Mozilla Public
32
* License, v. 2.0. If a copy of the MPL was not distributed with this
43
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -237,7 +236,10 @@ describe('#integration - /v1', function () {
237236
expect(redirect.query.scope).toBe('1');
238237
// unknown query params are forwarded
239238
expect(redirect.query.a).toBe('b');
240-
const target = url.parse(config.get('oauthServer.contentUrl'), true);
239+
const target = url.parse(
240+
config.get('oauthServer.contentUrl'),
241+
true
242+
);
241243
expect(redirect.pathname).toBe('/authorization');
242244
expect(redirect.host).toBe(target.host);
243245
});
@@ -594,9 +596,7 @@ describe('#integration - /v1', function () {
594596
expect(res.statusCode).toBe(200);
595597
assertSecurityHeaders(res);
596598
expect(res.result.state).toBe('aa');
597-
expect(
598-
url.parse(res.result.redirect, true).query.state
599-
).toBe('aa');
599+
expect(url.parse(res.result.redirect, true).query.state).toBe('aa');
600600
});
601601
});
602602
});
@@ -835,7 +835,9 @@ describe('#integration - /v1', function () {
835835
expect(res.result.token_type).toBe('bearer');
836836
expect(res.result.scope).toBeTruthy();
837837
expect(res.result.expires_in <= defaultExpiresIn).toBeTruthy();
838-
expect(res.result.expires_in > defaultExpiresIn - 10).toBeTruthy();
838+
expect(
839+
res.result.expires_in > defaultExpiresIn - 10
840+
).toBeTruthy();
839841
expect(res.result.auth_at).toBeTruthy();
840842
});
841843
});
@@ -1369,7 +1371,8 @@ describe('#integration - /v1', function () {
13691371

13701372
describe('when used by a public client (PKCE)', function () {
13711373
const code_verifier = 'WFX-9dPwcpPIXt8c5Pbx09_Z61zPm1Fjwv89lVrukOh';
1372-
const code_verifier_bad = 'QnuuNM5gfnJmWwIjiOKk2SKn8A89tph3-8BjNUUtooJ';
1374+
const code_verifier_bad =
1375+
'QnuuNM5gfnJmWwIjiOKk2SKn8A89tph3-8BjNUUtooJ';
13731376
const code_challenge = 'xWVKKAQVD9XSXT4Z4Oh8dLJ5pqrr0gQes2QwZOVJyAk';
13741377
const secret2 = unique.secret();
13751378
const client2 = {
@@ -2062,7 +2065,9 @@ describe('#integration - /v1', function () {
20622065

20632066
expect(res.statusCode).toBe(200);
20642067
assertSecurityHeaders(res);
2065-
expect(res.result.scope).toBe('email https://identity.mozilla.com/apps/notes');
2068+
expect(res.result.scope).toBe(
2069+
'email https://identity.mozilla.com/apps/notes'
2070+
);
20662071
});
20672072
});
20682073
});
@@ -2294,7 +2299,9 @@ describe('#integration - /v1', function () {
22942299
expect(res.statusCode).toBe(200);
22952300
expect(res.result.access_token).toBeTruthy();
22962301
// Should contain all requested scopes (including invalid ones)
2297-
expect(res.result.scope).toBe('profile email invalid:scope another:invalid');
2302+
expect(res.result.scope).toBe(
2303+
'profile email invalid:scope another:invalid'
2304+
);
22982305
});
22992306
});
23002307
});
@@ -3148,9 +3155,7 @@ describe('#integration - /v1', function () {
31483155

31493156
// Skipped: requires config/oldKey.json which is not generated by default
31503157
it.skip('should include the oldKey if present', function () {
3151-
expect(
3152-
config.get('oauthServer.openid.oldKey')
3153-
).toBeTruthy();
3158+
expect(config.get('oauthServer.openid.oldKey')).toBeTruthy();
31543159
return Server.api
31553160
.get({
31563161
url: '/jwks',
@@ -3322,11 +3327,7 @@ describe('#integration - /v1', function () {
33223327
const clients = res.result;
33233328
expect(clients.length).toBe(3);
33243329
expect(clients[0].client_id).toBe(client2Id.toString('hex'));
3325-
expect(clients[0].scope).toEqual([
3326-
'aaaSortMeFirst',
3327-
'other',
3328-
'scope',
3329-
]);
3330+
expect(clients[0].scope).toEqual(['aaaSortMeFirst', 'other', 'scope']);
33303331
expect(clients[0].refresh_token_id).toBeTruthy();
33313332
expect(clients[1].client_id).toBe(client2Id.toString('hex'));
33323333
expect(clients[1].scope).toEqual(['profile']);

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
/* This Source Code Form is subject to the terms of the Mozilla Public
42
* License, v. 2.0. If a copy of the MPL was not distributed with this
53
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -49,10 +47,7 @@ describe('db', () => {
4947
};
5048
}
5149

52-
it(
53-
'2-byte encoding preserved',
54-
makeTest(randomString(8), 'Düsseldorf')
55-
);
50+
it('2-byte encoding preserved', makeTest(randomString(8), 'Düsseldorf'));
5651
it('3-byte encoding preserved', makeTest(randomString(8), '北京'));
5752
it('4-byte encoding throws with mysql', async () => {
5853
const data = {
@@ -314,8 +309,7 @@ describe('db', () => {
314309

315310
describe('scopes', () => {
316311
it('can register and fetch scopes', async () => {
317-
const scopeName =
318-
'https://some-scope.mozilla.org/apps/' + Math.random();
312+
const scopeName = 'https://some-scope.mozilla.org/apps/' + Math.random();
319313
const notFoundScope = 'https://some-scope-404.mozilla.org';
320314
const newScope = {
321315
scope: scopeName,
@@ -523,9 +517,7 @@ describe('db', () => {
523517

524518
expect(await db.getRefreshToken(refreshTokenIdHash)).toBeFalsy();
525519

526-
const tokenIdHash = hex(
527-
encrypt.hash(accessToken.token.toString('hex'))
528-
);
520+
const tokenIdHash = hex(encrypt.hash(accessToken.token.toString('hex')));
529521
expect(await db.getAccessToken(tokenIdHash)).toBeFalsy();
530522
});
531523
});
@@ -574,9 +566,7 @@ describe('db', () => {
574566
}
575567
const token = await db.getUniqueRefreshTokensByUid(hex(userId));
576568
expect(token.length).toBe(1);
577-
expect(token[0].lastUsedAt.getTime()).toBe(
578-
lastUsedAtValues[2].getTime()
579-
);
569+
expect(token[0].lastUsedAt.getTime()).toBe(lastUsedAtValues[2].getTime());
580570
});
581571
});
582572
});
Lines changed: 69 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
/* This Source Code Form is subject to the terms of the Mozilla Public
42
* License, v. 2.0. If a copy of the MPL was not distributed with this
53
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -46,81 +44,73 @@ describe('the signing-key management scripts', () => {
4644
rimraf.sync(workDir);
4745
});
4846

49-
it(
50-
'work as intended',
51-
() => {
52-
// Initially, the directory is empty.
53-
expect(fs.readdirSync(workDir)).toEqual([]);
54-
55-
// We can't run any of the other management scripts until we generate initial set of keys.
56-
expect(() => runScript('prepare-new-signing-key.js')).toThrow(
57-
/oauthServer\.openid\.key is missing/
58-
);
59-
expect(() => runScript('activate-new-signing-key.js')).toThrow(
60-
/oauthServer\.openid\.key is missing/
61-
);
62-
expect(() => runScript('retire-old-signing-key.js')).toThrow(
63-
/oauthServer\.openid\.key is missing/
64-
);
65-
66-
// Need to initialize some keys
67-
runScript('oauth_gen_keys.js');
68-
expect(fs.readdirSync(workDir).length).toBe(2);
69-
expect(fs.existsSync(keyFile)).toBe(true);
70-
expect(fs.existsSync(newKeyFile)).toBe(false);
71-
expect(fs.existsSync(oldKeyFile)).toBe(true);
72-
73-
const kid = JSON.parse(fs.readFileSync(keyFile, 'utf-8')).kid;
74-
expect(kid).toBeTruthy();
75-
76-
// That generated a fake old key, which we can retire.
77-
runScript('retire-old-signing-key.js');
78-
expect(fs.readdirSync(workDir).length).toBe(1);
79-
expect(fs.existsSync(keyFile)).toBe(true);
80-
expect(fs.existsSync(newKeyFile)).toBe(false);
81-
expect(fs.existsSync(oldKeyFile)).toBe(false);
82-
83-
// But it didn't generate a new key, so we can't activate it.
84-
expect(() => runScript('activate-new-signing-key.js')).toThrow(
85-
/missing new signing key/
86-
);
87-
88-
// Generate new signing key.
89-
runScript('prepare-new-signing-key.js');
90-
expect(fs.readdirSync(workDir).length).toBe(2);
91-
expect(fs.existsSync(keyFile)).toBe(true);
92-
expect(fs.existsSync(newKeyFile)).toBe(true);
93-
expect(fs.existsSync(oldKeyFile)).toBe(false);
94-
95-
const newKid = JSON.parse(fs.readFileSync(newKeyFile, 'utf-8')).kid;
96-
expect(newKid).toBeTruthy();
97-
expect(newKid).not.toBe(kid);
98-
99-
// Now we can activate it.
100-
runScript('activate-new-signing-key.js');
101-
expect(fs.readdirSync(workDir).length).toBe(2);
102-
expect(fs.existsSync(keyFile)).toBe(true);
103-
expect(fs.existsSync(newKeyFile)).toBe(false);
104-
expect(fs.existsSync(oldKeyFile)).toBe(true);
105-
106-
const activatedKid = JSON.parse(
107-
fs.readFileSync(keyFile, 'utf-8')
108-
).kid;
109-
expect(activatedKid).toBe(newKid);
110-
111-
// Which should have moved the previous key to old-key.
112-
const retiringKid = JSON.parse(
113-
fs.readFileSync(oldKeyFile, 'utf-8')
114-
).kid;
115-
expect(retiringKid).toBe(kid);
116-
117-
// From where we can retire it completely.
118-
runScript('retire-old-signing-key.js');
119-
expect(fs.readdirSync(workDir).length).toBe(1);
120-
expect(fs.existsSync(keyFile)).toBe(true);
121-
expect(fs.existsSync(newKeyFile)).toBe(false);
122-
expect(fs.existsSync(oldKeyFile)).toBe(false);
123-
},
124-
60000
125-
);
47+
it('work as intended', () => {
48+
// Initially, the directory is empty.
49+
expect(fs.readdirSync(workDir)).toEqual([]);
50+
51+
// We can't run any of the other management scripts until we generate initial set of keys.
52+
expect(() => runScript('prepare-new-signing-key.js')).toThrow(
53+
/oauthServer\.openid\.key is missing/
54+
);
55+
expect(() => runScript('activate-new-signing-key.js')).toThrow(
56+
/oauthServer\.openid\.key is missing/
57+
);
58+
expect(() => runScript('retire-old-signing-key.js')).toThrow(
59+
/oauthServer\.openid\.key is missing/
60+
);
61+
62+
// Need to initialize some keys
63+
runScript('oauth_gen_keys.js');
64+
expect(fs.readdirSync(workDir).length).toBe(2);
65+
expect(fs.existsSync(keyFile)).toBe(true);
66+
expect(fs.existsSync(newKeyFile)).toBe(false);
67+
expect(fs.existsSync(oldKeyFile)).toBe(true);
68+
69+
const kid = JSON.parse(fs.readFileSync(keyFile, 'utf-8')).kid;
70+
expect(kid).toBeTruthy();
71+
72+
// That generated a fake old key, which we can retire.
73+
runScript('retire-old-signing-key.js');
74+
expect(fs.readdirSync(workDir).length).toBe(1);
75+
expect(fs.existsSync(keyFile)).toBe(true);
76+
expect(fs.existsSync(newKeyFile)).toBe(false);
77+
expect(fs.existsSync(oldKeyFile)).toBe(false);
78+
79+
// But it didn't generate a new key, so we can't activate it.
80+
expect(() => runScript('activate-new-signing-key.js')).toThrow(
81+
/missing new signing key/
82+
);
83+
84+
// Generate new signing key.
85+
runScript('prepare-new-signing-key.js');
86+
expect(fs.readdirSync(workDir).length).toBe(2);
87+
expect(fs.existsSync(keyFile)).toBe(true);
88+
expect(fs.existsSync(newKeyFile)).toBe(true);
89+
expect(fs.existsSync(oldKeyFile)).toBe(false);
90+
91+
const newKid = JSON.parse(fs.readFileSync(newKeyFile, 'utf-8')).kid;
92+
expect(newKid).toBeTruthy();
93+
expect(newKid).not.toBe(kid);
94+
95+
// Now we can activate it.
96+
runScript('activate-new-signing-key.js');
97+
expect(fs.readdirSync(workDir).length).toBe(2);
98+
expect(fs.existsSync(keyFile)).toBe(true);
99+
expect(fs.existsSync(newKeyFile)).toBe(false);
100+
expect(fs.existsSync(oldKeyFile)).toBe(true);
101+
102+
const activatedKid = JSON.parse(fs.readFileSync(keyFile, 'utf-8')).kid;
103+
expect(activatedKid).toBe(newKid);
104+
105+
// Which should have moved the previous key to old-key.
106+
const retiringKid = JSON.parse(fs.readFileSync(oldKeyFile, 'utf-8')).kid;
107+
expect(retiringKid).toBe(kid);
108+
109+
// From where we can retire it completely.
110+
runScript('retire-old-signing-key.js');
111+
expect(fs.readdirSync(workDir).length).toBe(1);
112+
expect(fs.existsSync(keyFile)).toBe(true);
113+
expect(fs.existsSync(newKeyFile)).toBe(false);
114+
expect(fs.existsSync(oldKeyFile)).toBe(false);
115+
}, 60000);
126116
});

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
/* This Source Code Form is subject to the terms of the Mozilla Public
42
* License, v. 2.0. If a copy of the MPL was not distributed with this
53
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -11,8 +9,7 @@ const hex = (v: any) => (Buffer.isBuffer(v) ? v.toString('hex') : v);
119

1210
const UID = 'eaf0';
1311
const CLIENT_ID = '98e6508e88680e1b';
14-
const CODE =
15-
'df6dcfe7bf6b54a65db5742cbcdce5c0a84a5da81a0bb6bdf5fc793eef041fc6';
12+
const CODE = 'df6dcfe7bf6b54a65db5742cbcdce5c0a84a5da81a0bb6bdf5fc793eef041fc6';
1613
const REFRESH_TOKEN = CODE;
1714
const DISABLED_CLIENT_ID = 'd15ab1edd15ab1ed';
1815
const NON_DISABLED_CLIENT_ID = '98e6508e88680e1a';
@@ -100,13 +97,22 @@ beforeAll(() => {
10097
// Mock the modules at their resolved paths (relative to this test file).
10198
// token.js at lib/routes/oauth/token.js requires('../../oauth/...') which
10299
// resolves to lib/oauth/..., so from test/remote/ that's ../../lib/oauth/...
103-
jest.doMock('../../lib/oauth/assertion', () => tokenRoutesDepMocks['../../oauth/assertion']);
100+
jest.doMock(
101+
'../../lib/oauth/assertion',
102+
() => tokenRoutesDepMocks['../../oauth/assertion']
103+
);
104104
jest.doMock('../../lib/oauth/client', () => ({
105105
...tokenRoutesDepMocks['../../oauth/client'],
106106
clientAuthValidators: realClient.clientAuthValidators,
107107
}));
108-
jest.doMock('../../lib/oauth/grant', () => tokenRoutesDepMocks['../../oauth/grant']);
109-
jest.doMock('../../lib/oauth/util', () => tokenRoutesDepMocks['../../oauth/util']);
108+
jest.doMock(
109+
'../../lib/oauth/grant',
110+
() => tokenRoutesDepMocks['../../oauth/grant']
111+
);
112+
jest.doMock(
113+
'../../lib/oauth/util',
114+
() => tokenRoutesDepMocks['../../oauth/util']
115+
);
110116
const tokenRouteFactory = require('../../lib/routes/oauth/token');
111117
tokenRoutes = tokenRouteFactory(tokenRoutesArgMocks);
112118
});

0 commit comments

Comments
 (0)