From 91bc4efd7778d83eebe89090bb6505cacaf4cd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Boixader=20G=C3=BCell?= Date: Tue, 16 Jan 2024 08:04:45 +0100 Subject: [PATCH] test: Add tests for refresh_endpoint param in oauth connectors --- .../connectors/dropbox.connector.ts | 5 +++++ .../connectors/gdrive.connector.ts | 6 ++++++ .../connectors/onedrive.connector.ts | 5 +++++ .../connectors/sharepoint.connector.ts | 5 +++++ .../tests/dropbox.connector.spec.js | 21 +++++++++++++++++++ .../connectors/tests/gdrive.connector.spec.js | 21 +++++++++++++++++++ .../tests/onedrive.connector.spec.js | 21 +++++++++++++++++++ .../tests/sharepoint.connector.spec.js | 21 +++++++++++++++++++ 8 files changed, 105 insertions(+) diff --git a/server/src/logic/connector/infrastructure/connectors/dropbox.connector.ts b/server/src/logic/connector/infrastructure/connectors/dropbox.connector.ts index cdaf656..92e2f31 100644 --- a/server/src/logic/connector/infrastructure/connectors/dropbox.connector.ts +++ b/server/src/logic/connector/infrastructure/connectors/dropbox.connector.ts @@ -32,6 +32,11 @@ export class DropboxImpl extends OAuthBaseConnector implements IConnector { if (!params?.refresh) { return false; } + try { + new URL(params.refresh_endpoint); + } catch (err) { + return false; + } return true; } diff --git a/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts b/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts index c0fe68f..68d7ba3 100644 --- a/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts +++ b/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts @@ -32,6 +32,12 @@ export class GDriveImpl extends OAuthBaseConnector implements IConnector { if (!params?.refresh) { return false; } + try { + new URL(params.refresh_endpoint); + } catch (err) { + return false; + } + return true; } diff --git a/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts b/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts index f73ac1b..caf911c 100644 --- a/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts +++ b/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts @@ -32,6 +32,11 @@ export class OneDriveImpl extends OAuthBaseConnector implements IConnector { if (!params?.refresh) { return false; } + try { + new URL(params.refresh_endpoint); + } catch (err) { + return false; + } return true; } diff --git a/server/src/logic/connector/infrastructure/connectors/sharepoint.connector.ts b/server/src/logic/connector/infrastructure/connectors/sharepoint.connector.ts index 8ea39e6..8f763a4 100644 --- a/server/src/logic/connector/infrastructure/connectors/sharepoint.connector.ts +++ b/server/src/logic/connector/infrastructure/connectors/sharepoint.connector.ts @@ -32,6 +32,11 @@ export class SharepointImpl extends OAuthBaseConnector implements IConnector { if (!params?.refresh) { return false; } + try { + new URL(params.refresh_endpoint); + } catch (err) { + return false; + } return true; } diff --git a/server/src/logic/connector/infrastructure/connectors/tests/dropbox.connector.spec.js b/server/src/logic/connector/infrastructure/connectors/tests/dropbox.connector.spec.js index 2dd4f94..51d6f92 100644 --- a/server/src/logic/connector/infrastructure/connectors/tests/dropbox.connector.spec.js +++ b/server/src/logic/connector/infrastructure/connectors/tests/dropbox.connector.spec.js @@ -75,11 +75,31 @@ describe('Test validate dropbox params', () => { ).toBe(false); }); + dropboxTest('Incorrect - With wrong params - two valid', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + }), + ).toBe(false); + }); + + dropboxTest('Incorrect - With wrong params - invalid url', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + refresh_endpoint: 'invalid_url', + }), + ).toBe(false); + }); + dropboxTest('Incorrect - With empty params', ({ sourceConnector }) => { expect( sourceConnector.areParametersValid({ token: '', refresh: '', + refresh_endpoint: '', }), ).toBe(false); }); @@ -89,6 +109,7 @@ describe('Test validate dropbox params', () => { sourceConnector.areParametersValid({ token: 'test', refresh: 'test', + refresh_endpoint: 'https://stashify.cloud/api/external_auth/gdrive/refresh', }), ).toBe(true); }); diff --git a/server/src/logic/connector/infrastructure/connectors/tests/gdrive.connector.spec.js b/server/src/logic/connector/infrastructure/connectors/tests/gdrive.connector.spec.js index b9fa14f..d696928 100644 --- a/server/src/logic/connector/infrastructure/connectors/tests/gdrive.connector.spec.js +++ b/server/src/logic/connector/infrastructure/connectors/tests/gdrive.connector.spec.js @@ -84,11 +84,31 @@ describe('Test validate gdrive params', () => { ).toBe(false); }); + gDriveTest('Incorrect - With wrong params - two valid', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + }), + ).toBe(false); + }); + + gDriveTest('Incorrect - With wrong params - invalid url', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + refresh_endpoint: 'invalid_url', + }), + ).toBe(false); + }); + gDriveTest('Incorrect - With empty params', ({ sourceConnector }) => { expect( sourceConnector.areParametersValid({ token: '', refresh: '', + refresh_endpoint: '', }), ).toBe(false); }); @@ -98,6 +118,7 @@ describe('Test validate gdrive params', () => { sourceConnector.areParametersValid({ token: 'test', refresh: 'test', + refresh_endpoint: 'https://stashify.cloud/api/external_auth/gdrive/refresh', }), ).toBe(true); }); diff --git a/server/src/logic/connector/infrastructure/connectors/tests/onedrive.connector.spec.js b/server/src/logic/connector/infrastructure/connectors/tests/onedrive.connector.spec.js index b1084b0..f45b3bc 100644 --- a/server/src/logic/connector/infrastructure/connectors/tests/onedrive.connector.spec.js +++ b/server/src/logic/connector/infrastructure/connectors/tests/onedrive.connector.spec.js @@ -84,11 +84,31 @@ describe('Test validate gdrive params', () => { ).toBe(false); }); + oneDriveTest('Incorrect - With wrong params - invalid url', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + refresh_endpoint: 'invalid_url', + }), + ).toBe(false); + }); + + oneDriveTest('Incorrect - With wrong params - two valid', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + }), + ).toBe(false); + }); + oneDriveTest('Incorrect - With empty params', ({ sourceConnector }) => { expect( sourceConnector.areParametersValid({ token: '', refresh: '', + refresh_endpoint: '', }), ).toBe(false); }); @@ -98,6 +118,7 @@ describe('Test validate gdrive params', () => { sourceConnector.areParametersValid({ token: 'test', refresh: 'test', + refresh_endpoint: 'https://stashify.cloud/api/external_auth/gdrive/refresh', }), ).toBe(true); }); diff --git a/server/src/logic/connector/infrastructure/connectors/tests/sharepoint.connector.spec.js b/server/src/logic/connector/infrastructure/connectors/tests/sharepoint.connector.spec.js index 73a1880..598f68d 100644 --- a/server/src/logic/connector/infrastructure/connectors/tests/sharepoint.connector.spec.js +++ b/server/src/logic/connector/infrastructure/connectors/tests/sharepoint.connector.spec.js @@ -84,11 +84,31 @@ describe('Test validate sharepoint params', () => { ).toBe(false); }); + sharepointTest('Incorrect - With wrong params - two valid', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + }), + ).toBe(false); + }); + + sharepointTest('Incorrect - With wrong params - invalid url', ({ sourceConnector }) => { + expect( + sourceConnector.areParametersValid({ + token: 'test', + refresh: 'test', + refresh_endpoint: 'invalid_url', + }), + ).toBe(false); + }); + sharepointTest('Incorrect - With empty params', ({ sourceConnector }) => { expect( sourceConnector.areParametersValid({ token: '', refresh: '', + refresh_endpoint: '', }), ).toBe(false); }); @@ -98,6 +118,7 @@ describe('Test validate sharepoint params', () => { sourceConnector.areParametersValid({ token: 'test', refresh: 'test', + refresh_endpoint: 'https://stashify.cloud/api/external_auth/gdrive/refresh', }), ).toBe(true); });