[ARVADOS-WORKBENCH2] updated: 1.4.1-452-gd924f14c

Git user git at public.arvados.org
Fri Oct 2 21:41:56 UTC 2020


Summary of changes:
 src/store/auth/auth-action-session.ts | 28 +++++++++--------
 src/store/auth/auth-action.test.ts    | 59 ++++++++++++++++++++++++-----------
 2 files changed, 55 insertions(+), 32 deletions(-)

       via  d924f14c5a81265fbd0f550ccf498fe791fc5b54 (commit)
      from  0ca7039728489e25ae1e196278454e7bafbca948 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit d924f14c5a81265fbd0f550ccf498fe791fc5b54
Author: Peter Amstutz <peter.amstutz at curii.com>
Date:   Fri Oct 2 17:40:19 2020 -0400

    16941: Make it possible to mock retrieving cluster config
    
    Fix auth-action.test using cluster config mock.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>

diff --git a/src/store/auth/auth-action-session.ts b/src/store/auth/auth-action-session.ts
index 5fc8cffb..f0093f9f 100644
--- a/src/store/auth/auth-action-session.ts
+++ b/src/store/auth/auth-action-session.ts
@@ -20,10 +20,10 @@ import { AuthService } from "~/services/auth-service/auth-service";
 import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
 import * as jsSHA from "jssha";
 
