Merge branch '16680-expired-token-handling'
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 2 Sep 2020 14:22:26 +0000 (11:22 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 2 Sep 2020 14:22:26 +0000 (11:22 -0300)
Closes #16680

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

cypress/integration/login.spec.js
docker/Dockerfile
src/index.tsx
src/services/common-service/common-service.ts

index c30124d8f2f9dfae5f63114953d82ac2640a383c..d88c7a6cfa7252a0825de0ba357a87c418947c14 100644 (file)
@@ -78,6 +78,25 @@ describe('Login tests', function() {
             `${activeUser.user.first_name} ${activeUser.user.last_name}`);
     })
 
+    it('logs out when token no longer valid', function() {
+        // Log in
+        cy.visit(`/token/?api_token=${activeUser.token}`);
+        cy.url().should('contain', '/projects/');
+        cy.get('div#root').should('contain', 'Arvados Workbench (zzzzz)');
+        cy.get('div#root').should('not.contain', 'Your account is inactive');
+        // Invalidate own token.
+        const tokenUuid = activeUser.token.split('/')[1];
+        cy.doRequest('PUT', `/arvados/v1/api_client_authorizations/${tokenUuid}`, {
+            id: tokenUuid,
+            api_client_authorization: JSON.stringify({
+                api_token: `randomToken${Math.floor(Math.random() * Math.floor(999999))}`
+            })
+        }, null, activeUser.token, true);
+        // Should log the user out.
+        cy.get('[data-cy=breadcrumb-first]').click();
+        cy.get('div#root').should('contain', 'Please log in');
+    })
+
     it('logs in successfully with valid admin token', function() {
         cy.visit(`/token/?api_token=${adminUser.token}`);
         cy.url().should('contain', '/projects/');
index e134dca09cd8227a7099463a4473582341cbcf7c..f138e842e00d46940f915b29ac8e433afda5b9fd 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0
 
 FROM node:8-buster
-MAINTAINER MAINTAINER Arvados Package Maintainers <packaging@arvados.org>
+LABEL maintainer="Arvados Package Maintainers <packaging@arvados.org>"
 
 RUN echo deb http://deb.debian.org/debian buster-backports main >> /etc/apt/sources.list.d/backports.list
 RUN apt-get update && \
index d07d3c9e025d870077445af3e79a0078c589a763..0a51ed3c8ab94c9fab61d80325f429428ea098d2 100644 (file)
@@ -14,7 +14,7 @@ import { configureStore, RootStore } from '~/store/store';
 import { ConnectedRouter } from "react-router-redux";
 import { ApiToken } from "~/views-components/api-token/api-token";
 import { AddSession } from "~/views-components/add-session/add-session";
-import { initAuth } from "~/store/auth/auth-action";
+import { initAuth, logout } from "~/store/auth/auth-action";
 import { createServices } from "~/services/services";
 import { MuiThemeProvider } from '@material-ui/core/styles';
 import { CustomTheme } from '~/common/custom-theme';
@@ -108,8 +108,10 @@ fetchConfig()
                 if (showSnackBar) {
                     console.error("Backend error:", error);
 
-                    if (error.errors[0].indexOf("not found") > -1) {
+                    if (error.status === 404) {
                         store.dispatch(openNotFoundDialog());
+                    } else if (error.status === 401 && error.errors[0].indexOf("Not logged in") > -1) {
+                        store.dispatch(logout());
                     } else {
                         store.dispatch(snackbarActions.OPEN_SNACKBAR({
                             message: `${error.errors
index e00a3d7d43b6ece7be78e55d1e67a0cd5dfe7fda..d605611f46143d8a044379fc56237b2ee7f52fa9 100644 (file)
@@ -9,6 +9,7 @@ import { ApiActions } from "~/services/api/api-actions";
 import * as QueryString from "query-string";
 
 interface Errors {
+    status: number;
     errors: string[];
     errorToken: string;
 }
@@ -80,6 +81,7 @@ export class CommonService<T> {
             .catch(({ response }) => {
                 actions.progressFn(reqId, false);
                 const errors = CommonService.mapResponseKeys(response) as Errors;
+                errors.status = response.status;
                 actions.errorFn(reqId, errors, showErrors);
                 throw errors;
             });