|
5 | 5 | InMemoryStrategy, |
6 | 6 | UNAUTHENTICATED, |
7 | 7 | INSUFFICIENT, |
| 8 | + UNAUTHORIZED, |
8 | 9 | } from '../../lib/shared/keytar-strategy'; |
9 | 10 |
|
10 | 11 | describe('GithubLoginModel', function() { |
@@ -47,25 +48,55 @@ describe('GithubLoginModel', function() { |
47 | 48 | }); |
48 | 49 |
|
49 | 50 | it('returns INSUFFICIENT if scopes are present', async function() { |
50 | | - sinon.stub(loginModel, 'getScopes').returns(Promise.resolve(['repo', 'read:org'])); |
| 51 | + sinon.stub(loginModel, 'getScopes').resolves(['repo', 'read:org']); |
51 | 52 |
|
52 | 53 | assert.strictEqual(await loginModel.getToken('https://api.github.com'), INSUFFICIENT); |
53 | 54 | }); |
54 | 55 |
|
55 | 56 | it('returns the token if at least the required scopes are present', async function() { |
56 | | - sinon.stub(loginModel, 'getScopes').returns(Promise.resolve(['repo', 'read:org', 'user:email', 'extra'])); |
| 57 | + sinon.stub(loginModel, 'getScopes').resolves(['repo', 'read:org', 'user:email', 'extra']); |
57 | 58 |
|
58 | 59 | assert.strictEqual(await loginModel.getToken('https://api.github.com'), '1234'); |
59 | 60 | }); |
60 | 61 |
|
61 | 62 | it('caches checked tokens', async function() { |
62 | | - sinon.stub(loginModel, 'getScopes').returns(Promise.resolve(['repo', 'read:org', 'user:email'])); |
| 63 | + sinon.stub(loginModel, 'getScopes').resolves(['repo', 'read:org', 'user:email']); |
63 | 64 |
|
64 | 65 | assert.strictEqual(await loginModel.getToken('https://api.github.com'), '1234'); |
65 | 66 | assert.strictEqual(loginModel.getScopes.callCount, 1); |
66 | 67 |
|
67 | 68 | assert.strictEqual(await loginModel.getToken('https://api.github.com'), '1234'); |
68 | 69 | assert.strictEqual(loginModel.getScopes.callCount, 1); |
69 | 70 | }); |
| 71 | + |
| 72 | + it('caches tokens that failed to authenticate correctly', async function() { |
| 73 | + sinon.stub(loginModel, 'getScopes').resolves(UNAUTHORIZED); |
| 74 | + |
| 75 | + assert.strictEqual(await loginModel.getToken('https://api.github.com'), UNAUTHENTICATED); |
| 76 | + assert.strictEqual(loginModel.getScopes.callCount, 1); |
| 77 | + |
| 78 | + assert.strictEqual(await loginModel.getToken('https://api.github.com'), UNAUTHENTICATED); |
| 79 | + assert.strictEqual(loginModel.getScopes.callCount, 1); |
| 80 | + }); |
| 81 | + |
| 82 | + it('caches tokens that had insufficient scopes', async function() { |
| 83 | + sinon.stub(loginModel, 'getScopes').resolves(['repo', 'read:org']); |
| 84 | + |
| 85 | + assert.strictEqual(await loginModel.getToken('https://api.github.com'), INSUFFICIENT); |
| 86 | + assert.strictEqual(loginModel.getScopes.callCount, 1); |
| 87 | + |
| 88 | + assert.strictEqual(await loginModel.getToken('https://api.github.com'), INSUFFICIENT); |
| 89 | + assert.strictEqual(loginModel.getScopes.callCount, 1); |
| 90 | + }); |
| 91 | + |
| 92 | + it('does not cache network errors', async function() { |
| 93 | + sinon.stub(loginModel, 'getScopes').rejects(new Error('You unplugged your ethernet cable')); |
| 94 | + |
| 95 | + assert.strictEqual(await loginModel.getToken('https://api.github.com'), UNAUTHENTICATED); |
| 96 | + assert.strictEqual(loginModel.getScopes.callCount, 1); |
| 97 | + |
| 98 | + assert.strictEqual(await loginModel.getToken('https://api.github.com'), UNAUTHENTICATED); |
| 99 | + assert.strictEqual(loginModel.getScopes.callCount, 2); |
| 100 | + }); |
70 | 101 | }); |
71 | 102 | }); |
0 commit comments