vault/ui/tests/helpers/oidc-config.js
claire bontempo 4ac07e1d97
UI: HDS adoption replace <ConfirmAction> component (#21520)
* replace confirm-action dropdown with button+modal

* add modal frame to sidebar

* fix weird paragraph indent

* pass button text as arg

* add warning color to rotate modals

* update seal action and config ssh

* cleanup confirm action

* edit form

* add dropdown arg

* put back seal text

* put back confirm button text

* fix toolbar stylinggp

* popup member group

* move up title

* finish popup- components

* keymgmt

* fix modal button logic

* remaining app template components

* add period for angel

* vault cluster items

* add button text assertion

* remaining instances

* remove arg for passing confirm text

* contextual confirm action components

* delete old components

* update docs

* ammend dropdown loading states, add getter for confirm button color

* address feedback

* remove @disabled arg and add @disabledMessage

* add changelog;

* mfa tests

* update test selectors

* lol cleanup selectors

* start confirm action tests WIP

* move dropdown class directly to component

* add default color of isInDropdown

* final cleanup

* add tests

* remove @buttonColor as arg for dropdown

* update confirm action tests

* updae modals with disabled message

* refactor provider edit test
2023-11-17 23:44:21 +00:00

185 lines
5.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { Response } from 'miragejs';
export const OIDC_BASE_URL = `/vault/access/oidc`;
export const SELECTORS = {
oidcHeader: '[data-test-oidc-header]',
oidcClientCreateButton: '[data-test-oidc-configure]',
oidcRouteTabs: '[data-test-oidc-tabs]',
oidcLandingImg: '[data-test-oidc-img]',
confirmActionButton: '[data-test-confirm-button]',
inlineAlert: '[data-test-inline-alert]',
// client route
clientSaveButton: '[data-test-oidc-client-save]',
clientCancelButton: '[data-test-oidc-client-cancel]',
clientDeleteButton: '[data-test-oidc-client-delete]',
clientEditButton: '[data-test-oidc-client-edit]',
clientDetailsTab: '[data-test-oidc-client-details]',
clientProvidersTab: '[data-test-oidc-client-providers]',
// assignment route
assignmentSaveButton: '[data-test-oidc-assignment-save]',
assignmentCreateButton: '[data-test-oidc-assignment-create]',
assignmentEditButton: '[data-test-oidc-assignment-edit]',
assignmentDeleteButton: '[data-test-oidc-assignment-delete]',
assignmentCancelButton: '[data-test-oidc-assignment-cancel]',
assignmentDetailsTab: '[data-test-oidc-assignment-details]',
// scope routes
scopeSaveButton: '[data-test-oidc-scope-save]',
scopeCancelButton: '[data-test-oidc-scope-cancel]',
scopeDeleteButton: '[data-test-oidc-scope-delete]',
scopeEditButton: '[data-test-oidc-scope-edit]',
scopeDetailsTab: '[data-test-oidc-scope-details]',
scopeEmptyState: '[data-test-oidc-scope-empty-state]',
scopeCreateButtonEmptyState: '[data-test-oidc-scope-create-empty-state]',
scopeCreateButton: '[data-test-oidc-scope-create]',
// key route
keySaveButton: '[data-test-oidc-key-save]',
keyCancelButton: '[data-test-oidc-key-cancel]',
keyDeleteButton: '[data-test-oidc-key-delete]',
keyEditButton: '[data-test-oidc-key-edit]',
keyRotateButton: '[data-test-oidc-key-rotate]',
keyDetailsTab: '[data-test-oidc-key-details]',
keyClientsTab: '[data-test-oidc-key-clients]',
// provider route
providerSaveButton: '[data-test-oidc-provider-save]',
providerCancelButton: '[data-test-oidc-provider-cancel]',
providerDeleteButton: '[data-test-oidc-provider-delete]',
providerEditButton: '[data-test-oidc-provider-edit]',
providerDetailsTab: '[data-test-oidc-provider-details]',
providerClientsTab: '[data-test-oidc-provider-clients]',
};
export function overrideMirageResponse(httpStatus, data) {
if (httpStatus === 403) {
return new Response(
403,
{ 'Content-Type': 'application/json' },
JSON.stringify({ errors: ['permission denied'] })
);
}
if (httpStatus === 404) {
return new Response(404, { 'Content-Type': 'application/json' });
}
if (httpStatus === 200) {
return new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify(data));
}
return {
request_id: crypto.randomUUID(),
lease_id: '',
renewable: false,
lease_duration: 0,
wrap_info: null,
warnings: null,
auth: null,
data: { ...data },
};
}
export function overrideCapabilities(requestPath, capabilitiesArray) {
// sample of capabilitiesArray: ['read', 'update']
return {
request_id: '40f7e44d-af5c-9b60-bd20-df72eb17e294',
lease_id: '',
renewable: false,
lease_duration: 0,
data: {
capabilities: capabilitiesArray,
[requestPath]: capabilitiesArray,
},
wrap_info: null,
warnings: null,
auth: null,
};
}
export async function clearRecord(store, modelType, id) {
await store
.findRecord(modelType, id)
.then((model) => {
deleteModelRecord(model);
})
.catch(() => {
// swallow error
});
}
const deleteModelRecord = async (model) => {
await model.destroyRecord();
};
// MOCK RESPONSES:
export const CLIENT_LIST_RESPONSE = {
keys: ['test-app', 'app-1'],
key_info: {
'test-app': {
assignments: ['allow_all'],
client_id: 'whaT7KB0C3iBH1l3rXhd5HPf0n6vXU0s',
client_secret: 'hvo_secret_nkJSTu2NVYqylXwFbFijsTxJHg4Ic4gqSJw7uOZ4FbSXcObngDkKoVsvyndrf2O8',
client_type: 'confidential',
id_token_ttl: 0,
key: 'default',
redirect_uris: [],
},
'app-1': {
assignments: ['allow_all'],
client_id: 'HkmsTA4GG17j0Djy4EUAB2VAyzuLVewg',
client_secret: 'hvo_secret_g3f30MxAJWLXhhrCejbG4zY3O4LEHhEIO24aMy181AYKnfQtWTVV924ZmnlpUFUw',
client_type: 'confidential',
id_token_ttl: 0,
key: 'test-key',
redirect_uris: [],
},
},
};
export const CLIENT_DATA_RESPONSE = {
access_token_ttl: 0,
assignments: ['allow_all'],
client_id: 'whaT7KB0C3iBH1l3rXhd5HPf0n6vXU0s',
client_secret: 'hvo_secret_nkJSTu2NVYqylXwFbFijsTxJHg4Ic4gqSJw7uOZ4FbSXcObngDkKoVsvyndrf2O8',
client_type: 'confidential',
id_token_ttl: 0,
key: 'default',
redirect_uris: [],
};
export const ASSIGNMENT_LIST_RESPONSE = {
keys: ['allow_all', 'test-assignment'],
};
export const ASSIGNMENT_DATA_RESPONSE = {
group_ids: ['262ca5b9-7b69-0a84-446a-303dc7d778af'],
entity_ids: ['b6094ac6-baf4-6520-b05a-2bd9f07c66da'],
};
export const SCOPE_LIST_RESPONSE = {
keys: ['test-scope'],
};
export const SCOPE_DATA_RESPONSE = {
description: 'this is a test',
template: `{
"groups": {{identity.entity.groups.names}}
}`,
};
export const PROVIDER_LIST_RESPONSE = {
keys: ['test-provider'],
};
export const PROVIDER_DATA_RESPONSE = {
allowed_client_ids: ['*'],
issuer: '',
scopes_supported: ['test-scope'],
};