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,
};
} 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 { }
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;
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;
}
// 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;
}
};
};
-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;
};
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 {
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);
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,
(dispatch: Dispatch<any>) => {
const sessions = authService.buildSessions(config, user);
dispatch(authActions.SET_SESSIONS(sessions));
- dispatch(validateSessions());
+ dispatch(validateSessions(authService.apiClient));
};
export const loadSiteManagerPanel = () =>
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";
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
"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",
"name": "John Doe",
"apiRevision": 12345678,
"uuid": "zzzzz-tpzed-abcefg",
+ "userIsActive": true
}, {
"active": false,
"baseUrl": "",
// 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}`
+ );
+ });
+ */
});