From 321eb4b2fd6d7ef7cfe8318dc87b14eb64c152ad Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 16 Mar 2020 15:22:27 -0300 Subject: [PATCH] 16029: Tests login with valid & expired tokens. Exposes a bug. When using an expired/invalid token, workbench2 doesn't do anything, it should at least show the login page. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- cypress/integration/login.spec.js | 46 ++++++++++--------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/cypress/integration/login.spec.js b/cypress/integration/login.spec.js index 1082819c..16ef915b 100644 --- a/cypress/integration/login.spec.js +++ b/cypress/integration/login.spec.js @@ -4,47 +4,29 @@ describe('Login tests', function() { before(function() { - this.email = `account_${Math.random()}@example.com` - this.password = Math.random() - this.firstName = 'Test' - this.lastName = 'User' + cy.resetDB(); }) beforeEach(function() { - cy.visit('/') - cy.contains('Please log in') - cy.get('button').contains('Log in').click() - cy.url().should('contain', "/users/sign_in") - }) - - it('register a new user', function() { - cy.get('a[role=button]').contains('Sign up for a new account').click() - cy.url().should('contain', '/users/sign_up') - cy.get('input[name="user[first_name]"]').type(this.firstName) - cy.get('input[name="user[last_name]"]').type(this.lastName) - cy.get('input[name="user[email]"]').type(this.email) - cy.get('input[name="user[password]"]').type(this.password) - cy.get('input[name="user[password_confirmation]"]').type(this.password) - cy.get('input[type=submit]').contains('Sign up').click() - cy.url().should('contain', '/projects/') - cy.get('button[title="Account Management"]').click() - cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`) + cy.arvadosFixture('users').as('users') + cy.arvadosFixture('api_client_authorizations').as('client_auth') + cy.clearCookies() + cy.clearLocalStorage() }) it('logs in successfully', function() { - cy.get('input[type=email]').type(this.email) - cy.get('input[type=password]').type(this.password) - cy.get('input[type=submit]').contains('Sign in').click() + const active_user = this.users['active'] + const active_token = this.client_auth['active']['api_token'] + cy.visit('/token/?api_token='+active_token) cy.url().should('contain', '/projects/') cy.get('button[title="Account Management"]').click() - cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`) + cy.get('ul[role=menu] > li[role=menuitem]').contains(`${active_user['first_name']} ${active_user['last_name']}`) }) - it('fails to log in with incorrect password', function() { - cy.get('input[type=email]').type(this.email) - cy.get('input[type=password]').type('incorrect') - cy.get('input[type=submit]').contains('Sign in').click() - cy.url().should('contain', "/users/sign_in") - cy.get('div.alert').contains('Invalid email or password') + it('fails to log in with expired token', function() { + const expired_token = this.client_auth['expired']['api_token'] + cy.visit('/token/?api_token='+expired_token) + cy.contains('Please log in') + cy.url().should('not.contain', '/projects/') }) }) \ No newline at end of file -- 2.30.2