Auth method token_type possibleValues fix (#19290)

* language by design

* fix issue with active class not doing anything on the LinkTo

* changelog

* noDefault instead of empty string

* test coverage

* update test descriptions

* address pr comments

* welp
This commit is contained in:
Angel Garbarino 2023-02-23 11:59:21 -07:00 committed by GitHub
parent 0a7656ae5c
commit ede0000843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 4 deletions

3
changelog/19290.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
ui: Remove `default` and add `default-service` and `default-batch` to UI token_type for auth mount and tuning.
```

View File

@ -26,7 +26,7 @@ export default AuthConfigComponent.extend({
const data = this.model.config.serialize();
data.description = this.model.description;
// token_type should not be tuneable for the token auth method, default is 'default-service'
// token_type should not be tuneable for the token auth method.
if (this.model.type === 'token') {
delete data.token_type;
}

View File

@ -52,9 +52,9 @@ export default class MountConfigModel extends Model {
@attr('string', {
label: 'Token Type',
helpText:
"The type of token that should be generated via this role. Can be `service`, `batch`, or `default` to use the mount's default (which unless changed will be `service` tokens).",
possibleValues: ['default', 'batch', 'service'],
defaultFormValue: 'default',
'The type of token that should be generated via this role. For `default-service` and `default-batch` service and batch tokens will be issued respectively, unless the auth method explicitly requests a different type.',
possibleValues: ['default-service', 'default-batch', 'batch', 'service'],
noDefault: true,
})
tokenType;
}

View File

@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { create } from 'ember-cli-page-object';
import { fillIn } from '@ember/test-helpers';
import enablePage from 'vault/tests/pages/settings/auth/enable';
import page from 'vault/tests/pages/settings/auth/configure/section';
import indexPage from 'vault/tests/pages/settings/auth/configure/index';
@ -29,6 +30,10 @@ module('Acceptance | settings/auth/configure/section', function (hooks) {
await enablePage.enable(type, path);
await page.visit({ path, section });
await page.fillInTextarea('description', 'This is AppRole!');
assert
.dom('[data-test-input="config.tokenType"]')
.hasValue('default-service', 'as default the token type selected is default-service.');
await fillIn('[data-test-input="config.tokenType"]', 'batch');
await page.save();
assert.strictEqual(
page.flash.latestMessage,
@ -40,8 +45,11 @@ module('Acceptance | settings/auth/configure/section', function (hooks) {
`/v1/sys/mounts/auth/${path}/tune`
)[0];
const keys = Object.keys(JSON.parse(tuneRequest.requestBody));
const token_type = JSON.parse(tuneRequest.requestBody).token_type;
assert.strictEqual(token_type, 'batch', 'passes new token type');
assert.ok(keys.includes('default_lease_ttl'), 'passes default_lease_ttl on tune');
assert.ok(keys.includes('max_lease_ttl'), 'passes max_lease_ttl on tune');
assert.ok(keys.includes('description'), 'passes updated description on tune');
});
for (const type of ['aws', 'azure', 'gcp', 'github', 'kubernetes']) {

View File

@ -82,6 +82,23 @@ module('Integration | Component | mount backend form', function (hooks) {
assert.strictEqual(component.pathValue, 'newpath', 'keeps custom path value');
});
test('it does not show a selected token type when first mounting an auth method', async function (assert) {
await render(
hbs`<MountBackendForm @mountModel={{this.model}} @onMountSuccess={{this.onMountSuccess}} />`
);
await component.selectType('github');
await component.next();
await component.toggleOptions();
assert
.dom('[data-test-input="config.tokenType"]')
.hasValue('', 'token type does not have a default value.');
const selectOptions = document.querySelector('[data-test-input="config.tokenType"]').options;
assert.strictEqual(selectOptions[1].text, 'default-service', 'first option is default-service');
assert.strictEqual(selectOptions[2].text, 'default-batch', 'second option is default-batch');
assert.strictEqual(selectOptions[3].text, 'batch', 'third option is batch');
assert.strictEqual(selectOptions[4].text, 'service', 'fourth option is service');
});
test('it calls mount success', async function (assert) {
assert.expect(3);