mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 04:16:31 +02:00
* removes store query from pki config route * updates pki overview route to use api service * removes remaining references to store in pki tests * removes unused store service injections in pki components * removes store dependency from pki engine * removes ember data related unit tests for pki * removes pki ember data models, adapters and serializers * removes unused pagination service injections in config-ui, kv, pki and sync engines * removes unused store service injections from pki engine * updates dashboard quick-actions-card component to fetch options using api service * removes path-help test using pki model Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
107 lines
3.3 KiB
JavaScript
107 lines
3.3 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2016, 2025
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import Sinon from 'sinon';
|
|
import { reject } from 'rsvp';
|
|
|
|
const openapiStub = {
|
|
openapi: {
|
|
components: {
|
|
schemas: {
|
|
UsersRequest: {
|
|
type: 'object',
|
|
properties: {
|
|
password: {
|
|
description: 'Password for the user',
|
|
type: 'string',
|
|
'x-vault-displayAttrs': { sensitive: true },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
paths: {
|
|
'/users/{username}': {
|
|
post: {
|
|
requestBody: {
|
|
content: {
|
|
'application/json': {
|
|
schema: { $ref: '#/components/schemas/UsersRequest' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
parameters: [
|
|
{
|
|
description: 'Username for this user.',
|
|
in: 'path',
|
|
name: 'username',
|
|
required: true,
|
|
schema: { type: 'string' },
|
|
},
|
|
],
|
|
'x-vault-displayAttrs': { itemType: 'User', action: 'Create' },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
module('Unit | Service | path-help', function (hooks) {
|
|
setupTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.pathHelp = this.owner.lookup('service:path-help');
|
|
this.store = this.owner.lookup('service:store');
|
|
});
|
|
|
|
module('getNewModel', function (hooks) {
|
|
hooks.beforeEach(function () {
|
|
this.server.get('/auth/userpass/', () => openapiStub);
|
|
this.server.get('/auth/userpass/users/example', () => openapiStub);
|
|
});
|
|
test('it generates a model with mutableId', async function (assert) {
|
|
assert.expect(2);
|
|
this.server.post('/auth/userpass/users/test', () => {
|
|
assert.true(true, 'POST request made to correct endpoint');
|
|
return;
|
|
});
|
|
|
|
const modelType = 'generated-user-userpass';
|
|
await this.pathHelp.getNewModel(modelType, 'userpass', 'auth/userpass/', 'user');
|
|
const model = this.store.createRecord(modelType);
|
|
model.set('mutableId', 'test');
|
|
await model.save();
|
|
assert.strictEqual(model.get('id'), 'test', 'model id is set to mutableId value on save success');
|
|
});
|
|
|
|
test('it only generates the model once', async function (assert) {
|
|
assert.expect(2);
|
|
Sinon.spy(this.pathHelp, 'getPaths');
|
|
|
|
const modelType = 'generated-user-userpass';
|
|
await this.pathHelp.getNewModel(modelType, 'userpass', 'auth/userpass/', 'user');
|
|
assert.true(this.pathHelp.getPaths.calledOnce, 'getPaths is called for new generated model');
|
|
|
|
await this.pathHelp.getNewModel(modelType, 'userpass2', 'auth/userpass/', 'user');
|
|
assert.true(this.pathHelp.getPaths.calledOnce, 'not called again even with different backend path');
|
|
});
|
|
|
|
test('it resolves without error if model already exists', async function (assert) {
|
|
Sinon.stub(this.pathHelp, 'getPaths').callsFake(() => {
|
|
assert.notOk(true, 'this method should not be called');
|
|
return reject();
|
|
});
|
|
const modelType = 'totp-key';
|
|
await this.pathHelp.getNewModel(modelType, 'my-kv').then(() => {
|
|
assert.true(true, 'getNewModel resolves');
|
|
});
|
|
});
|
|
});
|
|
});
|