|
1 | | -export {}; |
2 | | - |
3 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
@@ -46,81 +44,73 @@ describe('the signing-key management scripts', () => { |
46 | 44 | rimraf.sync(workDir); |
47 | 45 | }); |
48 | 46 |
|
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); |
126 | 116 | }); |
0 commit comments