2018-04-03 14:16:57 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'vault/tests/helpers/module-for-acceptance';
|
|
|
|
import { supportedAuthBackends } from 'vault/helpers/supported-auth-backends';
|
2018-04-17 22:04:34 +00:00
|
|
|
import authForm from '../pages/components/auth-form';
|
|
|
|
import { create } from 'ember-cli-page-object';
|
2018-04-20 20:39:45 +00:00
|
|
|
import apiStub from 'vault/tests/helpers/noop-all-api-requests';
|
2018-04-17 22:04:34 +00:00
|
|
|
|
|
|
|
const component = create(authForm);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | auth', {
|
2018-04-17 22:04:34 +00:00
|
|
|
beforeEach() {
|
2018-04-20 20:39:45 +00:00
|
|
|
this.server = apiStub({ usePassthrough: true });
|
2018-04-03 14:16:57 +00:00
|
|
|
return authLogout();
|
|
|
|
},
|
2018-04-20 20:39:45 +00:00
|
|
|
afterEach() {
|
|
|
|
this.server.shutdown();
|
|
|
|
},
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('auth query params', function(assert) {
|
|
|
|
const backends = supportedAuthBackends();
|
|
|
|
visit('/vault/auth');
|
2018-04-20 20:39:45 +00:00
|
|
|
andThen(() => {
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.equal(currentURL(), '/vault/auth');
|
|
|
|
});
|
|
|
|
backends.reverse().forEach(backend => {
|
|
|
|
click(`[data-test-auth-method-link="${backend.type}"]`);
|
2018-04-20 20:39:45 +00:00
|
|
|
andThen(() => {
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/vault/auth?with=${backend.type}`,
|
|
|
|
`has the correct URL for ${backend.type}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-04-17 22:04:34 +00:00
|
|
|
|
|
|
|
test('it clears token when changing selected auth method', function(assert) {
|
|
|
|
visit('/vault/auth');
|
2018-04-20 20:39:45 +00:00
|
|
|
andThen(() => {
|
2018-04-17 22:04:34 +00:00
|
|
|
assert.equal(currentURL(), '/vault/auth');
|
|
|
|
});
|
|
|
|
component.token('token').tabs.filterBy('name', 'GitHub')[0].link();
|
|
|
|
component.tabs.filterBy('name', 'Token')[0].link();
|
2018-04-20 20:39:45 +00:00
|
|
|
andThen(() => {
|
2018-04-17 22:04:34 +00:00
|
|
|
assert.equal(component.tokenValue, '', 'it clears the token value when toggling methods');
|
|
|
|
});
|
|
|
|
});
|
2018-04-20 20:39:45 +00:00
|
|
|
|
|
|
|
test('it sends the right attributes when authenticating', function(assert) {
|
|
|
|
let backends = supportedAuthBackends();
|
|
|
|
visit('/vault/auth');
|
|
|
|
backends.reverse().forEach(backend => {
|
|
|
|
click(`[data-test-auth-method-link="${backend.type}"]`);
|
|
|
|
if (backend.type === 'GitHub') {
|
|
|
|
component.token('token');
|
|
|
|
}
|
|
|
|
component.login();
|
|
|
|
andThen(() => {
|
|
|
|
let lastRequest = this.server.passthroughRequests[this.server.passthroughRequests.length - 1];
|
|
|
|
let body = JSON.parse(lastRequest.requestBody);
|
|
|
|
if (backend.type === 'token') {
|
|
|
|
assert.ok(
|
|
|
|
Object.keys(lastRequest.requestHeaders).includes('X-Vault-Token'),
|
|
|
|
'token uses vault token header'
|
|
|
|
);
|
|
|
|
} else if (backend.type === 'GitHub') {
|
|
|
|
assert.ok(Object.keys(body).includes('token'), 'GitHub includes token');
|
|
|
|
} else {
|
|
|
|
assert.ok(Object.keys(body).includes('password'), `${backend.type} includes password`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|