2021-01-07 20:18:36 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { currentURL, visit, fillIn } from '@ember/test-helpers';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
import Pretender from 'pretender';
|
2021-12-10 21:17:54 +00:00
|
|
|
import logout from 'vault/tests/pages/logout';
|
2022-03-10 14:26:33 +00:00
|
|
|
import { getManagedNamespace } from 'vault/routes/vault/cluster';
|
2021-01-07 20:18:36 +00:00
|
|
|
|
|
|
|
const FEATURE_FLAGS_RESPONSE = {
|
2021-01-11 20:44:52 +00:00
|
|
|
feature_flags: ['VAULT_CLOUD_ADMIN_NAMESPACE'],
|
2021-01-07 20:18:36 +00:00
|
|
|
};
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Acceptance | Enterprise | Managed namespace root', function (hooks) {
|
2021-01-07 20:18:36 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2021-01-07 20:18:36 +00:00
|
|
|
/**
|
|
|
|
* Since the features are fetched on the application load,
|
|
|
|
* we have to populate them on the beforeEach hook because
|
|
|
|
* the fetch won't trigger again within the tests
|
|
|
|
*/
|
2021-12-17 03:44:29 +00:00
|
|
|
this.server = new Pretender(function () {
|
2021-01-07 20:18:36 +00:00
|
|
|
this.get('/v1/sys/internal/ui/feature-flags', () => {
|
|
|
|
return [200, { 'Content-Type': 'application/json' }, JSON.stringify(FEATURE_FLAGS_RESPONSE)];
|
|
|
|
});
|
|
|
|
this.get('/v1/sys/health', this.passthrough);
|
|
|
|
this.get('/v1/sys/seal-status', this.passthrough);
|
|
|
|
this.get('/v1/sys/license/features', this.passthrough);
|
2021-12-10 21:17:54 +00:00
|
|
|
this.get('/v1/sys/internal/ui/mounts', this.passthrough);
|
2021-01-07 20:18:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.afterEach(function () {
|
2021-01-07 20:18:36 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it shows the managed namespace toolbar when feature flag exists', async function (assert) {
|
2021-12-10 21:17:54 +00:00
|
|
|
await logout.visit();
|
2021-01-07 20:18:36 +00:00
|
|
|
await visit('/vault/auth');
|
2021-12-10 21:17:54 +00:00
|
|
|
assert.ok(currentURL().startsWith('/vault/auth'), 'Redirected to auth');
|
|
|
|
assert.ok(currentURL().includes('?namespace=admin'), 'with base namespace');
|
2021-01-07 20:18:36 +00:00
|
|
|
assert.dom('[data-test-namespace-toolbar]').doesNotExist('Normal namespace toolbar does not exist');
|
|
|
|
assert.dom('[data-test-managed-namespace-toolbar]').exists('Managed namespace toolbar exists');
|
|
|
|
assert.dom('[data-test-managed-namespace-root]').hasText('/admin', 'Shows /admin namespace prefix');
|
|
|
|
assert.dom('input#namespace').hasAttribute('placeholder', '/ (Default)');
|
|
|
|
await fillIn('input#namespace', '/foo');
|
|
|
|
let encodedNamespace = encodeURIComponent('admin/foo');
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/vault/auth?namespace=${encodedNamespace}&with=token`,
|
|
|
|
'Correctly prepends root to namespace'
|
|
|
|
);
|
|
|
|
});
|
2022-03-10 14:26:33 +00:00
|
|
|
|
|
|
|
test('getManagedNamespace helper works as expected', function (assert) {
|
|
|
|
let managedNs = getManagedNamespace(null, 'admin');
|
|
|
|
assert.equal(managedNs, 'admin', 'returns root ns when no namespace present');
|
|
|
|
managedNs = getManagedNamespace('admin/', 'admin');
|
|
|
|
assert.equal(managedNs, 'admin', 'returns root ns when matches passed ns');
|
|
|
|
managedNs = getManagedNamespace('adminfoo/', 'admin');
|
|
|
|
assert.equal(
|
|
|
|
managedNs,
|
|
|
|
'admin/adminfoo/',
|
|
|
|
'appends passed namespace to root even if it matches without slashes'
|
|
|
|
);
|
|
|
|
managedNs = getManagedNamespace('admin/foo/', 'admin');
|
|
|
|
assert.equal(managedNs, 'admin/foo/', 'returns passed namespace if it starts with root and /');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it redirects to root prefixed ns when non-root passed', async function (assert) {
|
|
|
|
await logout.visit();
|
|
|
|
await visit('/vault/auth?namespace=admindev');
|
|
|
|
assert.ok(currentURL().startsWith('/vault/auth'), 'Redirected to auth');
|
|
|
|
assert.ok(
|
|
|
|
currentURL().includes(`?namespace=${encodeURIComponent('admin/admindev')}`),
|
|
|
|
'with appended namespace'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.dom('[data-test-managed-namespace-root]').hasText('/admin', 'Shows /admin namespace prefix');
|
|
|
|
assert.dom('input#namespace').hasValue('/admindev', 'Input has /dev value');
|
|
|
|
});
|
2021-01-07 20:18:36 +00:00
|
|
|
});
|