feat: 🎸 add token validation step to authenticator
This commit is contained in:
3 files changed
+67
-4
No files matched your search
@@ -96,4 +96,45 @@ module('Unit | Authenticator | password', function (hooks) {
|
||||
.then(() => assert.ok(true))
|
||||
.catch(() => assert.notOk(true, 'uh oh, this should not happen'));
|
||||
});
|
||||
|
||||
test('it passes token validation on restoration if receiving 200', async function (assert) {
|
||||
assert.expect(1);
|
||||
const mockData = { id: 'token_123' };
|
||||
const authenticator = this.owner.lookup('authenticator:password');
|
||||
this.server.get(authenticator.buildTokenValidationEndpointURL(mockData.id), () => {
|
||||
assert.ok(true, 'token validation was requested');
|
||||
return new Response(200);
|
||||
});
|
||||
await authenticator.restore(mockData);
|
||||
});
|
||||
|
||||
test('it fails token validation on restoration if receiving 401', async function (assert) {
|
||||
assert.expect(2);
|
||||
const mockData = { id: 'token_123' };
|
||||
const authenticator = this.owner.lookup('authenticator:password');
|
||||
this.server.get(authenticator.buildTokenValidationEndpointURL(mockData.id), () => {
|
||||
assert.ok(true, 'token validation was requested');
|
||||
return new Response(401);
|
||||
});
|
||||
try {
|
||||
await authenticator.restore(mockData);
|
||||
} catch (e) {
|
||||
assert.ok(true, 'restoration failed');
|
||||
}
|
||||
});
|
||||
|
||||
test('it fails token validation on restoration if receiving 404', async function (assert) {
|
||||
assert.expect(2);
|
||||
const mockData = { id: 'token_123' };
|
||||
const authenticator = this.owner.lookup('authenticator:password');
|
||||
this.server.get(authenticator.buildTokenValidationEndpointURL(mockData.id), () => {
|
||||
assert.ok(true, 'token validation was requested');
|
||||
return new Response(404);
|
||||
});
|
||||
try {
|
||||
await authenticator.restore(mockData);
|
||||
} catch (e) {
|
||||
assert.ok(true, 'restoration failed');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user