-const getClusterConfig = async (origin: string): Promise<Config | null> => {
+const getClusterConfig = async (origin: string, apiClient: AxiosInstance): Promise<Config | null> => {
     let configFromDD: Config | undefined;
     try {
-        const dd = (await Axios.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
+        const dd = (await apiClient.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
         configFromDD = {
             baseUrl: normalizeURLPath(dd.baseUrl),
             keepWebServiceUrl: dd.keepWebServiceUrl,
@@ -41,9 +41,9 @@ const getClusterConfig = async (origin: string): Promise<Config | null> => {
         };
     } catch { }
 
-    // Try the new public config endpoint
+    // Try public config endpoint
     try {
-        const config = (await Axios.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
+        const config = (await apiClient.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
         return { ...buildConfig(config), apiRevision: configFromDD ? configFromDD.apiRevision : 0 };
     } catch { }
 
@@ -55,7 +55,9 @@ const getClusterConfig = async (origin: string): Promise<Config | null> => {
     return null;
 };
 
-const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> => {
+const getRemoteHostConfig = async (remoteHost: string, useApiClient?: AxiosInstance): Promise<Config | null> => {
+    const apiClient = useApiClient || Axios.create({ headers: {} });
+
     let url = remoteHost;
     if (url.indexOf('://') < 0) {
         url = 'https://' + url;
@@ -63,14 +65,14 @@ const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> =
     const origin = new URL(url).origin;
 
     // Maybe it is an API server URL, try fetching config and discovery doc
-    let r = await getClusterConfig(origin);
+    let r = await getClusterConfig(origin, apiClient);
     if (r !== null) {
         return r;
     }
 
     // Maybe it is a Workbench2 URL, try getting config.json
     try {
-        r = await getClusterConfig((await Axios.get<any>(`${origin}/config.json`)).data.API_HOST);
+        r = await getClusterConfig((await apiClient.get<any>(`${origin}/config.json`)).data.API_HOST, apiClient);
         if (r !== null) {
             return r;
         }
@@ -78,7 +80,7 @@ const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> =
 
     // Maybe it is a Workbench1 URL, try getting status.json
     try {
-        r = await getClusterConfig((await Axios.get<any>(`${origin}/status.json`)).data.apiBaseURL);
+        r = await getClusterConfig((await apiClient.get<any>(`${origin}/status.json`)).data.apiBaseURL, apiClient);
         if (r !== null) {
             return r;
         }
@@ -121,7 +123,7 @@ export const validateCluster = async (config: Config, useToken: string):
     };
 };
 
-export const validateSession = (session: Session, activeSession: Session) =>
+export const validateSession = (session: Session, activeSession: Session, useApiClient?: AxiosInstance) =>
     async (dispatch: Dispatch): Promise<Session> => {
         dispatch(authActions.UPDATE_SESSION({ ...session, status: SessionStatus.BEING_VALIDATED }));
         session.loggedIn = false;
@@ -138,7 +140,7 @@ export const validateSession = (session: Session, activeSession: Session) =>
         };
 
         let fail: Error | null = null;
-        const config = await getRemoteHostConfig(session.remoteHost);
+        const config = await getRemoteHostConfig(session.remoteHost, useApiClient);
         if (config !== null) {
             dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config }));
             try {
@@ -169,7 +171,7 @@ export const validateSession = (session: Session, activeSession: Session) =>
         return session;
     };
 
-export const validateSessions = () =>
+export const validateSessions = (useApiClient?: AxiosInstance) =>
     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
         const sessions = getState().auth.sessions;
         const activeSession = getActiveSession(sessions);
@@ -187,7 +189,7 @@ export const validateSessions = () =>
 			   override it using Dispatch<any>.  This
 			   pattern is used in a bunch of different
 			   places in Workbench2. */
-                        await dispatch(validateSession(session, activeSession));
+                        await dispatch(validateSession(session, activeSession, useApiClient));
                     } catch (e) {
                         dispatch(snackbarActions.OPEN_SNACKBAR({
                             message: e.message,
@@ -311,7 +313,7 @@ export const initSessions = (authService: AuthService, config: Config, user: Use
     (dispatch: Dispatch<any>) => {
         const sessions = authService.buildSessions(config, user);
         dispatch(authActions.SET_SESSIONS(sessions));
-        dispatch(validateSessions());
+        dispatch(validateSessions(authService.apiClient));
     };
 
 export const loadSiteManagerPanel = () =>
diff --git a/src/store/auth/auth-action.test.ts b/src/store/auth/auth-action.test.ts
index 8a17fe9f..83a699a7 100644
--- a/src/store/auth/auth-action.test.ts
+++ b/src/store/auth/auth-action.test.ts
@@ -9,7 +9,7 @@ import 'jest-localstorage-mock';
 import { ServiceRepository, createServices } from "~/services/services";
 import { configureStore, RootStore } from "../store";
 import { createBrowserHistory } from "history";
-import { mockConfig } from '~/common/config';
+import { mockConfig, DISCOVERY_DOC_PATH, } from '~/common/config';
 import { ApiActions } from "~/services/api/api-actions";
 import { ACCOUNT_LINK_STATUS_KEY } from '~/services/link-account-service/link-account-service';
 import Axios from "axios";
@@ -57,6 +57,20 @@ describe('auth-actions', () => {
                 prefs: {}
             });
 
+        axiosMock
+            .onGet("https://xc59z.arvadosapi.com/discovery/v1/apis/arvados/v1/rest")
+            .reply(200, {
+                baseUrl: "https://xc59z.arvadosapi.com/arvados/v1",
+                keepWebServiceUrl: "",
+                remoteHosts: {},
+                rootUrl: "https://xc59z.arvadosapi.com",
+                uuidPrefix: "xc59z",
+                websocketUrl: "",
+                workbenchUrl: "",
+                workbench2Url: "",
+                revision: 12345678
+            });
+
         importMocks.push(ImportMock.mockFunction(servicesModule, 'createServices', services));
 
         // Only test the case when a link account operation is not being cancelled
@@ -103,6 +117,12 @@ describe('auth-actions', () => {
                                 "rootUrl": "https://zzzzz.arvadosapi.com",
                                 "uuidPrefix": "zzzzz",
                             },
+                            "xc59z": mockConfig({
+                                apiRevision: 12345678,
+                                baseUrl: "https://xc59z.arvadosapi.com/arvados/v1",
+                                rootUrl: "https://xc59z.arvadosapi.com",
+                                uuidPrefix: "xc59z"
+                            })
                         },
                         remoteHosts: {
                             zzzzz: "zzzzz.arvadosapi.com",
@@ -120,6 +140,7 @@ describe('auth-actions', () => {
                             "name": "John Doe",
                             "apiRevision": 12345678,
                             "uuid": "zzzzz-tpzed-abcefg",
+                            "userIsActive": true
                         }, {
                             "active": false,
                             "baseUrl": "",
@@ -156,22 +177,22 @@ describe('auth-actions', () => {
 
     // TODO: Add remaining action tests
     /*
-    it('should fire external url to login', () => {
-        const initialState = undefined;
-        window.location.assign = jest.fn();
-        reducer(initialState, authActions.LOGIN());
-        expect(window.location.assign).toBeCalledWith(
-            `/login?return_to=${window.location.protocol}//${window.location.host}/token`
-        );
-    });
-
-    it('should fire external url to logout', () => {
-        const initialState = undefined;
-        window.location.assign = jest.fn();
-        reducer(initialState, authActions.LOGOUT());
-        expect(window.location.assign).toBeCalledWith(
-            `/logout?return_to=${location.protocol}//${location.host}`
-        );
-    });
-    */
+       it('should fire external url to login', () => {
+       const initialState = undefined;
+       window.location.assign = jest.fn();
+       reducer(initialState, authActions.LOGIN());
+       expect(window.location.assign).toBeCalledWith(
+       `/login?return_to=${window.location.protocol}//${window.location.host}/token`
+       );
+       });
+
+       it('should fire external url to logout', () => {
+       const initialState = undefined;
+       window.location.assign = jest.fn();
+       reducer(initialState, authActions.LOGOUT());
+       expect(window.location.assign).toBeCalledWith(
+       `/logout?return_to=${location.protocol}//${location.host}`
+       );
+       });
+     */
 });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list