2018-03-14 02:21:37 +05:30
|
|
|
|
// account1 - authenticated
|
|
|
|
|
// account2 - invalid refreshToken
|
2019-12-28 15:55:44 +05:30
|
|
|
|
import { account1, account2 } from '../../fixtures/accounts.json';
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2018-03-14 02:21:37 +05:30
|
|
|
|
const multiAccount = createState();
|
|
|
|
|
const multiAccountWithBadTokens = createState();
|
|
|
|
|
const singleAccount = createState();
|
|
|
|
|
singleAccount.accounts.available = singleAccount.accounts.available.filter(
|
2020-05-20 22:05:52 +05:30
|
|
|
|
(account) => account.id === singleAccount.accounts.active,
|
2018-03-14 02:21:37 +05:30
|
|
|
|
);
|
2018-03-01 03:28:02 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
describe('User with invalid token and refreshToken', () => {
|
|
|
|
|
before(() => {
|
2019-11-27 14:33:32 +05:30
|
|
|
|
// ensure we always have one account with correct token
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.login({
|
|
|
|
|
accounts: ['default'],
|
|
|
|
|
updateState: false,
|
|
|
|
|
rawApiResp: true,
|
|
|
|
|
}).then(({ accounts: [resp] }) => {
|
|
|
|
|
const account = multiAccount.accounts.available.find(
|
2020-05-20 22:05:52 +05:30
|
|
|
|
(item) => item.username === account1.username,
|
2019-12-29 21:56:51 +05:30
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
|
throw new Error('Can not find an account');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
account.token = resp.access_token;
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-03-01 03:28:45 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
beforeEach(() =>
|
|
|
|
|
localStorage.setItem('redux-storage', JSON.stringify(multiAccount)),
|
|
|
|
|
);
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('should ask for password', () => {
|
|
|
|
|
cy.visit('/');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[name="password"]').type(`${account2.password}{enter}`);
|
2018-03-01 03:28:02 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.contains('account preferences');
|
|
|
|
|
});
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('should not allow to return to profile using toolbar', () => {
|
|
|
|
|
cy.visit('/');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2018-03-01 03:28:02 +05:30
|
|
|
|
|
2020-05-22 00:07:35 +05:30
|
|
|
|
cy.findByTestId('toolbar').get('a').contains('Ely.by').click();
|
2018-03-14 02:21:37 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
});
|
2018-03-01 03:28:02 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('should allow select account', () => {
|
|
|
|
|
cy.visit('/');
|
2018-03-01 03:28:02 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[data-e2e-go-back]').click();
|
2018-03-01 03:28:02 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/choose-account');
|
2018-02-28 02:47:31 +05:30
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
|
cy.get('[data-e2e-content]').contains(account2.email).should('not.exist');
|
2018-11-04 13:39:42 +05:30
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
|
cy.get('[data-e2e-content]').contains(account1.username).click();
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.get('[name="password"]').type(`${account2.password}{enter}`);
|
2018-02-28 02:47:31 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.contains('account preferences');
|
|
|
|
|
});
|
2018-02-28 02:47:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('it should redirect to login, when one account and clicking back', () => {
|
|
|
|
|
cy.url().should(() =>
|
|
|
|
|
localStorage.setItem('redux-storage', JSON.stringify(singleAccount)),
|
|
|
|
|
);
|
|
|
|
|
cy.visit('/');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2018-11-04 13:39:42 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[data-e2e-go-back]').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/login');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2020-05-22 00:07:35 +05:30
|
|
|
|
cy.findByTestId('toolbar').contains('Join');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
});
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('should allow logout', () => {
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.server();
|
|
|
|
|
cy.route({
|
|
|
|
|
url: `/api/v1/accounts/${account2.id}`,
|
|
|
|
|
}).as('account');
|
|
|
|
|
cy.route({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '/api/authentication/logout',
|
|
|
|
|
}).as('logout');
|
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.visit('/');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
|
cy.wait('@account').its('status').should('eq', 401);
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2020-05-22 00:07:35 +05:30
|
|
|
|
cy.findByTestId('toolbar').contains(account2.username).click();
|
|
|
|
|
cy.findByTestId('toolbar').contains('Log out').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.wait('@logout');
|
2020-05-22 00:07:35 +05:30
|
|
|
|
cy.findByTestId('toolbar').contains(account2.email).should('not.exist');
|
|
|
|
|
cy.findByTestId('toolbar').contains(account2.username).should('not.exist');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should allow enter new login from choose account', () => {
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.server();
|
|
|
|
|
cy.route({
|
|
|
|
|
url: `/api/v1/accounts/${account2.id}`,
|
|
|
|
|
}).as('account');
|
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.visit('/');
|
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
|
cy.wait('@account').its('status').should('eq', 401);
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[data-e2e-go-back]').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[name=password]').should('not.exist'); // wait till panel transition end
|
|
|
|
|
cy.url().should('include', '/choose-account');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.contains('Log into another').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/login');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/password');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[name=password]').type(account1.password);
|
|
|
|
|
cy.get('[name=rememberMe]').should('be.checked');
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.get('[type=submit]').should('have.length', 1); // wait till transition ends
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[type=submit]').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
});
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('should allow logout from all accounts while choosing an account', () => {
|
|
|
|
|
cy.visit('/');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[data-e2e-go-back]').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/choose-account');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.contains('Log out from all accounts').click();
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('include', '/login');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2020-05-22 00:07:35 +05:30
|
|
|
|
cy.findByTestId('toolbar').contains('a', 'Join');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
});
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
it('should ask for password if selected account with bad token', () => {
|
|
|
|
|
cy.url().should(() =>
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
'redux-storage',
|
|
|
|
|
JSON.stringify(multiAccountWithBadTokens),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
cy.visit('/');
|
|
|
|
|
|
|
|
|
|
cy.get('[data-e2e-go-back]').click();
|
|
|
|
|
|
|
|
|
|
cy.url().should('include', '/choose-account');
|
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
|
cy.get('[data-e2e-content]').contains(account1.username).click();
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
|
|
cy.url().should('include', '/password');
|
|
|
|
|
|
|
|
|
|
// TODO: remove wait and fix logic so that
|
|
|
|
|
// it won't show 'Please enter E‑mail or username' error
|
|
|
|
|
cy.wait(1000);
|
|
|
|
|
cy.get('[name="password"]').type(`${account1.password}{enter}`);
|
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.location('pathname').should('eq', '/');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.contains('account preferences');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is a regression test for the edge case, when user tries to register new
|
|
|
|
|
* account during a passowrd request to get new refreshToken for the current
|
|
|
|
|
* active account
|
|
|
|
|
*
|
|
|
|
|
* Expected result:
|
|
|
|
|
* It should show register page, when user clicks 'Register new account'
|
|
|
|
|
*
|
|
|
|
|
* Actual result:
|
|
|
|
|
* User was redirected from register page back to password page due to recursive
|
|
|
|
|
* atempt to get new refreshToken
|
|
|
|
|
*
|
|
|
|
|
* @see https://trello.com/c/iINbZ2l2
|
|
|
|
|
*/
|
|
|
|
|
it('should allow enter register page during password request for other account with invalid token', () => {
|
|
|
|
|
cy.visit('/');
|
|
|
|
|
|
|
|
|
|
cy.url().should('contain', '/password');
|
|
|
|
|
|
|
|
|
|
cy.get('[data-e2e-go-back]').click();
|
|
|
|
|
cy.get('[name=password]').should('not.exist'); // wait till panel transition end
|
|
|
|
|
cy.contains('[type=submit]', 'Log into another account').click();
|
|
|
|
|
cy.contains('a', 'Create new account').click();
|
|
|
|
|
|
|
|
|
|
cy.url().should('contain', '/register');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is a regression test for the edge case, when user tries to register new
|
|
|
|
|
* account via direct sign up page link
|
|
|
|
|
*
|
|
|
|
|
* Expected result:
|
|
|
|
|
* It should show register page
|
|
|
|
|
*
|
|
|
|
|
* Actual result:
|
|
|
|
|
* User was redirected from register page back to password page due to recursive
|
|
|
|
|
* atempt to get new refreshToken
|
|
|
|
|
*
|
|
|
|
|
* @see https://trello.com/c/iINbZ2l2
|
|
|
|
|
*/
|
|
|
|
|
it('should allow enter register page, when current account has invalid token', () => {
|
|
|
|
|
cy.visit('/register');
|
|
|
|
|
|
|
|
|
|
cy.url().should('contain', '/register');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should allow oauth', () => {
|
|
|
|
|
cy.visit(
|
2020-01-10 17:57:20 +05:30
|
|
|
|
'/oauth2/v1/ely?client_id=ely&redirect_uri=https%3A%2F%2Fdev.ely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email',
|
2019-11-27 14:33:32 +05:30
|
|
|
|
);
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.url().should('contain', '/password');
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
cy.get('[name=password]').type(`${account2.password}{enter}`);
|
2018-02-18 23:39:32 +05:30
|
|
|
|
|
2019-12-29 21:56:51 +05:30
|
|
|
|
cy.url().should('contain', '/oauth/choose-account');
|
2018-03-14 17:11:29 +05:30
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
|
cy.get('[data-e2e-content]').contains(account2.username).click();
|
2018-03-14 17:11:29 +05:30
|
|
|
|
|
2020-01-10 17:57:20 +05:30
|
|
|
|
cy.url().should('contain', '//dev.ely.by');
|
2019-11-27 14:33:32 +05:30
|
|
|
|
});
|
2018-02-18 23:39:32 +05:30
|
|
|
|
});
|
2018-03-14 02:21:37 +05:30
|
|
|
|
|
|
|
|
|
function createState() {
|
2019-11-27 14:33:32 +05:30
|
|
|
|
return {
|
|
|
|
|
accounts: {
|
|
|
|
|
available: [
|
|
|
|
|
{
|
|
|
|
|
id: 7,
|
|
|
|
|
username: 'SleepWalker',
|
|
|
|
|
email: 'danilenkos@auroraglobal.com',
|
|
|
|
|
token:
|
|
|
|
|
'eyJhbGciOiJIUzI1NiJ9.eyJlbHktc2NvcGVzIjoiYWNjb3VudHNfd2ViX3VzZXIiLCJpYXQiOjE1MTgzNzM4MDksImV4cCI6MTUxODM3NzQwOSwic3ViIjoiZWx5fDciLCJqdGkiOjM1NDh9.Fv4AbJ0iDbrH3bhbgF0ViJLfYYiwH78deR4fMlMhKrQ',
|
|
|
|
|
refreshToken:
|
|
|
|
|
'3gh6ZZ3R9jGeFdp0TmlY7sd0zBxH6Zfq48M86eUAv952RcAKx32RAnjlKkgd6i-MV-RKbjtADIdoRwMUWOYQjEYtwwXPjcQJ',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 102,
|
|
|
|
|
username: 'test',
|
|
|
|
|
email: 'admin@udf.su',
|
|
|
|
|
token:
|
|
|
|
|
'eyJhbGciOiJIUzI1NiJ9.eyJlbHktc2NvcGVzIjoiYWNjb3VudHNfd2ViX3VzZXIiLCJpYXQiOjE1MTgzNzM4NjUsImV4cCI6MTUxODM3NzQ2NSwic3ViIjoiZWx5fDEwMiIsImp0aSI6MzU0OX0.eJEgvXT3leGqBe3tYNGZb0E4WEvWfrLPjcD7eNjyQYO',
|
|
|
|
|
refreshToken:
|
|
|
|
|
'Al75SIx-LFOCP7kaqZBVqMVmSljJw9_bdFQGyuM64c6ShP7YsXbkCD8vPOundAwUDfRZqsIbOHUROmAHPB0VBfjLfw96yqxx',
|
2018-03-14 02:21:37 +05:30
|
|
|
|
},
|
2019-11-27 14:33:32 +05:30
|
|
|
|
],
|
|
|
|
|
active: 102,
|
|
|
|
|
},
|
|
|
|
|
user: {
|
|
|
|
|
id: 102,
|
|
|
|
|
uuid: 'e49cafdc-6e0c-442d-b608-dacdb864ee34',
|
|
|
|
|
username: 'test',
|
|
|
|
|
token: '',
|
|
|
|
|
email: 'admin@udf.su',
|
|
|
|
|
maskedEmail: '',
|
|
|
|
|
avatar: '',
|
|
|
|
|
lang: 'en',
|
|
|
|
|
isActive: true,
|
|
|
|
|
isOtpEnabled: true,
|
|
|
|
|
shouldAcceptRules: false,
|
|
|
|
|
passwordChangedAt: 1478961317,
|
|
|
|
|
hasMojangUsernameCollision: true,
|
|
|
|
|
isGuest: false,
|
|
|
|
|
registeredAt: 1478961317,
|
|
|
|
|
elyProfileLink: 'http://ely.by/u102',
|
|
|
|
|
},
|
|
|
|
|
};
|
2018-03-14 02:21:37 +05:30
|
|
|
|
}
|