From 1c2384258b758899790a109906262aebf6e07832 Mon Sep 17 00:00:00 2001 From: Chris Beer <cabeer@stanford.edu> Date: Wed, 16 Sep 2020 10:04:03 -0700 Subject: [PATCH] Re-fetch info.json documents after logging out --- __tests__/src/sagas/auth.test.js | 16 ++++++++++++++++ __tests__/src/sagas/iiif.test.js | 23 ++--------------------- src/state/sagas/auth.js | 12 +++++++++++- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/__tests__/src/sagas/auth.test.js b/__tests__/src/sagas/auth.test.js index f4979f7bf..5eebb7227 100644 --- a/__tests__/src/sagas/auth.test.js +++ b/__tests__/src/sagas/auth.test.js @@ -5,6 +5,7 @@ import serviceFixture from '../../fixtures/version-2/canvasService.json'; import ActionTypes from '../../../src/state/actions/action-types'; import { refetchInfoResponses, + refetchInfoResponsesOnLogout, } from '../../../src/state/sagas/auth'; import { fetchInfoResponse, @@ -17,6 +18,21 @@ import { } from '../../../src/state/selectors'; describe('IIIF Authentication sagas', () => { + describe('refetchInfoResponsesOnLogout', () => { + it('delays and then refetches info responses', () => { + const tokenServiceId = 'whatever'; + /** stub out delay... ugh. */ + const provideDelay = ({ fn }, next) => ((fn.name === 'delayP') ? null : next()); + + return expectSaga(refetchInfoResponsesOnLogout, { tokenServiceId }) + .provide([ + { call: provideDelay }, + [call(refetchInfoResponses, { serviceId: tokenServiceId }), {}], + ]) + .call(refetchInfoResponses, { serviceId: tokenServiceId }) + .run(); + }); + }); describe('refetchInfoResponses', () => { it('discards info responses that could hvae used the new access token', () => { const serviceId = 'https://authentication.example.org/token'; diff --git a/__tests__/src/sagas/iiif.test.js b/__tests__/src/sagas/iiif.test.js index c1dea0d21..6ca83b90a 100644 --- a/__tests__/src/sagas/iiif.test.js +++ b/__tests__/src/sagas/iiif.test.js @@ -1,11 +1,10 @@ -import { call, select } from 'redux-saga/effects'; -import { expectSaga, testSaga } from 'redux-saga-test-plan'; +import { select } from 'redux-saga/effects'; +import { expectSaga } from 'redux-saga-test-plan'; import { fetchAnnotation, fetchManifest, fetchSearchResponse, fetchInfoResponse, - refetchInfoResponses, fetchResourceManifest, } from '../../../src/state/sagas/iiif'; import { @@ -217,24 +216,6 @@ describe('IIIF sagas', () => { }); }); - describe('refetchInfoResponses', () => { - it('refetches info responses when a new access token is available', () => { - const serviceId = 'serviceId'; - const tokenService = { id: serviceId, infoIds: ['x', 'y'] }; - - testSaga(refetchInfoResponses, { serviceId }) - .next() - .select(getAccessTokens) - .next({ serviceId: tokenService }) - .all([ - call(fetchInfoResponse, { infoId: 'x', tokenService }), - call(fetchInfoResponse, { infoId: 'y', tokenService }), - ]) - .next() - .put({ serviceId, type: 'mirador/CLEAR_ACCESS_TOKEN_QUEUE' }); - }); - }); - describe('fetchSearchResponse', () => { it('fetches a IIIF search', () => { fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); diff --git a/src/state/sagas/auth.js b/src/state/sagas/auth.js index 23fafe717..10f9c7fda 100644 --- a/src/state/sagas/auth.js +++ b/src/state/sagas/auth.js @@ -1,5 +1,5 @@ import { - all, call, put, select, takeEvery, + all, call, put, select, takeEvery, delay, } from 'redux-saga/effects'; import { Utils } from 'manifesto.js/dist-esmodule/Utils'; import flatten from 'lodash/flatten'; @@ -12,6 +12,15 @@ import { } from '../selectors'; import { fetchInfoResponse } from './iiif'; +/** */ +export function* refetchInfoResponsesOnLogout({ tokenServiceId }) { + // delay logout actions to give the cookie service a chance to invalidate our cookies + // before we reinitialize openseadragon and rerequest images. + + yield delay(2000); + yield call(refetchInfoResponses, { serviceId: tokenServiceId }); +} + /** * Figure out what info responses could have used the access token service and: * - refetch, if they are currently visible @@ -55,5 +64,6 @@ export function* refetchInfoResponses({ serviceId }) { export default function* authSaga() { yield all([ takeEvery(ActionTypes.RECEIVE_ACCESS_TOKEN, refetchInfoResponses), + takeEvery(ActionTypes.RESET_AUTHENTICATION_STATE, refetchInfoResponsesOnLogout), ]); } -- GitLab