2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-03-01 18:52:46 +00:00
|
|
|
import EmberObject from '@ember/object';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
2021-04-14 21:07:07 +00:00
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
// default case should show all possible fields for each type
|
|
|
|
pluginType: '',
|
|
|
|
staticRoleFields: ['name', 'username', 'rotation_period', 'rotation_statements'],
|
|
|
|
dynamicRoleFields: [
|
|
|
|
'name',
|
2022-02-23 16:00:20 +00:00
|
|
|
'default_ttl',
|
2021-04-14 21:07:07 +00:00
|
|
|
'max_ttl',
|
|
|
|
'creation_statements',
|
|
|
|
'revocation_statements',
|
|
|
|
'rollback_statements',
|
|
|
|
'renew_statements',
|
|
|
|
],
|
|
|
|
},
|
2021-10-07 21:00:42 +00:00
|
|
|
{
|
|
|
|
pluginType: 'elasticsearch-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statement', 'default_ttl', 'max_ttl'],
|
2021-10-07 21:00:42 +00:00
|
|
|
},
|
2021-04-14 21:07:07 +00:00
|
|
|
{
|
|
|
|
pluginType: 'mongodb-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statement', 'revocation_statement', 'default_ttl', 'max_ttl'],
|
2021-04-14 21:07:07 +00:00
|
|
|
statementsHidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mssql-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'default_ttl', 'max_ttl'],
|
2021-04-14 21:07:07 +00:00
|
|
|
},
|
2021-05-06 18:22:40 +00:00
|
|
|
{
|
|
|
|
pluginType: 'mysql-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'default_ttl', 'max_ttl'],
|
2021-05-06 18:22:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mysql-aurora-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'default_ttl', 'max_ttl'],
|
2021-05-06 18:22:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mysql-rds-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'default_ttl', 'max_ttl'],
|
2021-05-06 18:22:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mysql-legacy-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'default_ttl', 'max_ttl'],
|
2021-05-06 18:22:40 +00:00
|
|
|
},
|
2021-10-11 16:20:23 +00:00
|
|
|
{
|
2021-11-10 22:20:36 +00:00
|
|
|
pluginType: 'vault-plugin-database-oracle',
|
2021-10-11 16:20:23 +00:00
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
2022-02-23 16:00:20 +00:00
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'default_ttl', 'max_ttl'],
|
2021-10-11 16:20:23 +00:00
|
|
|
},
|
2021-03-01 18:52:46 +00:00
|
|
|
];
|
2021-04-14 21:07:07 +00:00
|
|
|
|
|
|
|
// used to calculate checks that fields do NOT show up
|
2021-03-01 18:52:46 +00:00
|
|
|
const ALL_ATTRS = [
|
2022-02-23 16:00:20 +00:00
|
|
|
{ name: 'default_ttl', type: 'string', options: {} },
|
2021-03-01 18:52:46 +00:00
|
|
|
{ name: 'max_ttl', type: 'string', options: {} },
|
|
|
|
{ name: 'username', type: 'string', options: {} },
|
|
|
|
{ name: 'rotation_period', type: 'string', options: {} },
|
|
|
|
{ name: 'creation_statements', type: 'string', options: {} },
|
|
|
|
{ name: 'creation_statement', type: 'string', options: {} },
|
|
|
|
{ name: 'revocation_statements', type: 'string', options: {} },
|
|
|
|
{ name: 'revocation_statement', type: 'string', options: {} },
|
|
|
|
{ name: 'rotation_statements', type: 'string', options: {} },
|
2021-04-14 21:07:07 +00:00
|
|
|
{ name: 'rollback_statements', type: 'string', options: {} },
|
|
|
|
{ name: 'renew_statements', type: 'string', options: {} },
|
2021-03-01 18:52:46 +00:00
|
|
|
];
|
2021-12-17 03:44:29 +00:00
|
|
|
const getFields = (nameArray) => {
|
|
|
|
const show = ALL_ATTRS.filter((attr) => nameArray.indexOf(attr.name) >= 0);
|
|
|
|
const hide = ALL_ATTRS.filter((attr) => nameArray.indexOf(attr.name) < 0);
|
2021-03-01 18:52:46 +00:00
|
|
|
return { show, hide };
|
|
|
|
};
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | database-role-setting-form', function (hooks) {
|
2021-03-01 18:52:46 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2021-03-01 18:52:46 +00:00
|
|
|
this.set(
|
|
|
|
'model',
|
|
|
|
EmberObject.create({
|
|
|
|
// attrs is not its own set value b/c ember hates arrays as args
|
|
|
|
attrs: ALL_ATTRS,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it shows empty states when no roleType passed in', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<DatabaseRoleSettingForm @attrs={{this.model.attrs}} @model={{this.model}}/>`);
|
2021-03-01 18:52:46 +00:00
|
|
|
assert.dom('[data-test-component="empty-state"]').exists({ count: 2 }, 'Two empty states exist');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it shows appropriate fields based on roleType and db plugin', async function (assert) {
|
2021-03-01 18:52:46 +00:00
|
|
|
this.set('roleType', 'static');
|
|
|
|
this.set('dbType', '');
|
|
|
|
await render(hbs`
|
|
|
|
<DatabaseRoleSettingForm
|
2022-10-18 15:46:02 +00:00
|
|
|
@attrs={{this.model.attrs}}
|
|
|
|
@model={{this.model}}
|
|
|
|
@roleType={{this.roleType}}
|
|
|
|
@dbType={{this.dbType}}
|
2021-03-01 18:52:46 +00:00
|
|
|
/>
|
|
|
|
`);
|
|
|
|
assert.dom('[data-test-component="empty-state"]').doesNotExist('Does not show empty states');
|
2022-11-09 23:15:31 +00:00
|
|
|
for (const testCase of testCases) {
|
|
|
|
const staticFields = getFields(testCase.staticRoleFields);
|
|
|
|
const dynamicFields = getFields(testCase.dynamicRoleFields);
|
2021-04-14 21:07:07 +00:00
|
|
|
this.set('dbType', testCase.pluginType);
|
|
|
|
this.set('roleType', 'static');
|
2021-12-17 03:44:29 +00:00
|
|
|
staticFields.show.forEach((attr) => {
|
2021-04-14 21:07:07 +00:00
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.exists(
|
|
|
|
`${attr.name} attribute exists on static role for ${testCase.pluginType || 'default'} db type`
|
|
|
|
);
|
|
|
|
});
|
2021-12-17 03:44:29 +00:00
|
|
|
staticFields.hide.forEach((attr) => {
|
2021-04-14 21:07:07 +00:00
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.doesNotExist(
|
2021-12-17 03:44:29 +00:00
|
|
|
`${attr.name} attribute does not exist on static role for ${
|
|
|
|
testCase.pluginType || 'default'
|
|
|
|
} db type`
|
2021-04-14 21:07:07 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
if (testCase.statementsHidden) {
|
|
|
|
assert
|
|
|
|
.dom('[data-test-statements-section]')
|
|
|
|
.doesNotExist(`Statements section is hidden for static ${testCase.pluginType} role`);
|
|
|
|
}
|
|
|
|
this.set('roleType', 'dynamic');
|
2021-12-17 03:44:29 +00:00
|
|
|
dynamicFields.show.forEach((attr) => {
|
2021-04-14 21:07:07 +00:00
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.exists(
|
|
|
|
`${attr.name} attribute exists on dynamic role for ${testCase.pluginType || 'default'} db type`
|
|
|
|
);
|
|
|
|
});
|
2021-12-17 03:44:29 +00:00
|
|
|
dynamicFields.hide.forEach((attr) => {
|
2021-04-14 21:07:07 +00:00
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.doesNotExist(
|
2021-12-17 03:44:29 +00:00
|
|
|
`${attr.name} attribute does not exist on dynamic role for ${
|
|
|
|
testCase.pluginType || 'default'
|
|
|
|
} db type`
|
2021-04-14 21:07:07 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2021-03-01 18:52:46 +00:00
|
|
|
});
|
|
|
|
});
|