mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): Ensure the generic OAuth2 API credential uses the OAuth2 credential test (#8941)
This commit is contained in:
parent
89df277b80
commit
079a1147d4
|
@ -84,7 +84,7 @@ export class CredentialsTester {
|
||||||
return 'access_token' in oauthTokenData;
|
return 'access_token' in oauthTokenData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCredentialTestFunction(
|
getCredentialTestFunction(
|
||||||
credentialType: string,
|
credentialType: string,
|
||||||
): ICredentialTestFunction | ICredentialTestRequestData | undefined {
|
): ICredentialTestFunction | ICredentialTestRequestData | undefined {
|
||||||
// Check if test is defined on credentials
|
// Check if test is defined on credentials
|
||||||
|
@ -116,7 +116,8 @@ export class CredentialsTester {
|
||||||
for (const { name, testedBy } of nodeType.description.credentials ?? []) {
|
for (const { name, testedBy } of nodeType.description.credentials ?? []) {
|
||||||
if (
|
if (
|
||||||
name === credentialType &&
|
name === credentialType &&
|
||||||
this.credentialTypes.getParentTypes(name).includes('oAuth2Api')
|
(this.credentialTypes.getParentTypes(name).includes('oAuth2Api') ||
|
||||||
|
name === 'oAuth2Api')
|
||||||
) {
|
) {
|
||||||
return async function oauth2CredTest(
|
return async function oauth2CredTest(
|
||||||
this: ICredentialTestFunctions,
|
this: ICredentialTestFunctions,
|
||||||
|
|
32
packages/cli/test/unit/credentials-tester.unit.test.ts
Normal file
32
packages/cli/test/unit/credentials-tester.unit.test.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { CredentialsTester } from '@/services/credentials-tester.service';
|
||||||
|
import mock from 'jest-mock-extended/lib/Mock';
|
||||||
|
import type { CredentialTypes } from '@/CredentialTypes';
|
||||||
|
import type { ICredentialType, INodeType } from 'n8n-workflow';
|
||||||
|
import type { NodeTypes } from '@/NodeTypes';
|
||||||
|
|
||||||
|
describe('CredentialsTester', () => {
|
||||||
|
const credentialTypes = mock<CredentialTypes>();
|
||||||
|
const nodeTypes = mock<NodeTypes>();
|
||||||
|
const credentialsTester = new CredentialsTester(mock(), credentialTypes, nodeTypes, mock());
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should find the OAuth2 credential test for a generic OAuth2 API credential', () => {
|
||||||
|
credentialTypes.getByName.mockReturnValue(mock<ICredentialType>({ test: undefined }));
|
||||||
|
credentialTypes.getSupportedNodes.mockReturnValue(['oAuth2Api']);
|
||||||
|
credentialTypes.getParentTypes.mockReturnValue([]);
|
||||||
|
nodeTypes.getByName.mockReturnValue(
|
||||||
|
mock<INodeType>({
|
||||||
|
description: { credentials: [{ name: 'oAuth2Api' }] },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const testFn = credentialsTester.getCredentialTestFunction('oAuth2Api');
|
||||||
|
|
||||||
|
if (typeof testFn !== 'function') fail();
|
||||||
|
|
||||||
|
expect(testFn.name).toBe('oauth2CredTest');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue