2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2018-11-05 16:56:59 +00:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import { click, currentURL, visit, settled } from '@ember/test-helpers';
|
2018-04-03 14:16:57 +00:00
|
|
|
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-11-05 16:56:59 +00:00
|
|
|
import authPage from 'vault/tests/pages/auth';
|
2018-09-25 16:28:26 +00:00
|
|
|
import logout from 'vault/tests/pages/logout';
|
2018-04-17 22:04:34 +00:00
|
|
|
|
2018-11-05 16:56:59 +00:00
|
|
|
import consoleClass from 'vault/tests/pages/components/console/ui-panel';
|
|
|
|
const consoleComponent = create(consoleClass);
|
2018-04-17 22:04:34 +00:00
|
|
|
const component = create(authForm);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
module('Acceptance | auth', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2018-11-05 16:56:59 +00:00
|
|
|
this.clock = sinon.useFakeTimers({
|
|
|
|
now: Date.now(),
|
|
|
|
shouldAdvanceTime: true,
|
|
|
|
});
|
2018-04-20 20:39:45 +00:00
|
|
|
this.server = apiStub({ usePassthrough: true });
|
2018-09-25 16:28:26 +00:00
|
|
|
return logout.visit();
|
|
|
|
});
|
|
|
|
|
|
|
|
hooks.afterEach(function() {
|
2018-11-05 16:56:59 +00:00
|
|
|
this.clock.restore();
|
2018-04-20 20:39:45 +00:00
|
|
|
this.server.shutdown();
|
2018-11-05 16:56:59 +00:00
|
|
|
return logout.visit();
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('auth query params', async function(assert) {
|
|
|
|
let backends = supportedAuthBackends();
|
|
|
|
await visit('/vault/auth');
|
2018-07-05 18:28:12 +00:00
|
|
|
assert.equal(currentURL(), '/vault/auth?with=token');
|
2018-09-25 16:28:26 +00:00
|
|
|
for (let backend of backends.reverse()) {
|
|
|
|
await click(`[data-test-auth-method-link="${backend.type}"]`);
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/vault/auth?with=${backend.type}`,
|
|
|
|
`has the correct URL for ${backend.type}`
|
|
|
|
);
|
2018-09-25 16:28:26 +00:00
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
2018-04-17 22:04:34 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it clears token when changing selected auth method', async function(assert) {
|
|
|
|
await visit('/vault/auth');
|
2018-07-05 18:28:12 +00:00
|
|
|
assert.equal(currentURL(), '/vault/auth?with=token');
|
2018-09-25 16:28:26 +00:00
|
|
|
await component
|
|
|
|
.token('token')
|
|
|
|
.tabs.filterBy('name', 'GitHub')[0]
|
|
|
|
.link();
|
|
|
|
await component.tabs.filterBy('name', 'Token')[0].link();
|
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
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it sends the right attributes when authenticating', async function(assert) {
|
|
|
|
let backends = supportedAuthBackends();
|
|
|
|
await visit('/vault/auth');
|
|
|
|
for (let backend of backends.reverse()) {
|
|
|
|
await click(`[data-test-auth-method-link="${backend.type}"]`);
|
|
|
|
if (backend.type === 'github') {
|
|
|
|
await component.token('token');
|
|
|
|
}
|
|
|
|
await component.login();
|
2018-04-20 20:39:45 +00:00
|
|
|
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'
|
|
|
|
);
|
2018-08-16 13:16:24 +00:00
|
|
|
} else if (backend.type === 'github') {
|
2018-04-20 20:39:45 +00:00
|
|
|
assert.ok(Object.keys(body).includes('token'), 'GitHub includes token');
|
|
|
|
} else {
|
|
|
|
assert.ok(Object.keys(body).includes('password'), `${backend.type} includes password`);
|
|
|
|
}
|
2018-09-25 16:28:26 +00:00
|
|
|
}
|
2018-04-20 20:39:45 +00:00
|
|
|
});
|
2018-11-05 16:56:59 +00:00
|
|
|
|
|
|
|
test('it shows the token warning beacon on the menu', async function(assert) {
|
|
|
|
let authService = this.owner.lookup('service:auth');
|
|
|
|
await authPage.login();
|
|
|
|
await consoleComponent.runCommands([
|
|
|
|
'write -field=client_token auth/token/create policies=default ttl=1h',
|
|
|
|
]);
|
|
|
|
let token = consoleComponent.lastTextOutput;
|
|
|
|
await logout.visit();
|
|
|
|
await authPage.login(token);
|
|
|
|
this.clock.tick(authService.IDLE_TIMEOUT);
|
|
|
|
authService.shouldRenew();
|
|
|
|
await settled();
|
|
|
|
assert.dom('[data-test-allow-expiration="true"]').exists('shows expiration beacon');
|
|
|
|
|
|
|
|
await visit('/vault/access');
|
|
|
|
assert.dom('[data-test-allow-expiration="true"]').doesNotExist('hides beacon when the api is used again');
|
|
|
|
});
|
2018-04-20 20:39:45 +00:00
|
|
|
});
|