UI unauthed auth methods fix (#5113)

* lowercase auth method type so that hardcoded and unauthed methods both use the same key

* don't rely on top level data for capabilities serializer
This commit is contained in:
Matthew Irish 2018-08-16 08:16:24 -05:00 committed by GitHub
parent 0941c7a24a
commit 129494d98a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 14 deletions

View File

@ -3,6 +3,7 @@ import Ember from 'ember';
const SUPPORTED_AUTH_BACKENDS = [
{
type: 'token',
typeDisplay: 'Token',
description: 'Token authentication.',
tokenPath: 'id',
displayNamePath: 'display_name',
@ -10,27 +11,31 @@ const SUPPORTED_AUTH_BACKENDS = [
},
{
type: 'userpass',
typeDisplay: 'Username',
description: 'A simple username and password backend.',
tokenPath: 'client_token',
displayNamePath: 'metadata.username',
formAttributes: ['username', 'password'],
},
{
type: 'LDAP',
type: 'ldap',
typeDisplay: 'LDAP',
description: 'LDAP authentication.',
tokenPath: 'client_token',
displayNamePath: 'metadata.username',
formAttributes: ['username', 'password'],
},
{
type: 'Okta',
type: 'okta',
typeDisplay: 'Okta',
description: 'Authenticate with your Okta username and password.',
tokenPath: 'client_token',
displayNamePath: 'metadata.username',
formAttributes: ['username', 'password'],
},
{
type: 'GitHub',
type: 'github',
typeDisplay: 'GitHub',
description: 'GitHub authentication.',
tokenPath: 'client_token',
displayNamePath: ['metadata.org', 'metadata.username'],

View File

@ -1,6 +1,6 @@
import DS from 'ember-data';
import ApplicationSerializer from './application';
export default DS.RESTSerializer.extend({
export default ApplicationSerializer.extend({
primaryKey: 'path',
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
@ -8,8 +8,9 @@ export default DS.RESTSerializer.extend({
if (id) {
payload.path = id;
}
const response = {
[primaryModelClass.modelName]: payload,
let response = {
...payload.data,
path: payload.path,
};
return this._super(store, primaryModelClass, response, id, requestType);
},

View File

@ -11,7 +11,7 @@
{{else}}
<li class="{{if (eq (or selectedAuthBackend.path selectedAuthBackend.type) methodKey) 'is-active' ''}}" data-test-auth-method>
<a href="{{href-to 'vault.cluster.auth' cluster.name (query-params with=methodKey)}}" data-test-auth-method-link={{method.type}}>
{{or method.id (capitalize method.type)}}
{{or method.id method.typeDisplay}}
</a>
</li>
{{/if}}
@ -51,7 +51,7 @@
>
{{#each (supported-auth-backends) as |method|}}
<option selected={{eq selectedAuthBackend.type method.type}} value={{method.type}}>
{{capitalize method.type}}
{{method.typeDisplay}}
</option>
{{/each}}
</select>

View File

@ -52,7 +52,7 @@ test('it sends the right attributes when authenticating', function(assert) {
visit('/vault/auth');
backends.reverse().forEach(backend => {
click(`[data-test-auth-method-link="${backend.type}"]`);
if (backend.type === 'GitHub') {
if (backend.type === 'github') {
component.token('token');
}
component.login();
@ -64,7 +64,7 @@ test('it sends the right attributes when authenticating', function(assert) {
Object.keys(lastRequest.requestHeaders).includes('X-Vault-Token'),
'token uses vault token header'
);
} else if (backend.type === 'GitHub') {
} else if (backend.type === 'github') {
assert.ok(Object.keys(body).includes('token'), 'GitHub includes token');
} else {
assert.ok(Object.keys(body).includes('password'), `${backend.type} includes password`);

View File

@ -250,15 +250,15 @@ test('github authentication', function(assert) {
});
Ember.run(() => {
service.authenticate({ clusterId: '1', backend: 'GitHub', data: { token: 'test' } }).then(() => {
service.authenticate({ clusterId: '1', backend: 'github', data: { token: 'test' } }).then(() => {
const clusterTokenName = service.get('currentTokenName');
const clusterToken = service.get('currentToken');
const authData = service.get('authData');
const expectedTokenName = `${TOKEN_PREFIX}GitHub${TOKEN_SEPARATOR}1`;
const expectedTokenName = `${TOKEN_PREFIX}github${TOKEN_SEPARATOR}1`;
assert.equal(GITHUB_RESPONSE.auth.client_token, clusterToken, 'token is saved properly');
assert.equal(expectedTokenName, clusterTokenName, 'token name is saved properly');
assert.equal('GitHub', authData.backend.type, 'backend is saved properly');
assert.equal('github', authData.backend.type, 'backend is saved properly');
assert.equal(
GITHUB_RESPONSE.auth.metadata.org + '/' + GITHUB_RESPONSE.auth.metadata.username,
authData.displayName,