mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 19:17:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
196 lines
6.5 KiB
JavaScript
196 lines
6.5 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import { render, click, fillIn } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import { setupEngine } from 'ember-engines/test-support';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import { issuerPemBundle } from 'vault/tests/helpers/pki/values';
|
|
|
|
module('Integration | Component | PkiImportPemBundle', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupMirage(hooks);
|
|
setupEngine(hooks, 'pki'); // https://github.com/ember-engines/ember-engines/pull/653
|
|
|
|
hooks.beforeEach(function () {
|
|
this.store = this.owner.lookup('service:store');
|
|
this.model = this.store.createRecord('pki/action');
|
|
this.backend = 'pki-test';
|
|
this.secretMountPath = this.owner.lookup('service:secret-mount-path');
|
|
this.secretMountPath.currentPath = this.backend;
|
|
this.pemBundle = issuerPemBundle;
|
|
this.onComplete = () => {};
|
|
});
|
|
|
|
test('it renders import and updates model', async function (assert) {
|
|
assert.expect(3);
|
|
await render(
|
|
hbs`
|
|
<PkiImportPemBundle
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
@onComplete={{this.onComplete}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
|
|
assert.dom('[data-test-pki-import-pem-bundle-form]').exists('renders form');
|
|
assert.dom('[data-test-component="text-file"]').exists('renders text file input');
|
|
await click('[data-test-text-toggle]');
|
|
await fillIn('[data-test-text-file-textarea]', this.pemBundle);
|
|
assert.strictEqual(this.model.pemBundle, this.pemBundle);
|
|
});
|
|
|
|
test('it sends correct payload to import endpoint', async function (assert) {
|
|
assert.expect(4);
|
|
this.server.post(`/${this.backend}/issuers/import/bundle`, (schema, req) => {
|
|
assert.ok(true, 'Request made to the correct endpoint to import issuer');
|
|
const request = JSON.parse(req.requestBody);
|
|
assert.propEqual(
|
|
request,
|
|
{
|
|
pem_bundle: `${this.pemBundle}`,
|
|
},
|
|
'sends params in correct type'
|
|
);
|
|
return {
|
|
data: {
|
|
mapping: { 'issuer-id': 'key-id' },
|
|
},
|
|
};
|
|
});
|
|
|
|
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
|
|
|
|
await render(
|
|
hbs`
|
|
<PkiImportPemBundle
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
@onComplete={{this.onComplete}}
|
|
@adapterOptions={{hash actionType="import" useIssuer=true}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
|
|
await click('[data-test-text-toggle]');
|
|
await fillIn('[data-test-text-file-textarea]', this.pemBundle);
|
|
assert.strictEqual(this.model.pemBundle, this.pemBundle, 'PEM bundle updated on model');
|
|
await click('[data-test-pki-import-pem-bundle]');
|
|
});
|
|
|
|
test('it hits correct endpoint when userIssuer=false', async function (assert) {
|
|
assert.expect(4);
|
|
this.server.post(`${this.backend}/config/ca`, (schema, req) => {
|
|
assert.ok(true, 'Request made to the correct endpoint to import issuer');
|
|
const request = JSON.parse(req.requestBody);
|
|
assert.propEqual(
|
|
request,
|
|
{
|
|
pem_bundle: `${this.pemBundle}`,
|
|
},
|
|
'sends params in correct type'
|
|
);
|
|
return {
|
|
data: {
|
|
mapping: {},
|
|
},
|
|
};
|
|
});
|
|
|
|
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
|
|
|
|
await render(
|
|
hbs`
|
|
<PkiImportPemBundle
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
@onComplete={{this.onComplete}}
|
|
@adapterOptions={{hash actionType="import" useIssuer=false}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
|
|
await click('[data-test-text-toggle]');
|
|
await fillIn('[data-test-text-file-textarea]', this.pemBundle);
|
|
assert.strictEqual(this.model.pemBundle, this.pemBundle);
|
|
await click('[data-test-pki-import-pem-bundle]');
|
|
});
|
|
|
|
test('it shows the bundle mapping on success', async function (assert) {
|
|
assert.expect(9);
|
|
this.server.post(`/${this.backend}/issuers/import/bundle`, () => {
|
|
return {
|
|
data: {
|
|
imported_issuers: ['issuer-id', 'another-issuer'],
|
|
imported_keys: ['key-id', 'another-key'],
|
|
mapping: { 'issuer-id': 'key-id', 'another-issuer': null },
|
|
},
|
|
};
|
|
});
|
|
|
|
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
|
|
this.onComplete = () => assert.ok(true, 'onComplete callback fires on done button click');
|
|
|
|
await render(
|
|
hbs`
|
|
<PkiImportPemBundle
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
@onComplete={{this.onComplete}}
|
|
@adapterOptions={{hash actionType="import" useIssuer=true}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
|
|
await click('[data-test-text-toggle]');
|
|
await fillIn('[data-test-text-file-textarea]', this.pemBundle);
|
|
await click('[data-test-pki-import-pem-bundle]');
|
|
|
|
assert
|
|
.dom('[data-test-import-pair]')
|
|
.exists({ count: 3 }, 'Shows correct number of rows for imported items');
|
|
// Check that each row has expected values
|
|
assert.dom('[data-test-import-pair="issuer-id_key-id"] [data-test-imported-issuer]').hasText('issuer-id');
|
|
assert.dom('[data-test-import-pair="issuer-id_key-id"] [data-test-imported-key]').hasText('key-id');
|
|
assert
|
|
.dom('[data-test-import-pair="another-issuer_"] [data-test-imported-issuer]')
|
|
.hasText('another-issuer');
|
|
assert.dom('[data-test-import-pair="another-issuer_"] [data-test-imported-key]').hasText('None');
|
|
assert.dom('[data-test-import-pair="_another-key"] [data-test-imported-issuer]').hasText('None');
|
|
assert.dom('[data-test-import-pair="_another-key"] [data-test-imported-key]').hasText('another-key');
|
|
await click('[data-test-done]');
|
|
});
|
|
|
|
test('it should unload record on cancel', async function (assert) {
|
|
assert.expect(2);
|
|
this.onCancel = () => assert.ok(true, 'onCancel callback fires');
|
|
await render(
|
|
hbs`
|
|
<PkiImportPemBundle
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onComplete={{this.onComplete}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
|
|
await click('[data-test-pki-ca-cert-cancel]');
|
|
assert.true(this.model.isDestroyed, 'new model is unloaded on cancel');
|
|
});
|
|
});
|