forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Secrets header version badge (hashicorp#13015)
* updates secret list header to display badge for all versions * adds changelog entry * updates secret list header to only show badge for kv and generic engine types * adds secret-engine mirage factory * adds test helper for pushing serialized mirage data into store and returning ember data models * adds secret engine type version badge display test * updates mirage application serializer to return singular type key
- Loading branch information
Showing
9 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui: Display badge for all versions in secrets engine header | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Factory } from 'ember-cli-mirage'; | ||
import faker from 'faker'; | ||
import { supportedSecretBackends } from 'vault/helpers/supported-secret-backends'; | ||
|
||
export default Factory.extend({ | ||
path: () => faker.system.directoryPath(), | ||
description: () => faker.git.commitMessage(), | ||
local: () => faker.datatype.boolean(), | ||
sealWrap: () => faker.datatype.boolean(), | ||
// set in afterCreate | ||
accessor: null, | ||
type: null, | ||
options: null, | ||
|
||
afterCreate(secretEngine) { | ||
if (!secretEngine.type) { | ||
const type = faker.random.arrayElement(supportedSecretBackends()); | ||
secretEngine.type = type; | ||
|
||
if (!secretEngine.accessor) { | ||
secretEngine.accessor = `type_${faker.git.shortSha()}`; | ||
} | ||
} | ||
|
||
if (!secretEngine.options && ['generic', 'kv'].includes(secretEngine.type)) { | ||
secretEngine.options = { | ||
version: faker.random.arrayElement('1', '2'), | ||
}; | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { JSONAPISerializer } from 'ember-cli-mirage'; | ||
|
||
export default JSONAPISerializer.extend({}); | ||
export default JSONAPISerializer.extend({ | ||
typeKeyForModel(model) { | ||
return model.modelName; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getContext } from '@ember/test-helpers'; | ||
|
||
export default data => { | ||
const context = getContext(); | ||
const store = context.owner.lookup('service:store'); | ||
const modelName = Array.isArray(data) ? data[0].modelName : data.modelName; | ||
const json = context.server.serializerOrRegistry.serialize(data); | ||
store.push(json); | ||
return Array.isArray(data) | ||
? data.map(({ id }) => store.peekRecord(modelName, id)) | ||
: store.peekRecord(modelName, data.id); | ||
}; |
40 changes: 40 additions & 0 deletions
40
ui/tests/integration/components/secret-list-header-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { supportedSecretBackends } from 'vault/helpers/supported-secret-backends'; | ||
import { setupMirage } from 'ember-cli-mirage/test-support'; | ||
import mirageToModels from 'vault/tests/helpers/mirage-to-models'; | ||
|
||
module('Integration | Component | secret-list-header', function(hooks) { | ||
setupRenderingTest(hooks); | ||
setupMirage(hooks); | ||
|
||
test('it should render version badge for kv and generic engine types', async function(assert) { | ||
const backends = supportedSecretBackends(); | ||
assert.expect(backends.length); | ||
|
||
this.server.post('/sys/capabilities-self', () => {}); | ||
|
||
for (let type of backends) { | ||
const data = this.server.create('secret-engine', 2, { type }); | ||
this.model = mirageToModels(data); | ||
await render(hbs` | ||
<SecretListHeader | ||
@model={{this.model}} | ||
/> | ||
`); | ||
const selector = '[data-test-kv-version-badge]'; | ||
if (['kv', 'generic'].includes(type)) { | ||
assert | ||
.dom(selector) | ||
.hasText( | ||
`Version ${this.model.options.version}`, | ||
`Badge renders with correct version for ${type} engine type` | ||
); | ||
} else { | ||
assert.dom(selector).doesNotExist(`Version badge does not render for ${type} engine type`); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters