mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
UI: Dependency bumps 1.17.x (#26346)
* re-form yarn.lock, remove resolutions that are out of date. resolves: - mout VAULT-25595 VAULT-25603 - follow-redirects VAULT-25605 - terser VAULT-25594 VAULT-25593 - minimatch VAULT-25591 - loader-utils VAULT-25216 VAULT-25590 VAULT-25589 VAULT-25588 VAULT-25587 - decode-uri-component VAULT-25586 - qs VAULT-25585 - @xmldom/xmldom VAULT-25217 * VAULT-25596 pin async in resolutions due to testem > fireworm * VAULT-25606 pin nth-check due to ember-svg-jar * fix typescript errors after bump * update ember-template-lint to 6.0.0 * Add broken rules to template-eslintrc * pin ansi-html * remove ember-d3 in favor of specific d3 libraries we import * add changelog
This commit is contained in:
@@ -12,10 +12,11 @@ import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render, settled } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
import sinon from 'sinon';
|
||||
import Pretender from 'pretender';
|
||||
import { create } from 'ember-cli-page-object';
|
||||
import authForm from '../../pages/components/auth-form';
|
||||
import { validate } from 'uuid';
|
||||
import { setupMirage } from 'ember-cli-mirage/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
|
||||
const component = create(authForm);
|
||||
|
||||
@@ -39,6 +40,7 @@ const routerService = Service.extend({
|
||||
|
||||
module('Integration | Component | auth form', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.owner.register('service:router', routerService);
|
||||
@@ -60,35 +62,21 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
|
||||
test('it renders with vault style errors', async function (assert) {
|
||||
assert.expect(1);
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/auth/**', () => {
|
||||
return [
|
||||
400,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify({
|
||||
errors: ['Not allowed'],
|
||||
}),
|
||||
];
|
||||
});
|
||||
this.get('/v1/sys/internal/ui/mounts', this.passthrough);
|
||||
this.server.get('/auth/token/lookup-self', () => {
|
||||
return new Response(400, { 'Content-Type': 'application/json' }, { errors: ['Not allowed'] });
|
||||
});
|
||||
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
this.set('selectedAuth', 'token');
|
||||
await render(hbs`<AuthForm @cluster={{this.cluster}} @selectedAuth={{this.selectedAuth}} />`);
|
||||
return component.login().then(() => {
|
||||
assert.strictEqual(component.errorText, 'Error Authentication failed: Not allowed');
|
||||
server.shutdown();
|
||||
});
|
||||
await component.login();
|
||||
assert.strictEqual(component.errorText, 'Error Authentication failed: Not allowed');
|
||||
});
|
||||
|
||||
test('it renders AdapterError style errors', async function (assert) {
|
||||
assert.expect(1);
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/auth/**', () => {
|
||||
return [400, { 'Content-Type': 'application/json' }, JSON.stringify({ errors: ['API Error here'] })];
|
||||
});
|
||||
this.get('/v1/sys/internal/ui/mounts', this.passthrough);
|
||||
this.server.get('/auth/token/lookup-self', () => {
|
||||
return new Response(400, { 'Content-Type': 'application/json' }, { errors: ['API Error here'] });
|
||||
});
|
||||
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
@@ -100,7 +88,6 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
'Error Authentication failed: API Error here',
|
||||
'shows the error from the API'
|
||||
);
|
||||
server.shutdown();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,10 +97,8 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
type: 'approle',
|
||||
},
|
||||
};
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/sys/internal/ui/mounts', () => {
|
||||
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({ data: { auth: methods } })];
|
||||
});
|
||||
this.server.get('/sys/internal/ui/mounts', () => {
|
||||
return { data: { auth: methods } };
|
||||
});
|
||||
await render(hbs`<AuthForm @cluster={{this.cluster}} />`);
|
||||
|
||||
@@ -130,19 +115,15 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
type: 'approle',
|
||||
},
|
||||
};
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/sys/internal/ui/mounts', () => {
|
||||
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({ data: { auth: methods } })];
|
||||
});
|
||||
this.server.get('/sys/internal/ui/mounts', () => {
|
||||
return { data: { auth: methods } };
|
||||
});
|
||||
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
await render(hbs`<AuthForm @cluster={{this.cluster}} />`);
|
||||
|
||||
assert.strictEqual(component.tabs.length, 2, 'renders a tab for userpass and Other');
|
||||
assert.strictEqual(component.tabs.objectAt(0).name, 'foo', 'uses the path in the label');
|
||||
assert.strictEqual(component.tabs.objectAt(1).name, 'Other', 'second tab is the Other tab');
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
test('it renders the description', async function (assert) {
|
||||
@@ -152,10 +133,8 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
description: 'app description',
|
||||
},
|
||||
};
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/sys/internal/ui/mounts', () => {
|
||||
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({ data: { auth: methods } })];
|
||||
});
|
||||
this.server.get('/sys/internal/ui/mounts', () => {
|
||||
return { data: { auth: methods } };
|
||||
});
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
await render(hbs`<AuthForm @cluster={{this.cluster}} />`);
|
||||
@@ -165,7 +144,6 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
'app description',
|
||||
'renders a description for auth methods'
|
||||
);
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
test('it calls authenticate with the correct path', async function (assert) {
|
||||
@@ -178,10 +156,8 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
type: 'userpass',
|
||||
},
|
||||
};
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/sys/internal/ui/mounts', () => {
|
||||
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({ data: { auth: methods } })];
|
||||
});
|
||||
this.server.get('/sys/internal/ui/mounts', () => {
|
||||
return { data: { auth: methods } };
|
||||
});
|
||||
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
@@ -194,7 +170,6 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
const { data } = authSpy.getCall(0).args[0];
|
||||
assert.strictEqual(data.path, 'foo', 'uses the id for the path');
|
||||
authSpy.restore();
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
test('it renders no tabs when no supported methods are present in passed methods', async function (assert) {
|
||||
@@ -203,10 +178,8 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
type: 'approle',
|
||||
},
|
||||
};
|
||||
const server = new Pretender(function () {
|
||||
this.get('/v1/sys/internal/ui/mounts', () => {
|
||||
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({ data: { auth: methods } })];
|
||||
});
|
||||
this.server.get('/sys/internal/ui/mounts', () => {
|
||||
return { data: { auth: methods } };
|
||||
});
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
await render(hbs`<AuthForm @cluster={{this.cluster}} />`);
|
||||
@@ -216,21 +189,22 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
});
|
||||
|
||||
test('it makes a request to unwrap if passed a wrappedToken and logs in', async function (assert) {
|
||||
assert.expect(3);
|
||||
this.owner.register('service:auth', workingAuthService);
|
||||
this.auth = this.owner.lookup('service:auth');
|
||||
const authSpy = sinon.spy(this.auth, 'authenticate');
|
||||
const server = new Pretender(function () {
|
||||
this.post('/v1/sys/wrapping/unwrap', () => {
|
||||
return [
|
||||
200,
|
||||
{ 'content-type': 'application/json' },
|
||||
JSON.stringify({
|
||||
auth: {
|
||||
client_token: '12345',
|
||||
},
|
||||
}),
|
||||
];
|
||||
});
|
||||
const authSpy = sinon.stub(this.auth, 'authenticate');
|
||||
this.server.post('/sys/wrapping/unwrap', (_, req) => {
|
||||
assert.strictEqual(req.url, '/v1/sys/wrapping/unwrap', 'makes call to unwrap the token');
|
||||
assert.strictEqual(
|
||||
req.requestHeaders['X-Vault-Token'],
|
||||
wrappedToken,
|
||||
'uses passed wrapped token for the unwrap'
|
||||
);
|
||||
return {
|
||||
auth: {
|
||||
client_token: '12345',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const wrappedToken = '54321';
|
||||
@@ -241,32 +215,17 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
);
|
||||
later(() => cancelTimers(), 50);
|
||||
await settled();
|
||||
assert.strictEqual(
|
||||
server.handledRequests[0].url,
|
||||
'/v1/sys/wrapping/unwrap',
|
||||
'makes call to unwrap the token'
|
||||
);
|
||||
assert.strictEqual(
|
||||
server.handledRequests[0].requestHeaders['x-vault-token'],
|
||||
wrappedToken,
|
||||
'uses passed wrapped token for the unwrap'
|
||||
);
|
||||
assert.ok(authSpy.calledOnce, 'a call to authenticate was made');
|
||||
server.shutdown();
|
||||
authSpy.restore();
|
||||
});
|
||||
|
||||
test('it shows an error if unwrap errors', async function (assert) {
|
||||
const server = new Pretender(function () {
|
||||
this.post('/v1/sys/wrapping/unwrap', () => {
|
||||
return [
|
||||
400,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify({
|
||||
errors: ['There was an error unwrapping!'],
|
||||
}),
|
||||
];
|
||||
});
|
||||
this.server.post('/sys/wrapping/unwrap', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
{ errors: ['There was an error unwrapping!'] }
|
||||
);
|
||||
});
|
||||
|
||||
this.set('wrappedToken', '54321');
|
||||
@@ -279,32 +238,27 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
'Error Token unwrap failed: There was an error unwrapping!',
|
||||
'shows the error'
|
||||
);
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
test('it should retain oidc role when mount path is changed', async function (assert) {
|
||||
assert.expect(1);
|
||||
assert.expect(2);
|
||||
|
||||
const auth_url = 'http://dev-foo-bar.com';
|
||||
const server = new Pretender(function () {
|
||||
this.post('/v1/auth/:path/oidc/auth_url', (req) => {
|
||||
const { role, redirect_uri } = JSON.parse(req.requestBody);
|
||||
const goodRequest =
|
||||
req.params.path === 'foo-oidc' &&
|
||||
role === 'foo' &&
|
||||
redirect_uri.includes('/auth/foo-oidc/oidc/callback');
|
||||
this.server.post('/auth/:path/oidc/auth_url', (_, req) => {
|
||||
const { role, redirect_uri } = JSON.parse(req.requestBody);
|
||||
const goodRequest =
|
||||
req.params.path === 'foo-oidc' &&
|
||||
role === 'foo' &&
|
||||
redirect_uri.includes('/auth/foo-oidc/oidc/callback');
|
||||
|
||||
return [
|
||||
goodRequest ? 200 : 400,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify(
|
||||
goodRequest ? { data: { auth_url } } : { errors: [`role "${role}" could not be found`] }
|
||||
),
|
||||
];
|
||||
});
|
||||
this.get('/v1/sys/internal/ui/mounts', this.passthrough);
|
||||
return new Response(
|
||||
goodRequest ? 200 : 400,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify(
|
||||
goodRequest ? { data: { auth_url } } : { errors: [`role "${role}" could not be found`] }
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
window.open = (url) => {
|
||||
assert.strictEqual(url, auth_url, 'auth_url is returned when required params are passed');
|
||||
};
|
||||
@@ -322,29 +276,21 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
await component.oidcRole('foo');
|
||||
await component.oidcMoreOptions();
|
||||
await component.oidcMountPath('foo-oidc');
|
||||
assert.dom('[data-test-role]').hasValue('foo', 'role is retained when mount path is changed');
|
||||
await component.login();
|
||||
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
test('it should set nonce value as uuid for okta method type', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const server = new Pretender(function () {
|
||||
this.post('/v1/auth/okta/login/foo', (req) => {
|
||||
const { nonce } = JSON.parse(req.requestBody);
|
||||
assert.true(validate(nonce), 'Nonce value passed as uuid for okta login');
|
||||
return [
|
||||
200,
|
||||
{ 'content-type': 'application/json' },
|
||||
JSON.stringify({
|
||||
auth: {
|
||||
client_token: '12345',
|
||||
},
|
||||
}),
|
||||
];
|
||||
});
|
||||
this.get('/v1/sys/internal/ui/mounts', this.passthrough);
|
||||
this.server.post('/auth/okta/login/foo', (_, req) => {
|
||||
const { nonce } = JSON.parse(req.requestBody);
|
||||
assert.true(validate(nonce), 'Nonce value passed as uuid for okta login');
|
||||
return {
|
||||
auth: {
|
||||
client_token: '12345',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
this.set('cluster', EmberObject.create({}));
|
||||
@@ -354,7 +300,5 @@ module('Integration | Component | auth form', function (hooks) {
|
||||
await component.username('foo');
|
||||
await component.password('bar');
|
||||
await component.login();
|
||||
|
||||
server.shutdown();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user