mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
#184: support for /oauth2/v1/[clientId] requests
This commit is contained in:
@@ -33,7 +33,7 @@ describe('AuthFlow.functional', () => {
|
||||
navigate = function navigate(path, extra = {}) { // emulates router behaviour
|
||||
if (navigate.lastUrl !== path) {
|
||||
navigate.lastUrl = path;
|
||||
flow.handleRequest({path, ...extra}, navigate);
|
||||
flow.handleRequest({path, query: {}, params: {}, ...extra}, navigate);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,41 +69,36 @@ describe('AuthFlow.functional', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should oauth without any rendering if no acceptance required', () => {
|
||||
const expectedRedirect = 'foo';
|
||||
describe('oauth', () => {
|
||||
it('should oauth without any rendering if no acceptance required', () => {
|
||||
const expectedRedirect = 'foo';
|
||||
|
||||
Object.assign(state, {
|
||||
user: {
|
||||
isGuest: false,
|
||||
isActive: true
|
||||
},
|
||||
Object.assign(state, {
|
||||
user: {
|
||||
isGuest: false,
|
||||
isActive: true
|
||||
},
|
||||
|
||||
routing: {
|
||||
location: {
|
||||
query: {
|
||||
auth: {
|
||||
oauth: {
|
||||
clientId: 123
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
auth: {
|
||||
oauth: {
|
||||
clientId: 123
|
||||
}
|
||||
}
|
||||
flow.run.onCall(0).returns({then: (fn) => fn()});
|
||||
flow.run.onCall(1).returns({then: (fn) => fn({
|
||||
redirectUri: expectedRedirect
|
||||
})});
|
||||
|
||||
navigate('/oauth2');
|
||||
|
||||
expect(flow.run, 'to have calls satisfying', [
|
||||
['oAuthValidate', {}],
|
||||
['oAuthComplete', {}],
|
||||
['redirect', expectedRedirect]
|
||||
]);
|
||||
});
|
||||
|
||||
flow.run.onCall(0).returns({then: (fn) => fn()});
|
||||
flow.run.onCall(1).returns({then: (fn) => fn({
|
||||
redirectUri: expectedRedirect
|
||||
})});
|
||||
|
||||
navigate('/oauth2', {query: {}});
|
||||
|
||||
expect(flow.run, 'to have calls satisfying', [
|
||||
['oAuthValidate', {}],
|
||||
['oAuthComplete', {}],
|
||||
['redirect', expectedRedirect]
|
||||
]);
|
||||
});
|
||||
|
||||
describe('/resend-activation #goBack()', () => {
|
||||
@@ -112,12 +107,6 @@ describe('AuthFlow.functional', () => {
|
||||
isGuest: true,
|
||||
isActive: false
|
||||
};
|
||||
|
||||
state.routing = {
|
||||
location: {
|
||||
pathname: ''
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should goBack to /activation', () => {
|
||||
|
@@ -178,6 +178,7 @@ describe('AuthFlow', () => {
|
||||
'/accept-rules': LoginState,
|
||||
'/oauth/permissions': LoginState,
|
||||
'/oauth/finish': LoginState,
|
||||
'/oauth2/v1/foo': OAuthState,
|
||||
'/oauth2/v1': OAuthState,
|
||||
'/oauth2': OAuthState,
|
||||
'/register': RegisterState,
|
||||
@@ -260,6 +261,18 @@ describe('AuthFlow', () => {
|
||||
sinon.stub(flow, 'run').named('flow.run');
|
||||
});
|
||||
|
||||
it('should return request with path, query, params', () => {
|
||||
const request = {path: '/'};
|
||||
|
||||
flow.handleRequest(request);
|
||||
|
||||
expect(flow.getRequest(), 'to equal', {
|
||||
...request,
|
||||
query: {},
|
||||
params: {}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a copy of current request', () => {
|
||||
const request = {path: '/', query: {foo: 'bar'}, params: {baz: 'bud'}};
|
||||
|
||||
|
@@ -30,7 +30,66 @@ describe('OAuthState', () => {
|
||||
state: 'state'
|
||||
};
|
||||
|
||||
context.getRequest.returns({query});
|
||||
context.getRequest.returns({query, params: {}});
|
||||
|
||||
expectRun(
|
||||
mock,
|
||||
'oAuthValidate',
|
||||
sinon.match({
|
||||
clientId: query.client_id,
|
||||
redirectUrl: query.redirect_uri,
|
||||
responseType: query.response_type,
|
||||
scope: query.scope,
|
||||
state: query.state
|
||||
})
|
||||
).returns({then() {}});
|
||||
|
||||
state.enter(context);
|
||||
});
|
||||
|
||||
it('should support clientId through route params', () => {
|
||||
const clientId = 'client_id';
|
||||
const query = {
|
||||
redirect_uri: 'redirect_uri',
|
||||
response_type: 'response_type',
|
||||
scope: 'scope',
|
||||
state: 'state'
|
||||
};
|
||||
|
||||
context.getRequest.returns({
|
||||
query,
|
||||
params: {clientId}
|
||||
});
|
||||
|
||||
expectRun(
|
||||
mock,
|
||||
'oAuthValidate',
|
||||
sinon.match({
|
||||
clientId,
|
||||
redirectUrl: query.redirect_uri,
|
||||
responseType: query.response_type,
|
||||
scope: query.scope,
|
||||
state: query.state
|
||||
})
|
||||
).returns({then() {}});
|
||||
|
||||
state.enter(context);
|
||||
});
|
||||
|
||||
it('should give preference to client_id from query', () => {
|
||||
const clientId = 'wrong_id';
|
||||
const query = {
|
||||
client_id: 'client_id',
|
||||
redirect_uri: 'redirect_uri',
|
||||
response_type: 'response_type',
|
||||
scope: 'scope',
|
||||
state: 'state'
|
||||
};
|
||||
|
||||
context.getRequest.returns({
|
||||
query,
|
||||
params: {clientId}
|
||||
});
|
||||
|
||||
expectRun(
|
||||
mock,
|
||||
@@ -50,7 +109,7 @@ describe('OAuthState', () => {
|
||||
it('should transition to complete state on success', () => {
|
||||
const promise = Promise.resolve();
|
||||
|
||||
context.getRequest.returns({query: {}});
|
||||
context.getRequest.returns({query: {}, params: {}});
|
||||
|
||||
mock.expects('run').returns(promise);
|
||||
expectState(mock, CompleteState);
|
||||
|
Reference in New Issue
Block a user