#389: add e2e tests for invalid refreshToken case. Minor bug fixes

This commit is contained in:
SleepWalker 2018-02-18 20:09:32 +02:00
parent bf2976c009
commit 206627be17
20 changed files with 1371 additions and 14 deletions

View File

@ -1 +1,2 @@
flow-typed
tests-e2e

View File

@ -1,6 +1,7 @@
[ignore]
.*/node_modules/fbjs/lib/.*
.*/node_modules/react-motion/lib/.*
.*/tests-e2e/.*
[include]

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/node_modules
node_modules
/dist
/dll
config/*

View File

@ -53,7 +53,10 @@ describe('components/accounts/actions', () => {
available: [],
active: null
},
user: {}
auth: {
credentials: {},
},
user: {},
});
sinon.stub(authentication, 'validateToken').named('authentication.validateToken');
@ -197,7 +200,10 @@ describe('components/accounts/actions', () => {
active: account.id,
available: [account]
},
user
auth: {
credentials: {},
},
user,
});
});
@ -279,7 +285,10 @@ describe('components/accounts/actions', () => {
active: account2.id,
available: [account, account2]
},
user
auth: {
credentials: {},
},
user,
});
});
@ -338,7 +347,7 @@ describe('components/accounts/actions', () => {
active: foreignAccount.id,
available: [account, foreignAccount, foreignAccount2]
},
user
user,
});
});
@ -409,7 +418,10 @@ describe('components/accounts/actions', () => {
active: foreignAccount.id,
available: [foreignAccount, foreignAccount2]
},
user
auth: {
credentials: {},
},
user,
});
logoutStrangers()(dispatch, getState);

View File

@ -373,6 +373,7 @@ class PanelTransition extends Component {
const backButton = (
<button style={sideScrollStyle}
className={panelStyles.headerControl}
data-e2e-go-back
type="button"
onClick={this.onGoBack}
>

View File

@ -226,12 +226,15 @@ export function setLogin(login: ?string) {
}
export function relogin(login: ?string) {
return (dispatch: (Function | Object) => void) => {
return (dispatch: (Function | Object) => void, getState: () => Object) => {
const credentials = getCredentials(getState());
const returnUrl = credentials.returnUrl || location.pathname + location.search;
dispatch({
type: SET_CREDENTIALS,
payload: {
login,
returnUrl: location.pathname + location.search,
returnUrl,
isRelogin: true,
},
});

View File

@ -42,7 +42,10 @@ describe('refreshTokenMiddleware', () => {
expect(dispatch, 'to have a call satisfying', [
{
type: 'auth:setCredentials',
payload: {login: email}
payload: {
login: email,
returnUrl: expect.it('to be a string'),
},
}
]);
@ -68,7 +71,10 @@ describe('refreshTokenMiddleware', () => {
active: account,
available: [account]
},
user: {}
auth: {
credentials: {},
},
user: {},
});
});
@ -140,7 +146,10 @@ describe('refreshTokenMiddleware', () => {
active: account,
available: [account]
},
user: {}
auth: {
credentials: {},
},
user: {},
});
const req = {url: 'foo', options: {}};
@ -284,7 +293,10 @@ describe('refreshTokenMiddleware', () => {
refreshToken: null,
}]
},
user: {}
auth: {
credentials: {},
},
user: {},
});
return expect(

View File

@ -50,7 +50,7 @@ class AuthPage extends Component<{
<AppInfo {...client} onGoToAuth={this.onGoToAuth} />
</div>
<div className={styles.content}>
<div className={styles.content} data-e2e-content>
<Switch>
<Route path="/login" render={renderPanelTransition(Login)} />
<Route path="/mfa" render={renderPanelTransition(Mfa)} />

View File

@ -64,7 +64,7 @@ class RootPage extends Component<{
<div id="view-port" className={classNames(styles.viewPort, {
[styles.isPopupActive]: isPopupActive
})}>
<div className={styles.header}>
<div className={styles.header} data-e2e-toolbar>
<div className={styles.headerContent}>
<Link to="/" className={styles.logo} onClick={onLogoClick}>
<Message {...messages.siteName} />

4
tests-e2e/cypress.json Normal file
View File

@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:8080",
"chromeWebSecurity": false
}

View File

@ -0,0 +1,12 @@
{
"account1": {
"username": "SleepWalker",
"login": "SleepWalker",
"password": "qwer1234"
},
"account2": {
"username": "test",
"login": "test",
"password": "qwer1234"
}
}

View File

@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@ -0,0 +1,150 @@
import { account1, account2 } from '../fixtures/accounts.json';
describe('when user\'s token and refreshToken are invalid', () => {
beforeEach(() =>
cy
.visit('/')
.then(() =>
localStorage.setItem(
'redux-storage',
'{"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"}],"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","originalResponse":{}}}'
)
)
);
it('should ask for password', () => {
cy.visit('/');
cy.url().should('include', '/password');
cy.get('[name="password"]').type(`${account2.password}{enter}`);
cy.location('pathname', { timeout: 15000 }).should('eq', '/');
cy.contains('account preferences');
});
it('should allow select account', () => {
cy.visit('/');
cy.get('[data-e2e-go-back]').click();
cy.url().should('include', '/choose-account');
cy
.get('[data-e2e-content]')
.contains(account1.username)
.click();
cy.location('pathname', { timeout: 15000 }).should('eq', '/');
cy.contains('account preferences');
});
it('should allow enter new login from choose account', () => {
cy.visit('/');
cy.url().should('include', '/password');
cy.get('[data-e2e-go-back]').click();
cy.get('[name=password]').should('not.exist'); // wait till panel transition end
cy.url().should('include', '/choose-account');
cy.contains('Log into another').click();
cy.url().should('include', '/login');
cy.get('[name=login]').type(`${account1.login}{enter}`);
cy.url().should('include', '/password');
cy.get('[name=password]').type(account1.password);
cy.get('[name=rememberMe]').should('be.checked');
cy.get('[type=submit]').click();
cy.location('pathname', { timeout: 15000 }).should('eq', '/');
});
it('should allow logout from all accounts while choosing an account', () => {
cy.visit('/');
cy.get('[data-e2e-go-back]').click();
cy.url().should('include', '/choose-account');
cy.contains('Log out from all accounts').click();
cy.url().should('include', '/login');
cy.get('[data-e2e-toolbar]').contains('a', 'Join');
});
it('should ask for password if selected account with bad token', () => {
cy.visit('/');
cy.get('[data-e2e-go-back]').click();
cy.url().should('include', '/choose-account');
cy
.get('[data-e2e-content]')
.contains(account2.username)
.click();
cy.url().should('include', '/password');
cy.get('[name="password"]').type(`${account2.password}{enter}`);
cy.location('pathname', { timeout: 15000 }).should('eq', '/');
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', () => {
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
.get('@fetch')
.should('be.calledWith', '/api/options');
cy.url().should('contain', '/register');
});
it('should allow oauth', () => {
cy.visit(
'/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email'
);
cy.url().should('contain', '/password');
cy.get('[name=password]').type(`${account2.password}{enter}`);
cy.url({ timeout: 15000 }).should('contain', '/oauth/choose-account');
cy
.get('[data-e2e-content]')
.contains(account2.username)
.click();
cy.url().should('contain', '//ely.by');
});
});

View File

@ -0,0 +1,47 @@
import { account1 } from '../fixtures/accounts.json';
describe('sign in', () => {
it('should sign in', () => {
cy.visit('/');
cy.get('[name=login]').type(`${account1.login}{enter}`);
cy.url().should('include', '/password');
cy.get('[name=password]').type(account1.password);
cy.get('[name=rememberMe]').should('be.checked');
cy.get('[type=submit]').click();
cy.location('pathname', { timeout: 15000 }).should('eq', '/');
cy
.get('[data-e2e-toolbar]')
.contains(account1.username)
.should(() => {
const state = JSON.parse(localStorage.getItem('redux-storage'));
expect(state.accounts.available).to.have.length(1);
const account = state.accounts.available[0];
expect(account.username).to.be.equal(account1.username);
expect(account.id)
.to.be.a('number')
.and.to.be.gt(0);
expect(account.email)
.to.be.a('string')
.and.have.length.gt(0);
expect(account.token)
.to.be.a('string')
.and.have.length.gt(0);
expect(account.refreshToken)
.to.be.a('string')
.and.have.length.gt(0);
expect(state.accounts.active).to.be.equal(account.id);
const { user } = state;
expect(user.id).to.be.equal(account.id);
expect(user.username).to.be.equal(account.username);
expect(user.isGuest).to.be.false;
});
});
});

View File

@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

View File

@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

View File

@ -0,0 +1,28 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
Cypress.on('window:before:load', (win) => {
/**
* define @fetch alias for asserting fetch requests
* Example:
* cy
* .get('@fetch')
* .should('be.calledWith', '/api/options');
*/
cy.spy(win, 'fetch').as('fetch');
});

17
tests-e2e/package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "tests-e2e",
"version": "1.0.0",
"description": "account.ely.by e2e test suit",
"main": "index.js",
"scripts": {
"test": "cypress open"
},
"keywords": [],
"author": "SleepWalker <dev@udf.su>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"cypress": "^2.0.0",
"prettier": "^1.10.2"
}
}

1022
tests-e2e/yarn.lock Normal file

File diff suppressed because it is too large Load Diff