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',
|
|
|
|
'ttl',
|
|
|
|
'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'],
|
|
|
|
dynamicRoleFields: ['creation_statement', 'ttl', 'max_ttl'],
|
|
|
|
},
|
2021-04-14 21:07:07 +00:00
|
|
|
{
|
|
|
|
pluginType: 'mongodb-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
|
|
|
dynamicRoleFields: ['creation_statement', 'revocation_statement', 'ttl', 'max_ttl'],
|
|
|
|
statementsHidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mssql-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'ttl', 'max_ttl'],
|
|
|
|
},
|
2021-05-06 18:22:40 +00:00
|
|
|
{
|
|
|
|
pluginType: 'mysql-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'ttl', 'max_ttl'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mysql-aurora-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'ttl', 'max_ttl'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mysql-rds-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'ttl', 'max_ttl'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pluginType: 'mysql-legacy-database-plugin',
|
|
|
|
staticRoleFields: ['username', 'rotation_period'],
|
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'ttl', 'max_ttl'],
|
|
|
|
},
|
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'],
|
|
|
|
dynamicRoleFields: ['creation_statements', 'revocation_statements', 'ttl', 'max_ttl'],
|
|
|
|
},
|
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 = [
|
|
|
|
{ name: 'ttl', type: 'string', options: {} },
|
|
|
|
{ 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
|
|
|
];
|
|
|
|
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);
|
|
|
|
return { show, hide };
|
|
|
|
};
|
|
|
|
|
|
|
|
module('Integration | Component | database-role-setting-form', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
|
|
|
this.set(
|
|
|
|
'model',
|
|
|
|
EmberObject.create({
|
|
|
|
// attrs is not its own set value b/c ember hates arrays as args
|
|
|
|
attrs: ALL_ATTRS,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it shows empty states when no roleType passed in', async function(assert) {
|
|
|
|
await render(hbs`<DatabaseRoleSettingForm @attrs={{model.attrs}} @model={{model}}/>`);
|
|
|
|
assert.dom('[data-test-component="empty-state"]').exists({ count: 2 }, 'Two empty states exist');
|
|
|
|
});
|
|
|
|
|
2021-04-14 21:07:07 +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
|
|
|
|
@attrs={{model.attrs}}
|
|
|
|
@model={{model}}
|
|
|
|
@roleType={{roleType}}
|
|
|
|
@dbType={{dbType}}
|
|
|
|
/>
|
|
|
|
`);
|
|
|
|
assert.dom('[data-test-component="empty-state"]').doesNotExist('Does not show empty states');
|
2021-04-14 21:07:07 +00:00
|
|
|
for (let testCase of testCases) {
|
|
|
|
let staticFields = getFields(testCase.staticRoleFields);
|
|
|
|
let dynamicFields = getFields(testCase.dynamicRoleFields);
|
|
|
|
this.set('dbType', testCase.pluginType);
|
|
|
|
this.set('roleType', 'static');
|
|
|
|
staticFields.show.forEach(attr => {
|
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.exists(
|
|
|
|
`${attr.name} attribute exists on static role for ${testCase.pluginType || 'default'} db type`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
staticFields.hide.forEach(attr => {
|
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.doesNotExist(
|
|
|
|
`${attr.name} attribute does not exist on static role for ${testCase.pluginType ||
|
|
|
|
'default'} db type`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
if (testCase.statementsHidden) {
|
|
|
|
assert
|
|
|
|
.dom('[data-test-statements-section]')
|
|
|
|
.doesNotExist(`Statements section is hidden for static ${testCase.pluginType} role`);
|
|
|
|
}
|
|
|
|
this.set('roleType', 'dynamic');
|
|
|
|
dynamicFields.show.forEach(attr => {
|
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.exists(
|
|
|
|
`${attr.name} attribute exists on dynamic role for ${testCase.pluginType || 'default'} db type`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
dynamicFields.hide.forEach(attr => {
|
|
|
|
assert
|
|
|
|
.dom(`[data-test-input="${attr.name}"]`)
|
|
|
|
.doesNotExist(
|
|
|
|
`${attr.name} attribute does not exist on dynamic role for ${testCase.pluginType ||
|
|
|
|
'default'} db type`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2021-03-01 18:52:46 +00:00
|
|
|
});
|
|
|
|
});
|