mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-10 22:02:13 +05:30
Fix E2E tests, related to the OAuth flow
This commit is contained in:
parent
af59cc033f
commit
b0975f0b0f
@ -391,7 +391,7 @@ export function oAuthComplete(params: { accept?: boolean } = {}) {
|
|||||||
} else if (resp.redirectUri.startsWith('static_page')) {
|
} else if (resp.redirectUri.startsWith('static_page')) {
|
||||||
const displayCode = resp.redirectUri.includes('static_page_with_code');
|
const displayCode = resp.redirectUri.includes('static_page_with_code');
|
||||||
|
|
||||||
const [, code] = resp.redirectUri.match(/code=(.+)&/) || [];
|
const [, code] = resp.redirectUri.match(/code=([^&]+)/) || [];
|
||||||
[, resp.redirectUri] = resp.redirectUri.match(/^(.+)\?/) || [];
|
[, resp.redirectUri] = resp.redirectUri.match(/^(.+)\?/) || [];
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
|
@ -69,16 +69,17 @@ const api = {
|
|||||||
success: boolean;
|
success: boolean;
|
||||||
redirectUri?: string;
|
redirectUri?: string;
|
||||||
}> {
|
}> {
|
||||||
const query = request.buildQuery(oauthData);
|
const data: Record<string, any> = {};
|
||||||
|
|
||||||
|
if (typeof params.accept !== 'undefined') {
|
||||||
|
data.accept = params.accept;
|
||||||
|
}
|
||||||
|
|
||||||
return request
|
return request
|
||||||
.post<{
|
.post<{
|
||||||
success: boolean;
|
success: boolean;
|
||||||
redirectUri: string;
|
redirectUri: string;
|
||||||
}>(
|
}>(`/api/oauth2/v1/complete?${request.buildQuery(oauthData)}`, data)
|
||||||
`/api/oauth2/v1/complete?${query}`,
|
|
||||||
typeof params.accept === 'undefined' ? {} : { accept: params.accept },
|
|
||||||
)
|
|
||||||
.catch((resp = {}) => {
|
.catch((resp = {}) => {
|
||||||
if (resp.statusCode === 401 && resp.error === 'access_denied') {
|
if (resp.statusCode === 401 && resp.error === 'access_denied') {
|
||||||
// user declined permissions
|
// user declined permissions
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { account1 } from '../../fixtures/accounts.json';
|
import { account1 } from '../../fixtures/accounts.json';
|
||||||
|
import { OAuthState } from 'app/components/auth/reducer';
|
||||||
import { UserResponse } from 'app/services/api/accounts';
|
import { UserResponse } from 'app/services/api/accounts';
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
@ -23,14 +24,14 @@ describe('OAuth', () => {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
timestamp: Date.now() - 3600,
|
timestamp: Date.now() - 3600,
|
||||||
payload: {
|
payload: {
|
||||||
clientId: 'ely',
|
params: {
|
||||||
redirectUrl: 'https://dev.ely.by/authorization/oauth',
|
clientId: 'ely',
|
||||||
responseType: 'code',
|
redirectUrl: 'https://dev.ely.by/authorization/oauth',
|
||||||
description: null,
|
responseType: 'code',
|
||||||
scope: 'account_info account_email',
|
state: '',
|
||||||
loginHint: null,
|
scope: 'account_info account_email',
|
||||||
state: null,
|
},
|
||||||
},
|
} as OAuthState,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
cy.login({ accounts: ['default'] });
|
cy.login({ accounts: ['default'] });
|
||||||
@ -81,6 +82,7 @@ describe('OAuth', () => {
|
|||||||
...defaults,
|
...defaults,
|
||||||
client_id: 'tlauncher',
|
client_id: 'tlauncher',
|
||||||
redirect_uri: 'http://localhost:8080',
|
redirect_uri: 'http://localhost:8080',
|
||||||
|
state: '123',
|
||||||
})}`,
|
})}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ describe('OAuth', () => {
|
|||||||
|
|
||||||
cy.findByTestId('auth-controls').contains('Approve').click();
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
||||||
|
|
||||||
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=123$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to error page, when permission request declined', () => {
|
it('should redirect to error page, when permission request declined', () => {
|
||||||
@ -334,7 +336,7 @@ describe('OAuth', () => {
|
|||||||
|
|
||||||
cy.findByTestId('auth-controls').contains('Approve').click();
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
||||||
|
|
||||||
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to error page, when permission request declined', () => {
|
it('should redirect to error page, when permission request declined', () => {
|
||||||
@ -377,7 +379,7 @@ describe('OAuth', () => {
|
|||||||
|
|
||||||
cy.findByTestId('auth-controls').contains('Approve').click();
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
||||||
|
|
||||||
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+$/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -403,7 +405,7 @@ describe('OAuth', () => {
|
|||||||
|
|
||||||
cy.findByTestId('auth-controls').contains('Approve').click();
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
||||||
|
|
||||||
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+$/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user