mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
⚡ Add more auth tests (#2265)
This commit is contained in:
parent
4b64838db8
commit
ba647fbc7b
|
@ -1,15 +1,20 @@
|
||||||
|
import { OptionsWithUri } from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ICredentialsDecrypted,
|
||||||
|
ICredentialTestFunctions,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
IWebhookResponseData,
|
IWebhookResponseData,
|
||||||
|
NodeCredentialTestResult,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -35,6 +40,7 @@ export class BitbucketTrigger implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'bitbucketApi',
|
name: 'bitbucketApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
testedBy: 'bitbucketApiTest',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
webhooks: [
|
webhooks: [
|
||||||
|
@ -166,6 +172,41 @@ export class BitbucketTrigger implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
|
credentialTest: {
|
||||||
|
async bitbucketApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<NodeCredentialTestResult> {
|
||||||
|
const credentials = credential.data;
|
||||||
|
|
||||||
|
const options: OptionsWithUri = {
|
||||||
|
method: 'GET',
|
||||||
|
auth: {
|
||||||
|
user: credentials!.username as string,
|
||||||
|
password: credentials!.appPassword as string,
|
||||||
|
},
|
||||||
|
uri: 'https://api.bitbucket.org/2.0/user',
|
||||||
|
json: true,
|
||||||
|
timeout: 5000,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.helpers.request(options);
|
||||||
|
if (!response.username) {
|
||||||
|
return {
|
||||||
|
status: 'Error',
|
||||||
|
message: `Token is not valid: ${response.error}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: 'Error',
|
||||||
|
message: `Settings are not valid: ${error}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: 'OK',
|
||||||
|
message: 'Authentication successful!',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
loadOptions: {
|
loadOptions: {
|
||||||
// Get all the events to display them to user so that he can
|
// Get all the events to display them to user so that he can
|
||||||
// select them easily
|
// select them easily
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
|
import { OptionsWithUri } from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ICredentialsDecrypted,
|
||||||
|
ICredentialTestFunctions,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
NodeCredentialTestResult,
|
||||||
NodeOperationError,
|
NodeOperationError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
@ -39,6 +44,7 @@ export class Github implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'githubApi',
|
name: 'githubApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
testedBy: 'githubApiTest',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
authentication: [
|
authentication: [
|
||||||
|
@ -1698,6 +1704,43 @@ export class Github implements INodeType {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
methods = {
|
||||||
|
credentialTest: {
|
||||||
|
async githubApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<NodeCredentialTestResult> {
|
||||||
|
const credentials = credential.data;
|
||||||
|
const baseUrl = credentials!.server as string || 'https://api.github.com/user';
|
||||||
|
|
||||||
|
const options: OptionsWithUri = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'n8n',
|
||||||
|
Authorization: `token ${credentials!.accessToken}`,
|
||||||
|
},
|
||||||
|
uri: baseUrl,
|
||||||
|
json: true,
|
||||||
|
timeout: 5000,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await this.helpers.request(options);
|
||||||
|
if (!response.id) {
|
||||||
|
return {
|
||||||
|
status: 'Error',
|
||||||
|
message: `Token is not valid: ${response.error}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: 'Error',
|
||||||
|
message: `Settings are not valid: ${error}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: 'OK',
|
||||||
|
message: 'Authentication successful!',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
|
|
|
@ -3,10 +3,13 @@ import {
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ICredentialsDecrypted,
|
||||||
|
ICredentialTestFunctions,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
NodeCredentialTestResult,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -71,6 +74,7 @@ export class HomeAssistant implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'homeAssistantApi',
|
name: 'homeAssistantApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
testedBy: 'homeAssistantApiTest',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
@ -133,6 +137,43 @@ export class HomeAssistant implements INodeType {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
methods = {
|
||||||
|
credentialTest: {
|
||||||
|
async homeAssistantApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<NodeCredentialTestResult> {
|
||||||
|
const credentials = credential.data;
|
||||||
|
const options = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${credentials!.accessToken}`,
|
||||||
|
},
|
||||||
|
uri: `${credentials!.ssl === true ? 'https' : 'http'}://${credentials!.host}:${ credentials!.port || '8123' }/api/`,
|
||||||
|
json: true,
|
||||||
|
timeout: 5000,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await this.helpers.request(options);
|
||||||
|
if (!response.message) {
|
||||||
|
return {
|
||||||
|
status: 'Error',
|
||||||
|
message: `Token is not valid: ${response.error}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: 'Error',
|
||||||
|
message: `${error.statusCode === 401 ? 'Token is' : 'Settings are'} not valid: ${error}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: 'OK',
|
||||||
|
message: 'Authentication successful!',
|
||||||
|
};
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
Loading…
Reference in a new issue