Skip to content

Commit

Permalink
feat: Add more credentials tests (#3668)
Browse files Browse the repository at this point in the history
* ✨  Add injection to notion,
Add test to notion in cred

* 🔥 Remove unuse method

* 🎨  Move testing from node file to cred file

* ✨ Add injection and testing in facebook graph

* Add cred injec with testing

* Add Cred injection and cred test

* Add cred injection, and cred testing for typeform, fix issue in clickup

* Add cred injection, move testing inside creds

* Add cred injection and cred testing to SendGrid

* Add cred injection and cred testing to woocommerce

* Add cred injection, add cred test to gitlab

* 🔥 Fix duplicated imports in Mautic cred

* 🔥 removed unused credentials testing in node

* Add cred injection, cred testing, handles slash trailing for Grafana node

* Add cred injection,  cred testing to shopify

* Add cred injection , add cred testing to stripe

* changed cred injection, add testing to cred for mattermost

* add cred injection and testing for dropbox

* Add cred injection, cred testing to webflow

* ✨ Add cred injection and cred test to nocodb

* ✨ Add cred injection, cred testing to mailchimp

* 🐛 fix a bug In credentials testing

* ✨ Add cred injection, cred testing to sms77

* ✨ Add cred injection, cred testing to ActiveCampaign

* Add cred injection, cred testing to TheHive

* ✨ Add cred injection, add cred testing to ApiTemplateio

* ✨ Add cred injection, add cred testing for zoom

* ✨ Add cred injection, cred testing to rocketchat

* ✨ Add cred injection, add cred test to getResponse

* 🔥 Remove useless authentcate creds and testing from facebookGraphApp

* 🔥 Remove useless imports in FacebookGrappApp credentials file

* 🔥 Removed useless imports and if statement

* 🐛 Add version to header when testing cred

Co-authored-by: Omar Ajoue <[email protected]>
Co-authored-by: Jan Oberhauser <[email protected]>
  • Loading branch information
3 people authored Jul 15, 2022
1 parent 945e25a commit 683d2df
Show file tree
Hide file tree
Showing 52 changed files with 387 additions and 254 deletions.
16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/ActiveCampaignApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -22,4 +24,18 @@ export class ActiveCampaignApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'Api-Token': '={{$credentials.apiKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.apiUrl}}',
url: '/api/3/fields',
},
};
}
16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/ApiTemplateIoApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -15,4 +17,18 @@ export class ApiTemplateIoApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'X-API-KEY': '={{$credentials.apiKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.apitemplate.io/v1',
url: '/list-templates',
},
};
}
17 changes: 17 additions & 0 deletions packages/nodes-base/credentials/ClickUpApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -15,4 +17,19 @@ export class ClickUpApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '={{$credentials.accessToken}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.clickup.com/api/v2',
url: '/team',
},
};
}
21 changes: 20 additions & 1 deletion packages/nodes-base/credentials/DropboxApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
IAuthenticateGeneric,
ICredentialTestFunction,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
INodeProperties
} from 'n8n-workflow';

export class DropboxApi implements ICredentialType {
Expand Down Expand Up @@ -31,4 +34,20 @@ export class DropboxApi implements ICredentialType {
default: 'full',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.dropboxapi.com/2',
url: '/users/get_current_account',
method: 'POST',
},
};
}
16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/FacebookGraphApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -16,4 +18,18 @@ export class FacebookGraphApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
qs: {
access_token: '={{$credentials.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://graph.facebook.com/v8.0',
url: '/me',
},
};
}
16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/GetResponseApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -15,4 +17,18 @@ export class GetResponseApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'X-Auth-Token': '=api-key {{$credentials.apiKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.getresponse.com/v3',
url: '/campaigns',
},
};
}
17 changes: 17 additions & 0 deletions packages/nodes-base/credentials/GitlabApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -22,4 +24,19 @@ export class GitlabApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'Private-Token': '={{$credentials.accessToken}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.server.replace(new RegExp("/$"), "") + "/api/v4" }}',
url: '/users',
},
};
}
17 changes: 17 additions & 0 deletions packages/nodes-base/credentials/GrafanaApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -25,4 +27,19 @@ export class GrafanaApi implements ICredentialType {
required: true,
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.baseUrl.replace(new RegExp("/$"), "") + "/api" }}',
url: '/folders',
},
};
}
17 changes: 17 additions & 0 deletions packages/nodes-base/credentials/MailchimpApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
IAuthenticateGeneric,
ICredentialTestFunctions,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -15,4 +18,18 @@ export class MailchimpApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type:'generic',
properties:{
headers:{
Authorization: '=apikey {{$credentials.apiKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '=https://{{$credentials.apiKey.split("-").pop()}}.api.mailchimp.com/3.0',
url: '/lists',
},
};
}
20 changes: 16 additions & 4 deletions packages/nodes-base/credentials/MattermostApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
IAuthenticateGeneric,
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
Expand All @@ -24,8 +26,18 @@ export class MattermostApi implements ICredentialType {
default: '',
},
];
async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
requestOptions.headers!['Authorization'] = `Bearer ${credentials.accessToken}`;
return requestOptions;
}
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.baseUrl}}/api/v4',
url: '/users',
},
};
}
31 changes: 29 additions & 2 deletions packages/nodes-base/credentials/MauticApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
ICredentialType,
INodeProperties,
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';

export class MauticApi implements ICredentialType {
Expand Down Expand Up @@ -31,4 +34,28 @@ export class MauticApi implements ICredentialType {
default: '',
},
];
async authenticate (credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
const {
url,
username,
password,
} = credentials as {
url: string,
username: string,
password: string,
};
const credentialUrl = url.endsWith('/') ? `${url}api/users/self` : `${url}/api/users/self`;
const base64Key = Buffer.from(`${username}:${password}`).toString('base64');
requestOptions.headers!['Authorization'] = `Basic ${base64Key}`;
requestOptions.url = credentialUrl ? credentialUrl : requestOptions.url;

return requestOptions;
}

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.url.replace(new RegExp("/$"), "")}}',
url: '/api/users/self',
},
};
}
16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/NocoDb.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -23,4 +25,18 @@ export class NocoDb implements ICredentialType {
placeholder: 'http(s)://localhost:8080',
},
];
authenticate: IAuthenticateGeneric = {
type:'generic',
properties: {
headers:{
'xc-auth': '={{credentials.apiToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.host}}',
url: '/lists',
},
};
}
1 change: 1 addition & 0 deletions packages/nodes-base/credentials/NotionApi.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class NotionApi implements ICredentialType {
properties: {
headers: {
'Authorization': '=Bearer {{$credentials.apiKey}}',
'Notion-Version': '2021-05-13',
},
},
};
Expand Down
17 changes: 17 additions & 0 deletions packages/nodes-base/credentials/RocketchatApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand Down Expand Up @@ -29,4 +31,19 @@ export class RocketchatApi implements ICredentialType {
placeholder: 'https://n8n.rocket.chat',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'X-Auth-Token': '={{$credentials.authKey}}',
'X-User-Id': '={{$credentials.userId}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.domain}}',
url: '/api/v1/webdav.getMyAccounts',
},
};
}
Loading

0 comments on commit 683d2df

Please sign in to comment.