mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
feat(presets): Restrict internal presets validation (#8382)
This commit is contained in:
parent
32440f26a4
commit
64f93ec2a7
2 changed files with 34 additions and 4 deletions
|
@ -17,6 +17,7 @@ import * as gitlab from './gitlab';
|
||||||
import * as internal from './internal';
|
import * as internal from './internal';
|
||||||
import * as local from './local';
|
import * as local from './local';
|
||||||
import * as npm from './npm';
|
import * as npm from './npm';
|
||||||
|
import { PRESET_DEP_NOT_FOUND } from './util';
|
||||||
|
|
||||||
const presetSources: Record<string, PresetApi> = {
|
const presetSources: Record<string, PresetApi> = {
|
||||||
github,
|
github,
|
||||||
|
@ -151,6 +152,9 @@ export async function getPreset(
|
||||||
presetName,
|
presetName,
|
||||||
baseConfig,
|
baseConfig,
|
||||||
});
|
});
|
||||||
|
if (!presetConfig) {
|
||||||
|
throw new Error(PRESET_DEP_NOT_FOUND);
|
||||||
|
}
|
||||||
logger.trace({ presetConfig }, `Found preset ${preset}`);
|
logger.trace({ presetConfig }, `Found preset ${preset}`);
|
||||||
if (params) {
|
if (params) {
|
||||||
const argMapping = {};
|
const argMapping = {};
|
||||||
|
@ -227,7 +231,7 @@ export async function resolveConfigPresets(
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
if (err.message === 'dep not found') {
|
if (err.message === PRESET_DEP_NOT_FOUND) {
|
||||||
error.validationError = `Cannot find preset's package (${preset})`;
|
error.validationError = `Cannot find preset's package (${preset})`;
|
||||||
} else if (err.message === 'preset renovate-config not found') {
|
} else if (err.message === 'preset renovate-config not found') {
|
||||||
error.validationError = `Preset package is missing a renovate-config entry (${preset})`;
|
error.validationError = `Preset package is missing a renovate-config entry (${preset})`;
|
||||||
|
|
|
@ -1,20 +1,46 @@
|
||||||
|
import { mocked } from '../../../../test/util';
|
||||||
|
import { CONFIG_VALIDATION } from '../../../constants/error-messages';
|
||||||
import { massageConfig } from '../../massage';
|
import { massageConfig } from '../../massage';
|
||||||
import { validateConfig } from '../../validation';
|
import { validateConfig } from '../../validation';
|
||||||
|
import { resolveConfigPresets } from '../index';
|
||||||
|
import * as _npm from '../npm';
|
||||||
import * as internal from '.';
|
import * as internal from '.';
|
||||||
|
|
||||||
|
jest.mock('./npm');
|
||||||
jest.mock('../../../datasource/npm');
|
jest.mock('../../../datasource/npm');
|
||||||
|
|
||||||
|
const npm = mocked(_npm);
|
||||||
|
npm.getPreset = jest.fn((_) => null);
|
||||||
|
|
||||||
const ignoredPresets = ['default:group', 'default:timezone'];
|
const ignoredPresets = ['default:group', 'default:timezone'];
|
||||||
|
|
||||||
describe('config/presets/internal', () => {
|
describe('config/presets/internal', () => {
|
||||||
|
it('fails for undefined internal preset', async () => {
|
||||||
|
const preset = 'foo:bar';
|
||||||
|
const presetConfig = { extends: [preset] };
|
||||||
|
await expect(resolveConfigPresets(presetConfig)).rejects.toThrow(
|
||||||
|
CONFIG_VALIDATION
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
for (const [groupName, groupPresets] of Object.entries(internal.groups)) {
|
for (const [groupName, groupPresets] of Object.entries(internal.groups)) {
|
||||||
for (const [presetName, presetConfig] of Object.entries(groupPresets)) {
|
for (const [presetName, presetConfig] of Object.entries(groupPresets)) {
|
||||||
const preset = `${groupName}:${presetName}`;
|
const preset = `${groupName}:${presetName}`;
|
||||||
if (presetName !== 'description' && !ignoredPresets.includes(preset)) {
|
if (presetName !== 'description' && !ignoredPresets.includes(preset)) {
|
||||||
it(`${preset} validates`, async () => {
|
it(`${preset} validates`, async () => {
|
||||||
const res = await validateConfig(massageConfig(presetConfig), true);
|
try {
|
||||||
expect(res.errors).toHaveLength(0);
|
const config = await resolveConfigPresets(
|
||||||
expect(res.warnings).toHaveLength(0);
|
massageConfig(presetConfig)
|
||||||
|
);
|
||||||
|
const res = await validateConfig(config, true);
|
||||||
|
expect(res.errors).toHaveLength(0);
|
||||||
|
expect(res.warnings).toHaveLength(0);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.validationError) {
|
||||||
|
throw new Error(err.validationError);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue