Skip to content
Snippets Groups Projects
Unverified Commit cf570250 authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

fix(manager/nuget): quote arguments (#15226)

parent 2c087e86
Branches
Tags
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
exports[`modules/manager/nuget/artifacts aborts if lock file is unchanged 1`] = ` exports[`modules/manager/nuget/artifacts aborts if lock file is unchanged 1`] = `
Array [ Array [
Object { Object {
"cmd": "dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config", "cmd": "dotnet restore 'path/with space/project.csproj' --force-evaluate --configfile others/nuget/not-so-random/nuget.config",
"options": Object { "options": Object {
"cwd": "/tmp/github/some/repo", "cwd": "/tmp/github/some/repo",
"encoding": "utf-8", "encoding": "utf-8",
...@@ -23,8 +23,6 @@ Array [ ...@@ -23,8 +23,6 @@ Array [
] ]
`; `;
exports[`modules/manager/nuget/artifacts aborts if no lock file found 1`] = `Array []`;
exports[`modules/manager/nuget/artifacts authenticates at registries 1`] = ` exports[`modules/manager/nuget/artifacts authenticates at registries 1`] = `
Array [ Array [
Object { Object {
...@@ -66,10 +64,6 @@ Array [ ...@@ -66,10 +64,6 @@ Array [
] ]
`; `;
exports[`modules/manager/nuget/artifacts does not update lock file when no deps changed 1`] = `Array []`;
exports[`modules/manager/nuget/artifacts does not update lock file when non-proj file is changed 1`] = `Array []`;
exports[`modules/manager/nuget/artifacts performs lock file maintenance 1`] = ` exports[`modules/manager/nuget/artifacts performs lock file maintenance 1`] = `
Array [ Array [
Object { Object {
......
import { exec as _exec } from 'child_process';
import { join } from 'upath'; import { join } from 'upath';
import { envMock, mockExecAll } from '../../../../test/exec-util'; import { envMock, exec, mockExecAll } from '../../../../test/exec-util';
import { fs, git, mocked } from '../../../../test/util'; import { env, fs, git, mocked } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global'; import { GlobalConfig } from '../../../config/global';
import type { RepoGlobalConfig } from '../../../config/types'; import type { RepoGlobalConfig } from '../../../config/types';
import * as docker from '../../../util/exec/docker'; import * as docker from '../../../util/exec/docker';
import * as _env from '../../../util/exec/env';
import * as _hostRules from '../../../util/host-rules'; import * as _hostRules from '../../../util/host-rules';
import type { UpdateArtifactsConfig } from '../types'; import type { UpdateArtifactsConfig } from '../types';
import * as nuget from './artifacts'; import * as nuget from './artifacts';
import { import * as util from './util';
getConfiguredRegistries as _getConfiguredRegistries,
getDefaultRegistries as _getDefaultRegistries,
getRandomString as _getRandomString,
} from './util';
jest.mock('child_process'); jest.mock('child_process');
jest.mock('../../../util/exec/env'); jest.mock('../../../util/exec/env');
...@@ -22,14 +16,8 @@ jest.mock('../../../util/host-rules'); ...@@ -22,14 +16,8 @@ jest.mock('../../../util/host-rules');
jest.mock('../../../util/git'); jest.mock('../../../util/git');
jest.mock('./util'); jest.mock('./util');
const exec: jest.Mock<typeof _exec> = _exec as any; const { getConfiguredRegistries, getDefaultRegistries, getRandomString } =
const env = mocked(_env); mocked(util);
const getConfiguredRegistries: jest.Mock<typeof _getConfiguredRegistries> =
_getConfiguredRegistries as any;
const getDefaultRegistries: jest.Mock<typeof _getDefaultRegistries> =
_getDefaultRegistries as any;
const getRandomString: jest.Mock<typeof _getRandomString> =
_getRandomString as any;
const hostRules = mocked(_hostRules); const hostRules = mocked(_hostRules);
const adminConfig: RepoGlobalConfig = { const adminConfig: RepoGlobalConfig = {
...@@ -44,13 +32,13 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -44,13 +32,13 @@ describe('modules/manager/nuget/artifacts', () => {
beforeEach(() => { beforeEach(() => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.resetModules(); jest.resetModules();
getDefaultRegistries.mockReturnValue([] as any); getDefaultRegistries.mockReturnValue([]);
env.getChildProcessEnv.mockReturnValue(envMock.basic); env.getChildProcessEnv.mockReturnValue(envMock.basic);
fs.ensureCacheDir.mockImplementation((dirName: string) => fs.ensureCacheDir.mockImplementation((dirName: string) =>
Promise.resolve(`others/${dirName}`) Promise.resolve(`others/${dirName}`)
); );
git.getFileList.mockResolvedValueOnce([]); git.getFileList.mockResolvedValueOnce([]);
getRandomString.mockReturnValue('not-so-random' as any); getRandomString.mockReturnValue('not-so-random');
GlobalConfig.set(adminConfig); GlobalConfig.set(adminConfig);
docker.resetPrefetchedImages(); docker.resetPrefetchedImages();
}); });
...@@ -70,17 +58,19 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -70,17 +58,19 @@ describe('modules/manager/nuget/artifacts', () => {
config, config,
}) })
).toBeNull(); ).toBeNull();
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toBeEmptyArray();
}); });
it('aborts if lock file is unchanged', async () => { it('aborts if lock file is unchanged', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce(
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); 'path/with space/packages.lock.json'
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); );
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'project.csproj', packageFileName: 'path/with space/project.csproj',
updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }], updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }],
newPackageFileContent: '{}', newPackageFileContent: '{}',
config, config,
...@@ -92,8 +82,8 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -92,8 +82,8 @@ describe('modules/manager/nuget/artifacts', () => {
it('updates lock file', async () => { it('updates lock file', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'project.csproj', packageFileName: 'project.csproj',
...@@ -108,8 +98,8 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -108,8 +98,8 @@ describe('modules/manager/nuget/artifacts', () => {
it('does not update lock file when non-proj file is changed', async () => { it('does not update lock file when non-proj file is changed', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'otherfile.props', packageFileName: 'otherfile.props',
...@@ -118,14 +108,14 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -118,14 +108,14 @@ describe('modules/manager/nuget/artifacts', () => {
config, config,
}) })
).toBeNull(); ).toBeNull();
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toBeEmptyArray();
}); });
it('does not update lock file when no deps changed', async () => { it('does not update lock file when no deps changed', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'project.csproj', packageFileName: 'project.csproj',
...@@ -134,14 +124,14 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -134,14 +124,14 @@ describe('modules/manager/nuget/artifacts', () => {
config, config,
}) })
).toBeNull(); ).toBeNull();
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toBeEmptyArray();
}); });
it('performs lock file maintenance', async () => { it('performs lock file maintenance', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'project.csproj', packageFileName: 'project.csproj',
...@@ -160,8 +150,8 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -160,8 +150,8 @@ describe('modules/manager/nuget/artifacts', () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'project.csproj', packageFileName: 'project.csproj',
...@@ -177,8 +167,8 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -177,8 +167,8 @@ describe('modules/manager/nuget/artifacts', () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'global' }); GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
expect( expect(
await nuget.updateArtifacts({ await nuget.updateArtifacts({
packageFileName: 'project.csproj', packageFileName: 'project.csproj',
...@@ -192,7 +182,7 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -192,7 +182,7 @@ describe('modules/manager/nuget/artifacts', () => {
it('catches errors', async () => { it('catches errors', async () => {
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.writeLocalFile.mockImplementationOnce(() => { fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error('not found'); throw new Error('not found');
}); });
...@@ -216,8 +206,8 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -216,8 +206,8 @@ describe('modules/manager/nuget/artifacts', () => {
it('authenticates at registries', async () => { it('authenticates at registries', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
getConfiguredRegistries.mockResolvedValueOnce([ getConfiguredRegistries.mockResolvedValueOnce([
{ {
name: 'myRegistry', name: 'myRegistry',
...@@ -250,8 +240,8 @@ describe('modules/manager/nuget/artifacts', () => { ...@@ -250,8 +240,8 @@ describe('modules/manager/nuget/artifacts', () => {
it('strips protocol version from feed url', async () => { it('strips protocol version from feed url', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
getConfiguredRegistries.mockResolvedValueOnce([ getConfiguredRegistries.mockResolvedValueOnce([
{ {
name: 'myRegistry', name: 'myRegistry',
......
...@@ -42,14 +42,18 @@ async function addSourceCmds( ...@@ -42,14 +42,18 @@ async function addSourceCmds(
url: registry.url, url: registry.url,
}); });
const registryInfo = parseRegistryUrl(registry.url); const registryInfo = parseRegistryUrl(registry.url);
let addSourceCmd = `dotnet nuget add source ${registryInfo.feedUrl} --configfile ${nugetConfigFile}`; let addSourceCmd = `dotnet nuget add source ${quote(
registryInfo.feedUrl
)} --configfile ${quote(nugetConfigFile)}`;
if (registry.name) { if (registry.name) {
// Add name for registry, if known. // Add name for registry, if known.
addSourceCmd += ` --name ${quote(registry.name)}`; addSourceCmd += ` --name ${quote(registry.name)}`;
} }
if (username && password) { if (username && password) {
// Add registry credentials from host rules, if configured. // Add registry credentials from host rules, if configured.
addSourceCmd += ` --username ${username} --password ${password} --store-password-in-clear-text`; addSourceCmd += ` --username ${quote(username)} --password ${quote(
password
)} --store-password-in-clear-text`;
} }
result.push(addSourceCmd); result.push(addSourceCmd);
} }
...@@ -78,8 +82,10 @@ async function runDotnetRestore( ...@@ -78,8 +82,10 @@ async function runDotnetRestore(
const cmds = [ const cmds = [
...(await addSourceCmds(packageFileName, config, nugetConfigFile)), ...(await addSourceCmds(packageFileName, config, nugetConfigFile)),
...dependentPackageFileNames.map( ...dependentPackageFileNames.map(
(f) => (fileName) =>
`dotnet restore ${f} --force-evaluate --configfile ${nugetConfigFile}` `dotnet restore ${quote(
fileName
)} --force-evaluate --configfile ${quote(nugetConfigFile)}`
), ),
]; ];
await exec(cmds, execOptions); await exec(cmds, execOptions);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment