UI unauthenticated auth method login (#4972)

* fix unauthenticated auth form
* make sure to redirect if you're already authed
* add the ability to build in a welcome message at build time
This commit is contained in:
Matthew Irish 2018-07-20 16:48:25 -05:00 committed by GitHub
parent 1d99b7fd05
commit 4de7e4806b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 8 deletions

View File

@ -8,6 +8,7 @@ const DEFAULTS = {
token: null,
username: null,
password: null,
customPath: null,
};
export default Ember.Component.extend(DEFAULTS, {
@ -75,10 +76,14 @@ export default Ember.Component.extend(DEFAULTS, {
'selectedAuth',
'selectedAuthIsPath',
function() {
let methods = this.get('allSupportedMethods');
let methods = this.get('methods');
let selectedAuth = this.get('selectedAuth');
let keyIsPath = this.get('selectedAuthIsPath');
let findKey = keyIsPath ? 'path' : 'type';
return methods.findBy(findKey, this.get('selectedAuth'));
if (keyIsPath) {
return methods.findBy('path', selectedAuth);
} else {
return BACKENDS.findBy('type', selectedAuth);
}
}
),
@ -143,15 +148,14 @@ export default Ember.Component.extend(DEFAULTS, {
});
let targetRoute = this.get('redirectTo') || 'vault.cluster';
let backend = this.get('selectedAuthBackend') || {};
let path = get(backend, 'path') || this.get('customPath');
let backendMeta = BACKENDS.find(
b => get(b, 'type').toLowerCase() === get(backend, 'type').toLowerCase()
);
let attributes = get(backendMeta, 'formAttributes');
data = Ember.assign(data, this.getProperties(...attributes));
if (get(backend, 'path') || (this.get('useCustomPath') && path)) {
data.path = path;
if (this.get('customPath') || get(backend, 'id')) {
data.path = this.get('customPath') || get(backend, 'id');
}
const clusterId = this.get('cluster.id');
this.get('auth').authenticate({ clusterId, backend: get(backend, 'type'), data }).then(

View File

@ -1,11 +1,14 @@
import ClusterRouteBase from './cluster-route-base';
import Ember from 'ember';
import config from 'vault/config/environment';
const { RSVP } = Ember;
const { RSVP, inject } = Ember;
export default ClusterRouteBase.extend({
flashMessages: inject.service(),
beforeModel() {
return this.store.unloadAll('auth-method');
this.store.unloadAll('auth-method');
return this._super();
},
model() {
let cluster = this._super(...arguments);
@ -26,4 +29,10 @@ export default ClusterRouteBase.extend({
controller.set('wrappedToken', '');
controller.set('authMethod', '');
},
afterModel() {
if (config.welcomeMessage) {
this.get('flashMessages').stickyInfo(config.welcomeMessage);
}
},
});

View File

@ -66,6 +66,7 @@ module.exports = function(environment) {
if (environment === 'production') {
}
ENV.welcomeMessage = process.env.UI_AUTH_WELCOME;
return ENV;
};

View File

@ -128,6 +128,31 @@ test('it renders all the supported methods and Other tab when methods are presen
assert.equal(component.tabs.objectAt(1).name, 'Other', 'second tab is the Other tab');
});
test('it calls authorize with the correct path', function(assert) {
this.register('service:auth', workingAuthService);
this.inject.service('auth');
let authSpy = sinon.spy(this.get('auth'), 'authenticate');
let methods = [
{
type: 'userpass',
id: 'foo',
path: 'foo/',
},
];
this.set('methods', methods);
this.set('selectedAuth', 'foo/');
this.render(hbs`{{auth-form cluster=cluster methods=methods selectedAuth=selectedAuth}}`);
component.login();
return wait().then(() => {
assert.ok(authSpy.calledOnce, 'a call to authenticate was made');
let { data } = authSpy.getCall(0).args[0];
assert.equal(data.path, methods[0].id, 'uses the id for the path');
authSpy.restore();
});
});
test('it renders all the supported methods when no supported methods are present in passed methods', function(
assert
) {