16029: Tests login with valid & expired tokens. Exposes a bug.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 16 Mar 2020 18:22:27 +0000 (15:22 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 16 Mar 2020 18:22:27 +0000 (15:22 -0300)
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 <lucas@di-pentima.com.ar>

cypress/integration/login.spec.js

index 1082819c56295c314d84f2b7682428f85dadf34e..16ef915bdbea5ecbb4a197acbed79bcd6df73f9a 100644 (file)
@@ -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