feat: Add more credentials tests (#3668)

*   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 <krynble@gmail.com>
Co-authored-by: Jan Oberhauser <janober@users.noreply.github.com>
This commit is contained in:
agobrech
2022-07-15 16:20:41 +02:00
committed by GitHub
parent 945e25a77c
commit 683d2dfc98
52 changed files with 387 additions and 254 deletions

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,6 +1,9 @@
import {
IAuthenticateGeneric,
ICredentialTestFunction,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
INodeProperties
} from 'n8n-workflow';
export class DropboxApi implements ICredentialType {
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,4 +1,7 @@
import {
IAuthenticateGeneric,
ICredentialTestFunctions,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,5 +1,7 @@
import {
IAuthenticateGeneric,
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
@@ -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',
},
};
}

View File

@@ -1,6 +1,9 @@
import {
ICredentialType,
INodeProperties,
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
export class MauticApi implements ICredentialType {
@@ -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',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -28,6 +28,7 @@ export class NotionApi implements ICredentialType {
properties: {
headers: {
'Authorization': '=Bearer {{$credentials.apiKey}}',
'Notion-Version': '2021-05-13',
},
},
};

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -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',
},
};
}

View File

@@ -1,5 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -16,12 +17,19 @@ export class SendGridApi implements ICredentialType {
default: '',
},
];
authenticate = {
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.apiKey}}',
},
},
} as IAuthenticateGeneric;
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.sendgrid.com/v3',
url: '/marketing/contacts',
},
};
}

View File

@@ -1,5 +1,10 @@
import { BINARY_ENCODING } from 'n8n-core';
import {
IAuthenticateGeneric,
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
@@ -37,4 +42,18 @@ export class ShopifyApi implements ICredentialType {
default: '',
},
];
async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
requestOptions.headers = {
...requestOptions.headers,
Authorization: `Basic ${Buffer.from(`${credentials.apiKey}:${credentials.password}`).toString(BINARY_ENCODING)}`,
};
return requestOptions;
}
test: ICredentialTestRequest = {
request: {
baseURL: '=https://{{$credentials.shopSubdomain}}.myshopify.com/admin/api/2019-10',
url: '/products.json',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -15,4 +17,18 @@ export class Sms77Api implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'X-Api-Key': '={{$credentials.apiKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://gateway.sms77.io/api',
url: '/balance',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -9,9 +11,6 @@ export class StripeApi implements ICredentialType {
displayName = 'Stripe API';
documentationUrl = 'stripe';
properties: INodeProperties[] = [
// The credentials to get from user and save encrypted.
// Properties can be defined exactly in the same way
// as node properties.
{
displayName: 'Secret Key',
name: 'secretKey',
@@ -19,4 +18,19 @@ export class StripeApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.secretKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.stripe.com/v1',
url: '/charges',
json: true,
},
};
}

View File

@@ -18,11 +18,11 @@ export class TelegramApi implements ICredentialType {
description: 'Chat with the <a href="https://telegram.me/botfather">bot father</a> to obtain the access token',
},
];
test: ICredentialTestRequest = {
request: {
baseURL: `=https://api.telegram.org/bot{{$credentials?.accessToken}}`,
baseURL: '=https://api.telegram.org/bot{{$credentials.accessToken}}',
url: '/getMe',
method: 'GET',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -49,4 +51,18 @@ export class TheHiveApi implements ICredentialType {
default: false,
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.ApiKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.url}}',
url: '/api/alert',
},
};
}

View File

@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -16,4 +18,19 @@ export class TypeformApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=bearer {{$credentials.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.typeform.com',
url: '/forms',
},
};
}

View File

@@ -18,7 +18,7 @@ export class UrlScanIoApi implements ICredentialType {
required: true,
},
];
authenticate = {
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {

View File

@@ -20,8 +20,8 @@ export class WebflowApi implements ICredentialType {
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'Authorization': '=Bearer {{$credentials.accessToken}}',
headers:{
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};

View File

@@ -1,5 +1,8 @@
import {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
@@ -35,4 +38,22 @@ export class WooCommerceApi implements ICredentialType {
description: 'Whether credentials should be included in the query. Occasionally, some servers may not parse the Authorization header correctly (if you see a “Consumer key is missing” error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead.',
},
];
async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
requestOptions.auth = {
// @ts-ignore
user: credentials.consumerKey as string,
password: credentials.consumerSecret as string,
};
if (credentials.includeCredentialsInQuery === true) {
delete requestOptions.auth;
Object.assign(requestOptions.qs, { consumer_key: credentials.consumerKey, consumer_secret: credentials.consumerSecret });
}
return requestOptions;
}
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.url}}/wp-json/wc/v3',
url: '/products/categories',
},
};
}

View File

@@ -1,4 +1,4 @@
import { ICredentialType, INodeProperties } from 'n8n-workflow';
import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
export class ZoomApi implements ICredentialType {
name = 'zoomApi';
@@ -12,4 +12,18 @@ export class ZoomApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.zoom.us/v2',
url: '/users/me',
},
};
}