mirror of
https://github.com/hashicorp/vault.git
synced 2025-09-18 20:31:08 +02:00
* build mirage handler for snapshot recovery endpoints * WIP add namespace and mount fields to read/recover form * change option to engine object * update badge color according to status and make loaded snapshot reqs within root ns * wip read reqs and view * add recovery banner and form validation * move read view into modal * tidying * organize * tests * style fixes * error handling * tests * WIP load form and update header * styling * update requests with snapshot params * style fix * yarn lock update for latest spec updates * hide dr seconday + flesh out load reqs * tests * add polling for snapshot status * disable button when not in ready state * reset errors * don't poll during tests * remove todo * test updates * fix ns select + test * remove todo * Revert "Merge branch 'copy/main/VAULT-38374/build-snapshot-manage-form' into ui/VAULT-38373/build-snapshot-load-form" This reverts commit f7cce759cda286bc7b76e84186b5497589706095, reversing changes made to 6cba99557ce6d8478f4c875579b71be4c531522e. * add breadcrumbs for load form * hide shared paths on performance secondaries * styling, tidy, mount options, engine types * lots of tidying, add manual mount input, slower polling * make read + recover requests in selected namespace * link to child ns if recovering there * test updates * remove todos * centralize recovery data values * type, state and error improvements * update FileToArrayBuffer to use HDS FileInput * error handling * allow manual input * tests * remove unneeded services * api call update * update radio fields to allow a badge for 404 message * update tests --------- Co-authored-by: lane-wetmore <lane.wetmore@hashicorp.com> Co-authored-by: claire bontempo <cbontempo@hashicorp.com>
99 lines
3.2 KiB
JavaScript
99 lines
3.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'vault/tests/helpers';
|
|
import { click, fillIn, render, triggerEvent, waitUntil } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import recoveryHandler from 'vault/mirage/handlers/recovery';
|
|
import { GENERAL } from 'vault/tests/helpers/general-selectors';
|
|
import sinon from 'sinon';
|
|
|
|
module('Integration | Component | recovery/snapshots-load', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
recoveryHandler(this.server);
|
|
|
|
this.model = {
|
|
configs: [],
|
|
configError: undefined,
|
|
};
|
|
this.breadcrumbs = [
|
|
{ label: 'Secrets Recovery', route: 'vault.cluster.recovery.snapshots' },
|
|
{ label: 'Upload', route: 'vault.cluster.recovery.snapshots.load' },
|
|
];
|
|
|
|
this.version = this.owner.lookup('service:version');
|
|
this.version.type = 'enterprise';
|
|
|
|
this.router = this.owner.lookup('service:router');
|
|
this.transitionStub = sinon.stub(this.router, 'transitionTo');
|
|
});
|
|
|
|
test('it should validate form fields', async function (assert) {
|
|
await render(
|
|
hbs`<Recovery::Page::Snapshots::Load @breadcrumbs={{this.breadcrumbs}} @model={{this.model}} />`
|
|
);
|
|
|
|
await click(GENERAL.submitButton);
|
|
|
|
assert
|
|
.dom(GENERAL.validationErrorByAttr('config'))
|
|
.hasText('Please select a config', 'Config error renders.');
|
|
|
|
assert.dom(GENERAL.validationErrorByAttr('url')).hasText('Please enter a url', 'Url error renders');
|
|
|
|
await click(GENERAL.inputByAttr('manual'));
|
|
await click(GENERAL.submitButton);
|
|
|
|
assert
|
|
.dom(GENERAL.validationErrorByAttr('file'))
|
|
.hasText('Please upload a snapshot file', 'File error renders.');
|
|
});
|
|
|
|
test('it loads a manual snapshot successfully', async function (assert) {
|
|
const file = new Blob([['some content for a file']], { type: 'text/plain' });
|
|
file.name = 'snapshot.snap';
|
|
|
|
await render(
|
|
hbs`<Recovery::Page::Snapshots::Load @breadcrumbs={{this.breadcrumbs}} @model={{this.model}} />`
|
|
);
|
|
|
|
await click(GENERAL.inputByAttr('manual'));
|
|
await triggerEvent('[data-test-file-input]', 'change', { files: [file] });
|
|
await click(GENERAL.submitButton);
|
|
|
|
await waitUntil(() => this.transitionStub.called);
|
|
|
|
assert.true(
|
|
this.transitionStub.calledWith('vault.cluster.recovery.snapshots'),
|
|
'Route transitions correctly on submit success'
|
|
);
|
|
});
|
|
|
|
test('it loads an automated snapshot successfully', async function (assert) {
|
|
this.model.configs = ['test-config'];
|
|
|
|
await render(
|
|
hbs`<Recovery::Page::Snapshots::Load @breadcrumbs={{this.breadcrumbs}} @model={{this.model}} />`
|
|
);
|
|
|
|
await click(GENERAL.selectByAttr('config'));
|
|
await click('[data-option-index]');
|
|
await fillIn(GENERAL.inputByAttr('url'), 'test-snapshot-url');
|
|
await click(GENERAL.submitButton);
|
|
|
|
await waitUntil(() => this.transitionStub.called);
|
|
|
|
assert.true(
|
|
this.transitionStub.calledWith('vault.cluster.recovery.snapshots'),
|
|
'Route transitions correctly on submit success'
|
|
);
|
|
});
|
|
});
|