-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI/vault 9268/pki component tests (#17609)
* wip * work in progress * pki-role-form-test * clean up * radio-select-ttl-or-string test * clean up * add yielded check * 12 to 13 * add pki-key-usage test * remove meep * key-params test * clean up * clean up * pr comments
- Loading branch information
1 parent
de848b0
commit bfde310
Showing
13 changed files
with
448 additions
and
12 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
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
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
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,30 @@ | ||
export const PKI_BASE_URL = `/vault/cluster/secrets/backend/pki/roles`; | ||
|
||
export const SELECTORS = { | ||
// Pki role | ||
roleName: '[data-test-input="name"]', | ||
issuerRef: '[data-test-input="issuerRef"]', | ||
customTtl: '[data-test-field="customTtl"]', | ||
backdateValidity: '[data-test-ttl-value="Backdate validity"]', | ||
maxTtl: '[data-test-toggle-label="Max TTL"]', | ||
generateLease: '[data-test-field="generateLease"]', | ||
noStore: '[data-test-field="noStore"]', | ||
addBasicConstraints: '[data-test-input="addBasicConstraints"]', | ||
domainHandling: '[data-test-toggle-group="Domain handling"]', | ||
keyParams: '[data-test-toggle-group="Key parameters"]', | ||
keyType: '[data-test-input="keyType"]', | ||
keyBits: '[data-test-input="keyBits"]', | ||
signatureBits: '[data-test-input="signatureBits"]', | ||
keyUsage: '[data-test-toggle-group="Key usage"]', | ||
extKeyUsageOids: '[data-test-input="extKeyUsageOids"]', | ||
digitalSignature: '[data-test-input="DigitalSignature"]', | ||
keyAgreement: '[data-test-input="KeyAgreement"]', | ||
keyEncipherment: '[data-test-input="KeyEncipherment"]', | ||
any: '[data-test-input="Any"]', | ||
serverAuth: '[data-test-input="ServerAuth"]', | ||
policyIdentifiers: '[data-test-toggle-group="Policy identifiers"]', | ||
san: '[data-test-toggle-group="Subject Alternative Name (SAN) Options"]', | ||
additionalSubjectFields: '[data-test-toggle-group="Additional subject fields"]', | ||
roleCreateButton: '[data-test-pki-role-save]', | ||
roleCancelButton: '[data-test-pki-role-cancel]', | ||
}; |
101 changes: 101 additions & 0 deletions
101
ui/tests/integration/components/pki/pki-key-parameters-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,101 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, click, fillIn } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { setupEngine } from 'ember-engines/test-support'; | ||
import { SELECTORS } from 'vault/tests/helpers/pki-engine'; | ||
|
||
module('Integration | Component | pki-key-parameters', function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupEngine(hooks, 'pki'); | ||
|
||
hooks.beforeEach(function () { | ||
this.store = this.owner.lookup('service:store'); | ||
this.model = this.store.createRecord('pki/pki-role-engine'); | ||
this.model.backend = 'pki'; | ||
}); | ||
|
||
test('it should render the component and display the correct defaults', async function (assert) { | ||
assert.expect(3); | ||
await render( | ||
hbs` | ||
<div class="has-top-margin-xxl"> | ||
<PkiKeyParameters | ||
@model={{this.model}} | ||
@group="Key parameters" | ||
/> | ||
</div> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
await click(SELECTORS.keyParams); | ||
assert.dom(SELECTORS.keyType).hasValue('rsa'); | ||
assert.dom(SELECTORS.keyBits).hasValue('2048'); | ||
assert.dom(SELECTORS.signatureBits).hasValue('0'); | ||
}); | ||
|
||
test('it should set the model properties of key_type and key_bits when key_type changes', async function (assert) { | ||
assert.expect(11); | ||
await render( | ||
hbs` | ||
<div class="has-top-margin-xxl"> | ||
<PkiKeyParameters | ||
@model={{this.model}} | ||
@group="Key parameters" | ||
/> | ||
</div> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
assert.strictEqual(this.model.keyType, 'rsa', 'sets the default value for key_type on the model.'); | ||
assert.strictEqual(this.model.keyBits, 2048, 'sets the default value for key_bits on the model.'); | ||
assert.strictEqual( | ||
this.model.signatureBits, | ||
0, | ||
'sets the default value for signature_bits on the model.' | ||
); | ||
await click(SELECTORS.keyParams); | ||
await fillIn(SELECTORS.keyType, 'ec'); | ||
assert.strictEqual(this.model.keyType, 'ec', 'sets the new selected value for key_type on the model.'); | ||
assert.strictEqual( | ||
this.model.keyBits, | ||
256, | ||
'sets the new selected value for key_bits on the model based on the selection of key_type.' | ||
); | ||
|
||
await fillIn(SELECTORS.keyType, 'ed25519'); | ||
assert.strictEqual( | ||
this.model.keyType, | ||
'ed25519', | ||
'sets the new selected value for key_type on the model.' | ||
); | ||
assert.strictEqual( | ||
this.model.keyBits, | ||
0, | ||
'sets the new selected value for key_bits on the model based on the selection of key_type.' | ||
); | ||
|
||
await fillIn(SELECTORS.keyType, 'ec'); | ||
await fillIn(SELECTORS.keyBits, 384); | ||
assert.strictEqual(this.model.keyType, 'ec', 'sets the new selected value for key_type on the model.'); | ||
assert.strictEqual( | ||
this.model.keyBits, | ||
384, | ||
'sets the new selected value for key_bits on the model based on the selection of key_type.' | ||
); | ||
|
||
await fillIn(SELECTORS.signatureBits, '384'); | ||
assert.strictEqual( | ||
this.model.signatureBits, | ||
384, | ||
'sets the new selected value for signature_bits on the model.' | ||
); | ||
|
||
await fillIn(SELECTORS.signatureBits, '0'); | ||
assert.strictEqual( | ||
this.model.signatureBits, | ||
0, | ||
'sets the default value for signature_bits on the model.' | ||
); | ||
}); | ||
}); |
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,85 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, click, findAll } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { setupEngine } from 'ember-engines/test-support'; | ||
import { SELECTORS } from 'vault/tests/helpers/pki-engine'; | ||
|
||
module('Integration | Component | pki-key-usage', function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupEngine(hooks, 'pki'); | ||
|
||
hooks.beforeEach(function () { | ||
this.store = this.owner.lookup('service:store'); | ||
this.model = this.store.createRecord('pki/pki-role-engine'); | ||
this.model.backend = 'pki'; | ||
}); | ||
|
||
test('it should render the component', async function (assert) { | ||
assert.expect(7); | ||
await render( | ||
hbs` | ||
<div class="has-top-margin-xxl"> | ||
<PkiKeyUsage | ||
@model={{this.model}} | ||
@group="Key usage" | ||
/> | ||
</div> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
await click(SELECTORS.keyUsage); | ||
assert.strictEqual(findAll('.b-checkbox').length, 19, 'it render 19 checkboxes'); | ||
assert.dom(SELECTORS.digitalSignature).isChecked('Digital Signature is true by default'); | ||
assert.dom(SELECTORS.keyAgreement).isChecked('Key Agreement is true by default'); | ||
assert.dom(SELECTORS.keyEncipherment).isChecked('Key Encipherment is true by default'); | ||
assert.dom(SELECTORS.any).isNotChecked('Any is false by default'); | ||
assert.dom(SELECTORS.extKeyUsageOids).exists('Extended Key usage oids renders'); | ||
|
||
// check is flexbox by checking the height of the box | ||
let groupBoxHeight = document.querySelector('[data-test-surrounding-div="Key usage"]').clientHeight; | ||
assert.strictEqual( | ||
groupBoxHeight, | ||
518, | ||
'renders the correct height of the box element if the component is rending as a flexbox' | ||
); | ||
}); | ||
|
||
test('it should set the model properties of key_usage and ext_key_usage based on the checkbox selections', async function (assert) { | ||
assert.expect(4); | ||
await render( | ||
hbs` | ||
<div class="has-top-margin-xxl"> | ||
<PkiKeyUsage | ||
@model={{this.model}} | ||
@group="Key usage" | ||
/> | ||
</div> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
// See PKI API docs https://developer.hashicorp.com/vault/api-docs/secret/pki#key_usage | ||
assert.deepEqual( | ||
this.model.keyUsage, | ||
['DigitalSignature', 'KeyAgreement', 'KeyEncipherment'], | ||
'sets the default values for key_usage on the model.' | ||
); | ||
assert.strictEqual( | ||
this.model.extKeyUsage, | ||
undefined, | ||
'sets no default value set for ext_key_usage on load.' | ||
); | ||
|
||
await click(SELECTORS.keyUsage); | ||
await click(SELECTORS.digitalSignature); | ||
await click(SELECTORS.any); | ||
await click(SELECTORS.serverAuth); | ||
|
||
assert.deepEqual( | ||
this.model.keyUsage, | ||
['KeyAgreement', 'KeyEncipherment'], | ||
'removes digitalSignature from the model when unchecked.' | ||
); | ||
assert.deepEqual(this.model.extKeyUsage, ['Any', 'ServerAuth'], 'adds new checkboxes to when checked'); | ||
}); | ||
}); |
Oops, something went wrong.