refactor: 💡 mock authenticate should handle multiple auth types
This commit is contained in:
6 files changed
+36
-69
No files matched your search
@@ -23,28 +23,34 @@ import { Response } from 'miragejs';
|
||||
// }
|
||||
// }
|
||||
|
||||
const methodHandlers = {
|
||||
password: {
|
||||
authenticate: (scopeAttrs) =>
|
||||
new Response(200, {}, {
|
||||
scope: scopeAttrs,
|
||||
id: 'token123',
|
||||
token: 'thetokenstring',
|
||||
account_id: '1',
|
||||
user_id: 'user123',
|
||||
auth_method_id: 'authmethod123',
|
||||
created_time: '',
|
||||
updated_time: '',
|
||||
last_used_time: '',
|
||||
expiration_time: ''
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export function authHandler({ scopes, authMethods }, request) {
|
||||
const payload = JSON.parse(request.requestBody);
|
||||
if (payload.credentials.login_name === 'error') {
|
||||
return new Response(400);
|
||||
} else {
|
||||
const id = request.params.id_method.split(':')[0];
|
||||
const [, id, method] = request.params.id_method.match(/(?<id>.[^:]*)(?::)?(?<method>.*)?/);
|
||||
const authMethod = authMethods.find(id);
|
||||
const scope = scopes.find(authMethod.scopeId);
|
||||
const scopeAttrs =
|
||||
this.serialize(scopes.find(scope.id));
|
||||
return new Response(200, {}, {
|
||||
scope: scopeAttrs,
|
||||
id: 'token123',
|
||||
token: 'thetokenstring',
|
||||
account_id: '1',
|
||||
user_id: 'user123',
|
||||
auth_method_id: 'authmethod123',
|
||||
created_time: '',
|
||||
updated_time: '',
|
||||
last_used_time: '',
|
||||
expiration_time: ''
|
||||
});
|
||||
const scopeAttrs = this.serialize(scopes.find(scope.id));
|
||||
return methodHandlers[authMethod.type][method](scopeAttrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import BaseAuthenticator from './base';
|
||||
// import { resolve, reject } from 'rsvp';
|
||||
// import fetch from 'fetch';
|
||||
import { Promise } from 'rsvp';
|
||||
//import { Promise } from 'rsvp';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -17,9 +17,9 @@ export default class OIDCAuthenticator extends BaseAuthenticator {
|
||||
} */) { }
|
||||
|
||||
async authenticate(
|
||||
creds,
|
||||
requestCookies = true,
|
||||
options
|
||||
// creds,
|
||||
// requestCookies = true,
|
||||
// options
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { module/*, test */} from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
|
||||
module('Integration | Component | form/authenticate/oidc', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
// Set any properties with this.set('myProperty', 'value');
|
||||
// Handle any actions with this.set('myAction', function(val) { ... });
|
||||
|
||||
await render(hbs`<Form::Authenticate::Oidc />`);
|
||||
|
||||
assert.equal(this.element.textContent.trim(), '');
|
||||
|
||||
// Template block usage:
|
||||
await render(hbs`
|
||||
<Form::Authenticate::Oidc>
|
||||
template block text
|
||||
</Form::Authenticate::Oidc>
|
||||
`);
|
||||
|
||||
assert.equal(this.element.textContent.trim(), 'template block text');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user