open-vault/ui/tests/unit/utils/openapi-to-attrs-test.js
Madalyn 977af116c8 Enable generated items for more auth methods (#7513)
* enable auth method item configuration in go code

* properly parse and list generated items

* make sure we only set name on attrs if a label comes from openAPI

* correctly construct paths object for method index route

* set sensitive property on password for userpass

* remove debugger statements

* pass method model to list route template to use paths on model for tabs

* update tab generation in generated item list, undo enabling userpass users

* enable openapi generated itams for certs and userpass, update ldap to no longer have action on list endpoint

* add editType to DisplayAttributes, pull tokenutil fields into field group

* show sensitive message for sensitive fields displayed in fieldGroupShow component

* grab sensitive and editType fields from displayAttrs in openapi-to-attrs util

* make sure we don't ask for paths for secret backends since that isn't setup yet

* fix styling of sensitive text for fieldGroupShow component

* update openapi-to-attrs util test to no longer include label by default, change debugger to console.err in path-help, remove dynamic ui auth methods from tab count test

* properly log errors to the console

* capitalize This value is sensitive...

* get rid of extra padding on bottom of fieldgroupshow

* make auth methods clickable and use new confirm ux

* Update sdk/framework/path.go

Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>

* Update sdk/framework/path.go

Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>

* add whitespace

* return intErr instead of err

* uncomment out helpUrl because we need it

* remove extra box class

* use const instead of let

* remove extra conditional since we already split the pathName later on

* ensure we request the correct url when listing generated items

* use const

* link to list and show pages

* remove dead code

* show nested item name instead of id

* add comments

* show tooltip for text-file inputs

* fix storybook

* remove extra filter

* add TODOs

* add comments

* comment out unused variables but leave them in function signature

* only link to auth methods that can be fully managed in the ui

* clean up comments

* only render tooltip if there is helpText

* rename id authMethodPath

* remove optionsForQuery since we don't need it

* add indentation

* standardize ConfirmMessage and show model name instead of id when editing

* standardize ConfirmMessage and show model name instead of id when editing

* add comments

* post to the correct updateUrl so we can edit users and groups

* use pop instead of slice

* add TODO for finding a better way to store ids

* ensure ids are handled the same way on list and show pages; fix editing and deleting

* add comment about difference between list and show urls

* use model.id instead of name since we do not need it

* remove dead code

* ensure list pages have page headers

* standardize using authMethodPath instead of method and remove dead code

* i love indentation

* remove more dead code

* use new Confirm

* show correct flash message when deleting an item

* update flash message for creating and updating

* use plus icon for creating group/user instead of an arrow
2019-10-17 16:19:14 -07:00

224 lines
5.8 KiB
JavaScript

import { expandOpenApiProps, combineAttributes, combineFieldGroups } from 'vault/utils/openapi-to-attrs';
import { module, test } from 'qunit';
import DS from 'ember-data';
const { attr } = DS;
module('Unit | Util | OpenAPI Data Utilities', function() {
const OPENAPI_RESPONSE_PROPS = {
ttl: {
type: 'string',
format: 'seconds',
description: 'this is a TTL!',
'x-vault-displayAttrs': {
name: 'TTL',
},
},
'awesome-people': {
type: 'array',
items: {
type: 'string',
},
'x-vault-displayAttrs': {
value: 'Grace Hopper,Lady Ada',
},
},
'favorite-ice-cream': {
type: 'string',
enum: ['vanilla', 'chocolate', 'strawberry'],
},
'default-value': {
default: 30,
'x-vault-displayAttrs': {
value: 300,
},
type: 'integer',
},
default: {
'x-vault-displayAttrs': {
value: 30,
},
type: 'integer',
},
'super-secret': {
type: 'string',
'x-vault-displayAttrs': {
sensitive: true,
},
description: 'A really secret thing',
},
};
const EXPANDED_PROPS = {
ttl: {
helpText: 'this is a TTL!',
editType: 'ttl',
label: 'TTL',
fieldGroup: 'default',
},
awesomePeople: {
editType: 'stringArray',
defaultValue: 'Grace Hopper,Lady Ada',
fieldGroup: 'default',
},
favoriteIceCream: {
editType: 'string',
type: 'string',
possibleValues: ['vanilla', 'chocolate', 'strawberry'],
fieldGroup: 'default',
},
defaultValue: {
editType: 'number',
type: 'number',
defaultValue: 300,
fieldGroup: 'default',
},
default: {
editType: 'number',
type: 'number',
defaultValue: 30,
fieldGroup: 'default',
},
superSecret: {
type: 'string',
editType: 'string',
sensitive: true,
helpText: 'A really secret thing',
fieldGroup: 'default',
},
};
const EXISTING_MODEL_ATTRS = [
{
key: 'name',
value: {
isAttribute: true,
name: 'name',
options: {
editType: 'string',
label: 'Role name',
},
},
},
{
key: 'awesomePeople',
value: {
isAttribute: true,
name: 'awesomePeople',
options: {
label: 'People Who Are Awesome',
},
},
},
];
const COMBINED_ATTRS = {
name: attr('string', {
editType: 'string',
type: 'string',
label: 'Role name',
}),
ttl: attr('string', {
editType: 'ttl',
label: 'TTL',
helpText: 'this is a TTL!',
}),
awesomePeople: attr({
label: 'People Who Are Awesome',
editType: 'stringArray',
defaultValue: 'Grace Hopper,Lady Ada',
}),
favoriteIceCream: attr('string', {
type: 'string',
editType: 'string',
possibleValues: ['vanilla', 'chocolate', 'strawberry'],
}),
superSecret: attr('string', {
type: 'string',
editType: 'string',
sensitive: true,
description: 'A really secret thing',
}),
};
const NEW_FIELDS = ['one', 'two', 'three'];
test('it creates objects from OpenAPI schema props', function(assert) {
const generatedProps = expandOpenApiProps(OPENAPI_RESPONSE_PROPS);
for (let propName in EXPANDED_PROPS) {
assert.deepEqual(EXPANDED_PROPS[propName], generatedProps[propName], `correctly expands ${propName}`);
}
});
test('it combines OpenAPI props with existing model attrs', function(assert) {
const combined = combineAttributes(EXISTING_MODEL_ATTRS, EXPANDED_PROPS);
for (let propName in EXISTING_MODEL_ATTRS) {
assert.deepEqual(COMBINED_ATTRS[propName], combined[propName]);
}
});
test('it adds new fields from OpenAPI to fieldGroups except for exclusions', function(assert) {
let modelFieldGroups = [
{ default: ['name', 'awesomePeople'] },
{
Options: ['ttl'],
},
];
const excludedFields = ['two'];
const expectedGroups = [
{ default: ['name', 'awesomePeople', 'one', 'three'] },
{
Options: ['ttl'],
},
];
const newFieldGroups = combineFieldGroups(modelFieldGroups, NEW_FIELDS, excludedFields);
for (let groupName in modelFieldGroups) {
assert.deepEqual(
newFieldGroups[groupName],
expectedGroups[groupName],
'it incorporates all new fields except for those excluded'
);
}
});
test('it adds all new fields from OpenAPI to fieldGroups when excludedFields is empty', function(assert) {
let modelFieldGroups = [
{ default: ['name', 'awesomePeople'] },
{
Options: ['ttl'],
},
];
const excludedFields = [];
const expectedGroups = [
{ default: ['name', 'awesomePeople', 'one', 'two', 'three'] },
{
Options: ['ttl'],
},
];
const nonExcludedFieldGroups = combineFieldGroups(modelFieldGroups, NEW_FIELDS, excludedFields);
for (let groupName in modelFieldGroups) {
assert.deepEqual(
nonExcludedFieldGroups[groupName],
expectedGroups[groupName],
'it incorporates all new fields'
);
}
});
test('it keeps fields the same when there are no brand new fields from OpenAPI', function(assert) {
let modelFieldGroups = [
{ default: ['name', 'awesomePeople', 'two', 'one', 'three'] },
{
Options: ['ttl'],
},
];
const excludedFields = [];
const expectedGroups = [
{ default: ['name', 'awesomePeople', 'two', 'one', 'three'] },
{
Options: ['ttl'],
},
];
const fieldGroups = combineFieldGroups(modelFieldGroups, NEW_FIELDS, excludedFields);
for (let groupName in modelFieldGroups) {
assert.deepEqual(fieldGroups[groupName], expectedGroups[groupName], 'it incorporates all new fields');
}
});
});