mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Add N8N_GIT_NODE_DISABLE_BARE_REPOS environment variable to allow users to disable bare repositories in Git Node (#19559)
This commit is contained in:
117
packages/nodes-base/nodes/Git/__test__/Git.node.test.ts
Normal file
117
packages/nodes-base/nodes/Git/__test__/Git.node.test.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { DeploymentConfig, SecurityConfig } from '@n8n/config';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
import type { SimpleGit } from 'simple-git';
|
||||
import simpleGit from 'simple-git';
|
||||
|
||||
import { Git } from '../Git.node';
|
||||
|
||||
const mockGit = {
|
||||
log: jest.fn(),
|
||||
env: jest.fn().mockReturnThis(),
|
||||
};
|
||||
|
||||
jest.mock('simple-git');
|
||||
const mockSimpleGit = simpleGit as jest.MockedFunction<typeof simpleGit>;
|
||||
mockSimpleGit.mockReturnValue(mockGit as unknown as SimpleGit);
|
||||
|
||||
describe('Git Node', () => {
|
||||
let gitNode: Git;
|
||||
let executeFunctions: jest.Mocked<IExecuteFunctions>;
|
||||
let deploymentConfig: jest.Mocked<DeploymentConfig>;
|
||||
let securityConfig: jest.Mocked<SecurityConfig>;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
deploymentConfig = mock<DeploymentConfig>({
|
||||
type: 'default',
|
||||
});
|
||||
securityConfig = mock<SecurityConfig>({
|
||||
disableBareRepos: false,
|
||||
});
|
||||
Container.set(DeploymentConfig, deploymentConfig);
|
||||
Container.set(SecurityConfig, securityConfig);
|
||||
|
||||
executeFunctions = mock<IExecuteFunctions>({
|
||||
getInputData: jest.fn().mockReturnValue([{ json: {} }]),
|
||||
getNodeParameter: jest.fn(),
|
||||
helpers: {
|
||||
returnJsonArray: jest
|
||||
.fn()
|
||||
.mockImplementation((data: unknown[]) => data.map((item: unknown) => ({ json: item }))),
|
||||
},
|
||||
});
|
||||
executeFunctions.getNodeParameter.mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'operation':
|
||||
return 'log';
|
||||
case 'repositoryPath':
|
||||
return '/tmp/test-repo';
|
||||
case 'options':
|
||||
return {};
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
});
|
||||
|
||||
mockGit.log.mockResolvedValue({ all: [] });
|
||||
|
||||
gitNode = new Git();
|
||||
});
|
||||
|
||||
describe('Bare Repository Configuration', () => {
|
||||
it('should add safe.bareRepository=explicit when deployment type is cloud', async () => {
|
||||
deploymentConfig.type = 'cloud';
|
||||
securityConfig.disableBareRepos = false;
|
||||
|
||||
await gitNode.execute.call(executeFunctions);
|
||||
|
||||
expect(mockSimpleGit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: ['safe.bareRepository=explicit'],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should add safe.bareRepository=explicit when disableBareRepos is true', async () => {
|
||||
deploymentConfig.type = 'default';
|
||||
securityConfig.disableBareRepos = true;
|
||||
|
||||
await gitNode.execute.call(executeFunctions);
|
||||
|
||||
expect(mockSimpleGit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: ['safe.bareRepository=explicit'],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should add safe.bareRepository=explicit when both cloud and disableBareRepos are true', async () => {
|
||||
deploymentConfig.type = 'cloud';
|
||||
securityConfig.disableBareRepos = true;
|
||||
|
||||
await gitNode.execute.call(executeFunctions);
|
||||
|
||||
expect(mockSimpleGit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: ['safe.bareRepository=explicit'],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should not add safe.bareRepository=explicit when neither cloud nor disableBareRepos is true', async () => {
|
||||
deploymentConfig.type = 'default';
|
||||
securityConfig.disableBareRepos = false;
|
||||
|
||||
await gitNode.execute.call(executeFunctions);
|
||||
|
||||
expect(mockSimpleGit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: [],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user