Files
threshold-ui/addons/auth/tests/unit/authenticators/password-test.js
T
78585d999b feat: 🎸 switch to new token type parameter (#1082)
Boundary is deprecating the use of the token_type
parameter to the Authenticate endpoint, instead
replacing it with the new type parameter.

See https://github.com/hashicorp/boundary/commit/80b2c9230fa84605d9aaf7c862f780b50690a36e
for more context.

Co-authored-by: Randall Morey <randall@randallmorey.com>
Co-authored-by: Carlos Alcaide Corvo <ccorvo@hashicorp.com>
2022-07-11 16:39:20 -07:00

78 lines
2.5 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { Response } from 'miragejs';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
module('Unit | Authenticator | password', function (hooks) {
setupTest(hooks);
setupMirage(hooks);
test('it authenticates to the specified authEndpoint', async function (assert) {
assert.expect(2);
const authenticator = this.owner.lookup('authenticator:password');
this.server.post(
authenticator.buildAuthEndpointURL(),
(schema, request) => {
const json = JSON.parse(request.requestBody);
assert.ok(json.type, 'Requested token cookies by default');
return new Response(200);
}
);
await authenticator.authenticate({}).then(() => {
assert.ok(true, 'authentication succeeded');
});
});
test('it can authenticate without requesting cookies', async function (assert) {
assert.expect(2);
const authenticator = this.owner.lookup('authenticator:password');
this.server.post(
authenticator.buildAuthEndpointURL(),
(schema, request) => {
const json = JSON.parse(request.requestBody);
assert.notOk(json.type, 'Did not request tokens cookies');
return new Response(200);
}
);
await authenticator.authenticate({}, false).then(() => {
assert.ok(true, 'authentication succeeded');
});
});
test('it authenticates with the expected payload', async function (assert) {
assert.expect(1);
const authenticator = this.owner.lookup('authenticator:password');
this.server.post(
authenticator.buildAuthEndpointURL(),
(schema, request) => {
const json = JSON.parse(request.requestBody);
assert.deepEqual(json, {
command: 'login',
type: 'cookie',
attributes: {
login_name: 'foo',
password: 'bar',
},
});
return new Response(200);
}
);
const creds = {
identification: 'foo',
password: 'bar',
};
await authenticator.authenticate(creds);
});
test('it rejects if the endpoint sends an error status code', async function (assert) {
assert.expect(1);
const authenticator = this.owner.lookup('authenticator:password');
this.server.post(authenticator.buildAuthEndpointURL(), () => {
return new Response(400);
});
await authenticator.authenticate({}).catch(() => {
assert.ok(true, 'authentication failed');
});
});
});