Skip to content

Commit

Permalink
Merge pull request #6 from nuclia/test-connectors
Browse files Browse the repository at this point in the history
test: Add tests for refresh_endpoint param in oauth connectors
  • Loading branch information
ebrehault authored Jan 16, 2024
2 parents 2d9380c + 91bc4ef commit a72620d
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down

0 comments on commit a72620d

Please sign in to comment.