mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Add more auth tests (#2265)
This commit is contained in:
@@ -3,10 +3,13 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeCredentialTestResult,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -71,6 +74,7 @@ export class HomeAssistant implements INodeType {
|
||||
{
|
||||
name: 'homeAssistantApi',
|
||||
required: true,
|
||||
testedBy: 'homeAssistantApiTest',
|
||||
},
|
||||
],
|
||||
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[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
Reference in New Issue
Block a user