2018-09-25 16:28:26 +00:00
|
|
|
import { click, fillIn, find, findAll, currentURL, visit } from '@ember/test-helpers';
|
2018-05-22 21:49:29 +00:00
|
|
|
import Pretender from 'pretender';
|
2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2018-04-03 14:16:57 +00:00
|
|
|
import { toolsActions } from 'vault/helpers/tools-actions';
|
2018-09-25 16:28:26 +00:00
|
|
|
import authPage from 'vault/tests/pages/auth';
|
|
|
|
import logout from 'vault/tests/pages/logout';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
module('Acceptance | tools', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
hooks.beforeEach(function() {
|
|
|
|
return authPage.login();
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
hooks.afterEach(function() {
|
|
|
|
return logout.visit();
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
const DATA_TO_WRAP = JSON.stringify({ tools: 'tests' });
|
|
|
|
const TOOLS_ACTIONS = toolsActions();
|
|
|
|
|
|
|
|
/*
|
|
|
|
data-test-tools-input="wrapping-token"
|
|
|
|
data-test-tools-input="rewrapped-token"
|
|
|
|
data-test-tools="token-lookup-row"
|
|
|
|
data-test-tools-action-link=supportedAction
|
|
|
|
*/
|
|
|
|
|
|
|
|
var createTokenStore = () => {
|
|
|
|
let token;
|
|
|
|
return {
|
|
|
|
set(val) {
|
|
|
|
token = val;
|
|
|
|
},
|
|
|
|
get() {
|
|
|
|
return token;
|
|
|
|
},
|
|
|
|
};
|
2018-04-03 14:16:57 +00:00
|
|
|
};
|
2018-09-25 16:28:26 +00:00
|
|
|
test('tools functionality', async function(assert) {
|
|
|
|
var tokenStore = createTokenStore();
|
|
|
|
await visit('/vault/tools');
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.equal(currentURL(), '/vault/tools/wrap', 'forwards to the first action');
|
|
|
|
TOOLS_ACTIONS.forEach(action => {
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(find(`[data-test-tools-action-link="${action}"]`), `${action} link renders`);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
findAll('.CodeMirror')[0].CodeMirror.setValue(DATA_TO_WRAP);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
// wrap
|
|
|
|
await click('[data-test-tools-submit]');
|
|
|
|
tokenStore.set(find('[data-test-tools-input="wrapping-token"]').value);
|
|
|
|
assert.ok(find('[data-test-tools-input="wrapping-token"]').value, 'has a wrapping token');
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
//lookup
|
|
|
|
await click('[data-test-tools-action-link="lookup"]');
|
|
|
|
await fillIn('[data-test-tools-input="wrapping-token"]', tokenStore.get());
|
|
|
|
await click('[data-test-tools-submit]');
|
2018-05-29 14:14:31 +00:00
|
|
|
let rows = document.querySelectorAll('[data-test-tools="token-lookup-row"]');
|
|
|
|
assert.dom(rows[0]).hasText(/Creation path/, 'show creation path row');
|
|
|
|
assert.dom(rows[1]).hasText(/Creation time/, 'show creation time row');
|
|
|
|
assert.dom(rows[2]).hasText(/Creation TTL/, 'show creation ttl row');
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
//rewrap
|
|
|
|
await click('[data-test-tools-action-link="rewrap"]');
|
|
|
|
await fillIn('[data-test-tools-input="wrapping-token"]', tokenStore.get());
|
|
|
|
await click('[data-test-tools-submit]');
|
|
|
|
assert.ok(find('[data-test-tools-input="rewrapped-token"]').value, 'has a new re-wrapped token');
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.notEqual(
|
2018-09-25 16:28:26 +00:00
|
|
|
find('[data-test-tools-input="rewrapped-token"]').value,
|
2018-04-03 14:16:57 +00:00
|
|
|
tokenStore.get(),
|
|
|
|
're-wrapped token is not the wrapped token'
|
|
|
|
);
|
2018-09-25 16:28:26 +00:00
|
|
|
tokenStore.set(find('[data-test-tools-input="rewrapped-token"]').value);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
//unwrap
|
|
|
|
await click('[data-test-tools-action-link="unwrap"]');
|
|
|
|
await fillIn('[data-test-tools-input="wrapping-token"]', tokenStore.get());
|
|
|
|
await click('[data-test-tools-submit]');
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.deepEqual(
|
2018-09-25 16:28:26 +00:00
|
|
|
JSON.parse(findAll('.CodeMirror')[0].CodeMirror.getValue()),
|
2018-04-03 14:16:57 +00:00
|
|
|
JSON.parse(DATA_TO_WRAP),
|
|
|
|
'unwrapped data equals input data'
|
|
|
|
);
|
2019-03-13 14:43:57 +00:00
|
|
|
await click('[data-test-button-details]');
|
|
|
|
await click('[data-test-button-data]');
|
|
|
|
assert.dom('.CodeMirror').exists();
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
//random
|
|
|
|
await click('[data-test-tools-action-link="random"]');
|
2018-04-27 16:33:19 +00:00
|
|
|
assert.dom('[data-test-tools-input="bytes"]').hasValue('32', 'defaults to 32 bytes');
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-tools-submit]');
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.ok(
|
2018-09-25 16:28:26 +00:00
|
|
|
find('[data-test-tools-input="random-bytes"]').value,
|
2018-04-03 14:16:57 +00:00
|
|
|
'shows the returned value of random bytes'
|
|
|
|
);
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
//hash
|
|
|
|
await click('[data-test-tools-action-link="hash"]');
|
|
|
|
await fillIn('[data-test-tools-input="hash-input"]', 'foo');
|
|
|
|
await click('[data-test-tools-b64-toggle="input"]');
|
|
|
|
await click('[data-test-tools-submit]');
|
2018-05-24 03:10:21 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-tools-input="sum"]')
|
|
|
|
.hasValue('LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=', 'hashes the data, encodes input');
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-tools-back]');
|
|
|
|
await fillIn('[data-test-tools-input="hash-input"]', 'e2RhdGE6ImZvbyJ9');
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-tools-submit]');
|
2018-05-24 03:10:21 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-tools-input="sum"]')
|
|
|
|
.hasValue('JmSi2Hhbgu2WYOrcOyTqqMdym7KT3sohCwAwaMonVrc=', 'hashes the data, passes b64 input through');
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
2018-05-22 21:49:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
const AUTH_RESPONSE = {
|
|
|
|
request_id: '39802bc4-235c-2f0b-87f3-ccf38503ac3e',
|
|
|
|
lease_id: '',
|
2018-05-24 03:10:21 +00:00
|
|
|
renewable: false,
|
2018-09-25 16:28:26 +00:00
|
|
|
lease_duration: 0,
|
|
|
|
data: null,
|
|
|
|
wrap_info: null,
|
|
|
|
warnings: null,
|
|
|
|
auth: {
|
|
|
|
client_token: 'ecfc2758-588e-981d-50f4-a25883bbf03c',
|
|
|
|
accessor: '6299780b-f2b2-1a3f-7b83-9d3d67629249',
|
|
|
|
policies: ['root'],
|
|
|
|
metadata: null,
|
|
|
|
lease_duration: 0,
|
|
|
|
renewable: false,
|
|
|
|
entity_id: '',
|
|
|
|
},
|
|
|
|
};
|
2018-05-22 21:49:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('ensure unwrap with auth block works properly', async function(assert) {
|
|
|
|
this.server = new Pretender(function() {
|
|
|
|
this.post('/v1/sys/wrapping/unwrap', response => {
|
|
|
|
return [response, { 'Content-Type': 'application/json' }, JSON.stringify(AUTH_RESPONSE)];
|
|
|
|
});
|
2018-05-22 21:49:29 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
await visit('/vault/tools');
|
|
|
|
//unwrap
|
|
|
|
await click('[data-test-tools-action-link="unwrap"]');
|
|
|
|
await fillIn('[data-test-tools-input="wrapping-token"]', 'sometoken');
|
|
|
|
await click('[data-test-tools-submit]');
|
2018-05-22 21:49:29 +00:00
|
|
|
assert.deepEqual(
|
2018-09-25 16:28:26 +00:00
|
|
|
JSON.parse(findAll('.CodeMirror')[0].CodeMirror.getValue()),
|
2018-05-22 21:49:29 +00:00
|
|
|
AUTH_RESPONSE.auth,
|
|
|
|
'unwrapped data equals input data'
|
|
|
|
);
|
|
|
|
this.server.shutdown();
|
|
|
|
});
|
|
|
|
});
|