diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index 88969b1d0a..5a088fa274 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -160,8 +160,9 @@ export default class Provider extends RequestClient { await this.#refreshingTokenPromise try { - // throw Object.assign(new Error(), { isAuthError: true }) // testing simulate access token expired (to refresh token) - // A better way to test this is for example with Google Drive: + // to test simulate access token expired (leading to a token token refresh), + // see mockAccessTokenExpiredError in companion/drive. + // If you want to test refresh token *and* access token invalid, do this for example with Google Drive: // While uploading, go to your google account settings, // "Third-party apps & services", then click "Companion" and "Remove access". diff --git a/packages/@uppy/companion/src/server/provider/drive/index.js b/packages/@uppy/companion/src/server/provider/drive/index.js index a5dd5f185f..f0b4e9a850 100644 --- a/packages/@uppy/companion/src/server/provider/drive/index.js +++ b/packages/@uppy/companion/src/server/provider/drive/index.js @@ -5,6 +5,16 @@ const logger = require('../../logger') const { VIRTUAL_SHARED_DIR, adaptData, isShortcut, isGsuiteFile, getGsuiteExportType } = require('./adapter') const { withProviderErrorHandling } = require('../providerErrors') const { prepareStream } = require('../../helpers/utils') +const { ProviderAuthError } = require('../error') + + +// For testing refresh token: +// first run a download with mockAccessTokenExpiredError = true +// then when you want to test expiry, set to mockAccessTokenExpiredError to the logged access token +// This will trigger companion/nodemon to restart, and it will respond with a simulated invalid token response +const mockAccessTokenExpiredError = undefined +// const mockAccessTokenExpiredError = true +// const mockAccessTokenExpiredError = '' const DRIVE_FILE_FIELDS = 'kind,id,imageMediaMetadata,name,mimeType,ownedByMe,size,modifiedTime,iconLink,thumbnailLink,teamDriveId,videoMediaMetadata,shortcutDetails(targetId,targetMimeType)' const DRIVE_FILES_FIELDS = `kind,nextPageToken,incompleteSearch,files(${DRIVE_FILE_FIELDS})` @@ -117,6 +127,15 @@ class Drive extends Provider { } async download ({ id: idIn, token }) { + if (mockAccessTokenExpiredError != null) { + logger.warn(`Access token: ${token}`) + + if (mockAccessTokenExpiredError === token) { + logger.warn('Mocking expired access token!') + throw new ProviderAuthError() + } + } + return this.#withErrorHandling('provider.drive.download.error', async () => { const client = getClient({ token })