Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Ensure the generic OAuth2 API credential uses the OAuth2 credential test #8941

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/cli/src/services/credentials-tester.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class CredentialsTester {
return 'access_token' in oauthTokenData;
}

private getCredentialTestFunction(
getCredentialTestFunction(
credentialType: string,
): ICredentialTestFunction | ICredentialTestRequestData | undefined {
// Check if test is defined on credentials
Expand Down Expand Up @@ -116,7 +116,8 @@ export class CredentialsTester {
for (const { name, testedBy } of nodeType.description.credentials ?? []) {
if (
name === credentialType &&
this.credentialTypes.getParentTypes(name).includes('oAuth2Api')
(this.credentialTypes.getParentTypes(name).includes('oAuth2Api') ||
name === 'oAuth2Api')
) {
return async function oauth2CredTest(
this: ICredentialTestFunctions,
Expand Down
32 changes: 32 additions & 0 deletions packages/cli/test/unit/credentials-tester.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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