Skip to content

Commit

Permalink
Decouple superset and opensrp states
Browse files Browse the repository at this point in the history
  • Loading branch information
ciremusyoka committed Oct 13, 2021
1 parent 3d4cc46 commit 56d1172
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,6 @@ REACT_APP_SUPERSET_MDA_LITE_REPORTING_INDICATOR_STOPS=kenya2021
REACT_APP_CLIENTS_LIST_BATCH_SIZE=100

REACT_APP_AUTO_ENABLE_NAVIGATION_TO='/assign,/teams'
REACT_APP_REVOKE_COMPLETE_AND_RETIRED_PLANS_TEAM_ASSIGNMENTS=false
REACT_APP_REVOKE_COMPLETE_AND_RETIRED_PLANS_TEAM_ASSIGNMENTS=false

REACT_APP_SUPERSET_OAUTH_STATE=opensrp
3 changes: 3 additions & 0 deletions src/configs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ export type OPENSRP_USER_URL = typeof OPENSRP_USER_URL;
export const OPENSRP_OAUTH_STATE = setEnv('REACT_APP_OPENSRP_OAUTH_STATE', 'opensrp');
export type OPENSRP_OAUTH_STATE = typeof OPENSRP_OAUTH_STATE;

export const SUPERSET_OAUTH_STATE = setEnv('REACT_APP_SUPERSET_OAUTH_STATE', '');
export type SUPERSET_OAUTH_STATE = typeof SUPERSET_OAUTH_STATE;

export const OPENSRP_LOGOUT_URL = setEnv(
'REACT_APP_OPENSRP_LOGOUT_URL',
'https://reveal-stage.smartregister.org/opensrp/logout.do'
Expand Down
10 changes: 8 additions & 2 deletions src/services/superset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import reducerRegistry from '@onaio/redux-reducer-registry';
import { getOauthProviderState } from '@onaio/session-reducer';
import superset, { SupersetConnectorConfig } from '@onaio/superset-connector';
import { Dictionary } from '@onaio/utils';
import { OPENSRP_OAUTH_STATE, SUPERSET_API_BASE, SUPERSET_API_ENDPOINT } from '../../configs/env';
import {
OPENSRP_OAUTH_STATE,
SUPERSET_API_BASE,
SUPERSET_API_ENDPOINT,
SUPERSET_OAUTH_STATE,
} from '../../configs/env';
import { ERROR_PERMISSION_DENIED } from '../../configs/lang';
import { SUPERSET_ACCESS_DENIED_MESSAGE } from '../../constants';
import { displayError } from '../../helpers/errors';
Expand Down Expand Up @@ -60,7 +65,8 @@ const supersetFetch = async (
* to enable the use of multiple providers, we store the provider name in the
* `state` parameter so that we can use it here
*/
provider: getOauthProviderState(store.getState()) || OPENSRP_OAUTH_STATE,
provider:
SUPERSET_OAUTH_STATE || getOauthProviderState(store.getState()) || OPENSRP_OAUTH_STATE,
token: '',
};

Expand Down
26 changes: 26 additions & 0 deletions src/services/superset/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ describe('services/superset', () => {

expect(processDataMock).toHaveBeenCalledWith(fixtures.sliceResponse);
});

it('sets superset oauth state correctly', async () => {
store.dispatch(resetSuperset());

const envModule = require('../../../configs/env');
const supersetState = 'superset-oauth-state';
envModule.SUPERSET_OAUTH_STATE = supersetState;

const authZMock = jest.spyOn(superset, 'authZ');

fetchMock.get(`${SUPERSET_API_BASE}oauth-authorized/${supersetState}`, JSON.stringify({}));
fetchMock.get(
`${SUPERSET_API_BASE}superset/slice_json/1337`,
JSON.stringify(fixtures.sliceResponse)
);

await supersetFetch('1337');

expect(authZMock.mock.calls[0][0]).toEqual({
base: 'http://localhost',
endpoint: 'slice',
extraPath: '1337',
provider: supersetState,
token: '',
});
});
});

describe('services/superset/fetchCallback', () => {
Expand Down

0 comments on commit 56d1172

Please sign in to comment.