2019-12-28 14:58:25 +05:30
|
|
|
|
import { account1 } from '../../fixtures/accounts.json';
|
2024-12-18 02:19:05 +05:30
|
|
|
|
import { OAuthState } from 'app/components/auth/reducer';
|
2020-08-02 00:49:00 +05:30
|
|
|
|
import { UserResponse } from 'app/services/api/accounts';
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2019-12-26 17:48:58 +05:30
|
|
|
|
const defaults = {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
client_id: 'ely',
|
|
|
|
|
redirect_uri: 'https://dev.ely.by/authorization/oauth',
|
|
|
|
|
response_type: 'code',
|
|
|
|
|
scope: 'account_info,account_email',
|
2019-12-26 17:48:58 +05:30
|
|
|
|
};
|
|
|
|
|
|
2019-12-28 15:55:44 +05:30
|
|
|
|
describe('OAuth', () => {
|
2024-12-18 03:41:39 +05:30
|
|
|
|
describe('AuthCode grant flow', () => {
|
|
|
|
|
it('should complete oauth', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
|
|
|
|
|
|
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should restore previous oauthData if any', () => {
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
'oauthData',
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
timestamp: Date.now() - 3600,
|
|
|
|
|
payload: {
|
|
|
|
|
params: {
|
|
|
|
|
clientId: 'ely',
|
|
|
|
|
redirectUrl: 'https://dev.ely.by/authorization/oauth',
|
|
|
|
|
responseType: 'code',
|
|
|
|
|
state: '',
|
|
|
|
|
scope: 'account_info account_email',
|
|
|
|
|
},
|
|
|
|
|
} as OAuthState,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/');
|
|
|
|
|
|
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('static pages', () => {
|
|
|
|
|
it('should authenticate using static page', () => {
|
|
|
|
|
cy.server();
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '/api/oauth2/v1/complete**',
|
|
|
|
|
}).as('complete');
|
|
|
|
|
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'static_page',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cy.wait('@complete');
|
|
|
|
|
|
|
|
|
|
cy.url().should('include', 'oauth/finish#{%22auth_code%22:');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should authenticate using static page with code', () => {
|
|
|
|
|
cy.server();
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '/api/oauth2/v1/complete**',
|
|
|
|
|
}).as('complete');
|
|
|
|
|
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'static_page_with_code',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cy.wait('@complete');
|
|
|
|
|
|
|
|
|
|
cy.url().should('include', 'oauth/finish#{%22auth_code%22:');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2024-12-18 03:41:39 +05:30
|
|
|
|
cy.findByTestId('oauth-code-container').should('contain', 'provide the following code');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2024-12-18 03:41:39 +05:30
|
|
|
|
// just click on copy, but we won't assert if the string was copied
|
|
|
|
|
// because it is a little bit complicated
|
|
|
|
|
// https://github.com/cypress-io/cypress/issues/2752
|
|
|
|
|
cy.findByTestId('oauth-code-container').contains('Copy').click();
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2024-12-18 03:41:39 +05:30
|
|
|
|
describe('DeviceCode grant flow', () => {
|
|
|
|
|
it('should complete flow by complete uri', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code?user_code=E2E-APPROVED');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/oauth/finish');
|
|
|
|
|
cy.get('[data-e2e-content]').contains('successfully completed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should complete flow with manual approve', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=user_code]').type('E2E-UNAPPROVED{enter}');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/oauth/permissions');
|
|
|
|
|
|
|
|
|
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/oauth/finish');
|
|
|
|
|
cy.get('[data-e2e-content]').contains('successfully completed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should complete flow with auto approve', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=user_code]').type('E2E-APPROVED{enter}');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/oauth/finish');
|
|
|
|
|
cy.get('[data-e2e-content]').contains('successfully completed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should complete flow by declining the code', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=user_code]').type('E2E-UNAPPROVED{enter}');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/oauth/permissions');
|
|
|
|
|
|
|
|
|
|
cy.findByTestId('auth-controls-secondary').contains('Decline').click();
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/oauth/finish');
|
|
|
|
|
cy.get('[data-e2e-content]').contains('was failed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should show an error for an unknown code', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=user_code]').type('UNKNOWN-CODE{enter}');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/code');
|
|
|
|
|
cy.findByTestId('auth-error').contains('Invalid Device Code');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should show an error for an expired code', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=user_code]').type('E2E-EXPIRED{enter}');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/code');
|
|
|
|
|
cy.findByTestId('auth-error').contains('The code has expired');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should show an error for an expired code', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
|
|
|
|
|
|
|
|
|
cy.visit('/code');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=user_code]').type('E2E-COMPLETED{enter}');
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/code');
|
|
|
|
|
cy.findByTestId('auth-error').contains('This code has been already used');
|
|
|
|
|
});
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
describe('AccountSwitcher', () => {
|
|
|
|
|
it('should ask to choose an account if user has multiple', () => {
|
|
|
|
|
cy.login({ accounts: ['default', 'default2'] }).then(({ accounts: [account] }) => {
|
|
|
|
|
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.url().should('include', '/oauth/choose-account');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.findByTestId('auth-header').should('contain', 'Choose an account');
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.findByTestId('auth-body').contains(account.email).click();
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
describe('Permissions prompt', () => {
|
|
|
|
|
// TODO: remove api mocks, when we will be able to revoke permissions
|
|
|
|
|
it('should prompt for permissions', () => {
|
|
|
|
|
cy.server();
|
|
|
|
|
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
// NOTE: can not use cypress glob syntax, because it will break due to
|
|
|
|
|
// '%2F%2F' (//) in redirect_uri
|
|
|
|
|
// url: '/api/oauth2/v1/complete/*',
|
|
|
|
|
url: new RegExp('/api/oauth2/v1/complete'),
|
|
|
|
|
response: {
|
|
|
|
|
statusCode: 401,
|
|
|
|
|
error: 'accept_required',
|
|
|
|
|
},
|
|
|
|
|
status: 401,
|
|
|
|
|
}).as('complete');
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.login({ accounts: ['default'] });
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'http://localhost:8080',
|
2024-12-18 02:19:05 +05:30
|
|
|
|
state: '123',
|
2020-10-11 22:45:53 +05:30
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.wait('@complete');
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
assertPermissions();
|
2019-12-28 15:55:44 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.server({ enable: false });
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2024-12-18 02:19:05 +05:30
|
|
|
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=123$/);
|
2020-10-11 22:45:53 +05:30
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2021-03-29 08:24:37 +05:30
|
|
|
|
it('should redirect to error page, when permission request declined', () => {
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.server();
|
|
|
|
|
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
// NOTE: can not use cypress glob syntax, because it will break due to
|
|
|
|
|
// '%2F%2F' (//) in redirect_uri
|
|
|
|
|
// url: '/api/oauth2/v1/complete/*',
|
|
|
|
|
url: new RegExp('/api/oauth2/v1/complete'),
|
|
|
|
|
response: {
|
|
|
|
|
statusCode: 401,
|
|
|
|
|
error: 'accept_required',
|
|
|
|
|
},
|
|
|
|
|
status: 401,
|
|
|
|
|
}).as('complete');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.login({ accounts: ['default'] });
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'http://localhost:8080',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.wait('@complete');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
assertPermissions();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.server({ enable: false });
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.findByTestId('auth-controls-secondary').contains('Decline').click();
|
2020-08-02 00:49:00 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.url().should('include', 'error=access_denied');
|
2020-08-02 00:49:00 +05:30
|
|
|
|
});
|
2020-10-11 22:45:53 +05:30
|
|
|
|
});
|
2020-08-02 00:49:00 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
describe('Sign-in during oauth', () => {
|
|
|
|
|
it('should allow sign in during oauth (guest oauth)', () => {
|
|
|
|
|
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
|
2020-08-02 00:49:00 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/login');
|
2020-08-02 00:49:00 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.get('[name=password]').type(`${account1.password}{enter}`);
|
2019-12-28 15:55:44 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
describe('Deleted account', () => {
|
|
|
|
|
it('should show account switcher and then abort oauth and redirect to profile', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
|
|
|
|
|
cy.server();
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: `/api/v1/accounts/${account1.id}`,
|
|
|
|
|
response: {
|
|
|
|
|
id: account.id,
|
|
|
|
|
uuid: '522e8c19-89d8-4a6d-a2ec-72ebb58c2dbe',
|
|
|
|
|
username: account.username,
|
|
|
|
|
isOtpEnabled: false,
|
|
|
|
|
registeredAt: 1475568334,
|
|
|
|
|
lang: 'en',
|
|
|
|
|
elyProfileLink: 'http://ely.by/u7',
|
|
|
|
|
email: account.email,
|
|
|
|
|
isActive: true,
|
|
|
|
|
isDeleted: true, // force user into the deleted state
|
|
|
|
|
passwordChangedAt: 1476075696,
|
|
|
|
|
hasMojangUsernameCollision: true,
|
|
|
|
|
shouldAcceptRules: false,
|
|
|
|
|
} as UserResponse,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
|
|
|
|
|
|
|
|
|
|
cy.findByTestId('auth-header').should('contain', 'Choose an account');
|
|
|
|
|
|
|
|
|
|
cy.findByTestId('auth-body').contains(account.email).click();
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/');
|
|
|
|
|
cy.findByTestId('deletedAccount').should('contain', 'Account is deleted');
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
it('should allow sign and then abort oauth and redirect to profile', () => {
|
|
|
|
|
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
|
|
|
|
|
|
|
|
|
|
cy.location('pathname').should('eq', '/login');
|
|
|
|
|
|
|
|
|
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
|
|
|
|
|
|
|
|
|
cy.url().should('include', '/password');
|
|
|
|
|
|
|
|
|
|
cy.server();
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: `/api/v1/accounts/${account1.id}`,
|
|
|
|
|
response: {
|
|
|
|
|
id: 7,
|
|
|
|
|
uuid: '522e8c19-89d8-4a6d-a2ec-72ebb58c2dbe',
|
|
|
|
|
username: 'SleepWalker',
|
|
|
|
|
isOtpEnabled: false,
|
|
|
|
|
registeredAt: 1475568334,
|
|
|
|
|
lang: 'en',
|
|
|
|
|
elyProfileLink: 'http://ely.by/u7',
|
|
|
|
|
email: 'danilenkos@auroraglobal.com',
|
|
|
|
|
isActive: true,
|
|
|
|
|
isDeleted: true, // force user into the deleted state
|
|
|
|
|
passwordChangedAt: 1476075696,
|
|
|
|
|
hasMojangUsernameCollision: true,
|
|
|
|
|
shouldAcceptRules: false,
|
|
|
|
|
} as UserResponse,
|
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.get('[name=password]').type(`${account1.password}{enter}`);
|
2019-12-28 15:55:44 +05:30
|
|
|
|
|
2020-10-11 22:45:53 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/');
|
|
|
|
|
cy.findByTestId('deletedAccount').should('contain', 'Account is deleted');
|
|
|
|
|
});
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
describe('login_hint', () => {
|
|
|
|
|
it('should automatically choose account, when id in login_hint is present', () => {
|
|
|
|
|
cy.login({ accounts: ['default', 'default2'] }).then(({ accounts: [account] }) => {
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
// suggest preferred username
|
|
|
|
|
// https://docs.ely.by/ru/oauth.html#id3
|
|
|
|
|
login_hint: String(account.id),
|
|
|
|
|
}).toString()}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should automatically choose account, when email in login_hint is present', () => {
|
|
|
|
|
cy.login({ accounts: ['default', 'default2'] }).then(({ accounts: [account] }) => {
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
// suggest preferred username
|
|
|
|
|
// https://docs.ely.by/ru/oauth.html#id3
|
|
|
|
|
login_hint: account.email,
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should automatically choose account, when username in login_hint is present and it is not an active account', () => {
|
|
|
|
|
cy.login({ accounts: ['default2', 'default'] }).then(
|
|
|
|
|
({
|
|
|
|
|
// try to authenticate with an account, that is not currently active one
|
|
|
|
|
accounts: [, account],
|
|
|
|
|
}) => {
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
// suggest preferred username
|
|
|
|
|
// https://docs.ely.by/ru/oauth.html#id3
|
|
|
|
|
login_hint: account.username,
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
2019-12-28 15:55:44 +05:30
|
|
|
|
});
|
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
describe('prompts', () => {
|
|
|
|
|
it('should prompt for account', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
prompt: 'select_account',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/oauth/choose-account');
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-header').should('contain', 'Choose an account');
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-body').contains(account.email).click();
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
it('should allow sign in with another account', () => {
|
|
|
|
|
cy.login({ accounts: ['default2'] });
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
prompt: 'select_account',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/oauth/choose-account');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-controls').contains('another account').click();
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-08-04 16:18:16 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/login');
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.get('[name=password]').type(`${account1.password}{enter}`);
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('equal', 'https://dev.ely.by/');
|
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
it('should prompt for permissions', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] });
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'http://localhost:8080',
|
|
|
|
|
prompt: 'consent',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
assertPermissions();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2024-12-18 02:19:05 +05:30
|
|
|
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+$/);
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2021-03-29 08:24:37 +05:30
|
|
|
|
it('should redirect to error page, when permission request declined', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.login({ accounts: ['default'] });
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'http://localhost:8080',
|
|
|
|
|
prompt: 'consent',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/oauth/permissions');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-controls-secondary').contains('Decline').click();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', 'error=access_denied');
|
|
|
|
|
});
|
2019-12-28 15:55:44 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
it('should prompt for both account and permissions', () => {
|
|
|
|
|
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'http://localhost:8080',
|
|
|
|
|
prompt: 'select_account,consent',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-28 15:55:44 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/oauth/choose-account');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-header').should('contain', 'Choose an account');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-body').contains(account.email).click();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
assertPermissions();
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
2019-12-28 15:55:44 +05:30
|
|
|
|
|
2024-12-18 02:19:05 +05:30
|
|
|
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+$/);
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
it('should allow sign in during oauth (guest oauth)', () => {
|
|
|
|
|
cy.visit(
|
|
|
|
|
`/oauth2/v1/ely?${new URLSearchParams({
|
|
|
|
|
...defaults,
|
|
|
|
|
client_id: 'tlauncher',
|
|
|
|
|
redirect_uri: 'http://localhost:8080',
|
|
|
|
|
prompt: 'select_account,consent',
|
|
|
|
|
})}`,
|
|
|
|
|
);
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-08-04 16:18:16 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/login');
|
2019-12-26 17:48:58 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2019-12-29 21:56:51 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.get('[name=password]').type(`${account1.password}{enter}`);
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
assertPermissions();
|
2019-12-28 14:58:25 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.findByTestId('auth-controls').contains('Approve').click();
|
2019-12-29 21:56:51 +05:30
|
|
|
|
|
2024-12-18 02:19:05 +05:30
|
|
|
|
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+$/);
|
2020-05-24 04:38:24 +05:30
|
|
|
|
});
|
2019-12-28 15:55:44 +05:30
|
|
|
|
});
|
2019-12-26 17:48:58 +05:30
|
|
|
|
});
|
2019-12-29 21:56:51 +05:30
|
|
|
|
|
|
|
|
|
function assertPermissions() {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
cy.url().should('include', '/oauth/permissions');
|
|
|
|
|
|
|
|
|
|
cy.findByTestId('auth-header').should('contain', 'Application permissions');
|
|
|
|
|
cy.findByTestId('auth-body').should('contain', 'Access to your profile data (except E‑mail)');
|
|
|
|
|
cy.findByTestId('auth-body').should('contain', 'Access to your E‑mail address');
|
2019-12-29 21:56:51 +05:30
|
|
|
|
}
|