fix(core): Allow secrets manager secrets to be used in credentials (#13110)

This commit is contained in:
Marc Littlemore
2025-02-07 16:43:00 +00:00
committed by GitHub
parent 4577ce0846
commit cae98e733d
5 changed files with 75 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import { type Response } from 'express';
import { mock } from 'jest-mock-extended';
import { Cipher } from 'n8n-core';
import { Logger } from 'n8n-core';
import type { IWorkflowExecuteAdditionalData } from 'n8n-workflow';
import nock from 'nock';
import { CREDENTIAL_BLANKING_VALUE, Time } from '@/constants';
@@ -19,14 +20,20 @@ import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { ExternalHooks } from '@/external-hooks';
import type { OAuthRequest } from '@/requests';
import { SecretsHelper } from '@/secrets-helpers.ee';
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';
import { mockInstance } from '@test/mocking';
jest.mock('@/workflow-execute-additional-data');
describe('OAuth2CredentialController', () => {
mockInstance(Logger);
mockInstance(SecretsHelper);
mockInstance(VariablesService, {
getAllCached: async () => [],
});
const additionalData = mock<IWorkflowExecuteAdditionalData>();
(WorkflowExecuteAdditionalData.getBase as jest.Mock).mockReturnValue(additionalData);
const cipher = mockInstance(Cipher);
const externalHooks = mockInstance(ExternalHooks);
const credentialsHelper = mockInstance(CredentialsHelper);
@@ -108,6 +115,14 @@ describe('OAuth2CredentialController', () => {
type: 'oAuth2Api',
}),
);
expect(credentialsHelper.getDecrypted).toHaveBeenCalledWith(
additionalData,
credential,
credential.type,
'internal',
undefined,
false,
);
});
});
@@ -256,6 +271,14 @@ describe('OAuth2CredentialController', () => {
}),
);
expect(res.render).toHaveBeenCalledWith('oauth-callback');
expect(credentialsHelper.getDecrypted).toHaveBeenCalledWith(
additionalData,
credential,
credential.type,
'internal',
undefined,
true,
);
});
it('merges oauthTokenData if it already exists', async () => {