diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index f495b674f..07c128229 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -119305,6 +119305,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; diff --git a/lib/analyze-action.js b/lib/analyze-action.js index b188052d8..97f9f4c38 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -91297,6 +91297,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index f14b14c17..f16cfbfe1 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -80043,6 +80043,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 26f324303..9c59ab324 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -129435,6 +129435,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; diff --git a/lib/init-action.js b/lib/init-action.js index 38cb198d2..26e28786e 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -88057,24 +88057,26 @@ function generateCodeScanningConfig(logger, originalUserInput, augmentationPrope } return augmentedConfig; } -function parseUserConfig(logger, pathInput, contents) { +function parseUserConfig(logger, pathInput, contents, validateConfig) { try { const schema2 = ( // eslint-disable-next-line @typescript-eslint/no-require-imports require_db_config_schema() ); const doc = load(contents); - const result = new jsonschema.Validator().validate(doc, schema2); - if (result.errors.length > 0) { - for (const error2 of result.errors) { - logger.error(error2.stack); + if (validateConfig) { + const result = new jsonschema.Validator().validate(doc, schema2); + if (result.errors.length > 0) { + for (const error2 of result.errors) { + logger.error(error2.stack); + } + throw new ConfigurationError( + getInvalidConfigFileMessage( + pathInput, + result.errors.map((e) => e.stack) + ) + ); } - throw new ConfigurationError( - getInvalidConfigFileMessage( - pathInput, - result.errors.map((e) => e.stack) - ) - ); } return doc; } catch (error2) { @@ -88683,6 +88685,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; @@ -89288,7 +89295,7 @@ async function downloadCacheWithTime(trapCachingEnabled, codeQL, languages, logg } return { trapCaches, trapCacheDownloadTime }; } -async function loadUserConfig(logger, configFile, workspacePath, apiDetails, tempDir) { +async function loadUserConfig(logger, configFile, workspacePath, apiDetails, tempDir, validateConfig) { if (isLocal(configFile)) { if (configFile !== userConfigFromActionPath(tempDir)) { configFile = path11.resolve(workspacePath, configFile); @@ -89298,9 +89305,14 @@ async function loadUserConfig(logger, configFile, workspacePath, apiDetails, tem ); } } - return getLocalConfig(logger, configFile); + return getLocalConfig(logger, configFile, validateConfig); } else { - return await getRemoteConfig(logger, configFile, apiDetails); + return await getRemoteConfig( + logger, + configFile, + apiDetails, + validateConfig + ); } } var OVERLAY_ANALYSIS_FEATURES = { @@ -89429,7 +89441,7 @@ function userConfigFromActionPath(tempDir) { function hasQueryCustomisation(userConfig) { return isDefined(userConfig["disable-default-queries"]) || isDefined(userConfig.queries) || isDefined(userConfig["query-filters"]); } -async function initConfig(inputs) { +async function initConfig(features, inputs) { const { logger, tempDir } = inputs; if (inputs.configInput) { if (inputs.configFile) { @@ -89446,12 +89458,14 @@ async function initConfig(inputs) { logger.debug("No configuration file was provided"); } else { logger.debug(`Using configuration file: ${inputs.configFile}`); + const validateConfig = await features.getValue("validate_db_config" /* ValidateDbConfig */); userConfig = await loadUserConfig( logger, inputs.configFile, inputs.workspacePath, inputs.apiDetails, - tempDir + tempDir, + validateConfig ); } const config = await initActionState(inputs, userConfig); @@ -89513,7 +89527,7 @@ function isLocal(configPath) { } return configPath.indexOf("@") === -1; } -function getLocalConfig(logger, configFile) { +function getLocalConfig(logger, configFile, validateConfig) { if (!fs9.existsSync(configFile)) { throw new ConfigurationError( getConfigFileDoesNotExistErrorMessage(configFile) @@ -89522,10 +89536,11 @@ function getLocalConfig(logger, configFile) { return parseUserConfig( logger, configFile, - fs9.readFileSync(configFile, "utf-8") + fs9.readFileSync(configFile, "utf-8"), + validateConfig ); } -async function getRemoteConfig(logger, configFile, apiDetails) { +async function getRemoteConfig(logger, configFile, apiDetails, validateConfig) { const format = new RegExp( "(?[^/]+)/(?[^/]+)/(?[^@]+)@(?.*)" ); @@ -89556,7 +89571,8 @@ async function getRemoteConfig(logger, configFile, apiDetails) { return parseUserConfig( logger, configFile, - Buffer.from(fileContents, "base64").toString("binary") + Buffer.from(fileContents, "base64").toString("binary"), + validateConfig ); } function getPathToParsedConfigFile(tempDir) { @@ -91668,9 +91684,9 @@ async function initCodeQL(toolsInput, apiDetails, tempDir, variant, defaultCliVe zstdAvailability }; } -async function initConfig2(inputs) { +async function initConfig2(features, inputs) { return await withGroupAsync("Load language configuration", async () => { - return await initConfig(inputs); + return await initConfig(features, inputs); }); } async function runDatabaseInitCluster(databaseInitEnvironment, codeql, config, sourceRoot, processName, qlconfigFile, logger) { @@ -92356,7 +92372,7 @@ async function run() { } } analysisKinds = await getAnalysisKinds(logger); - config = await initConfig2({ + config = await initConfig2(features, { analysisKinds, languagesInput: getOptionalInput("languages"), queriesInput: getOptionalInput("queries"), diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 868829e9a..78e744c09 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -80034,6 +80034,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 046e384d4..d3f6f960f 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -79305,6 +79305,1303 @@ var require_cache3 = __commonJS({ } }); +// node_modules/jsonschema/lib/helpers.js +var require_helpers3 = __commonJS({ + "node_modules/jsonschema/lib/helpers.js"(exports2, module2) { + "use strict"; + var uri = require("url"); + var ValidationError = exports2.ValidationError = function ValidationError2(message, instance, schema2, path12, name, argument) { + if (Array.isArray(path12)) { + this.path = path12; + this.property = path12.reduce(function(sum, item) { + return sum + makeSuffix(item); + }, "instance"); + } else if (path12 !== void 0) { + this.property = path12; + } + if (message) { + this.message = message; + } + if (schema2) { + var id = schema2.$id || schema2.id; + this.schema = id || schema2; + } + if (instance !== void 0) { + this.instance = instance; + } + this.name = name; + this.argument = argument; + this.stack = this.toString(); + }; + ValidationError.prototype.toString = function toString2() { + return this.property + " " + this.message; + }; + var ValidatorResult = exports2.ValidatorResult = function ValidatorResult2(instance, schema2, options, ctx) { + this.instance = instance; + this.schema = schema2; + this.options = options; + this.path = ctx.path; + this.propertyPath = ctx.propertyPath; + this.errors = []; + this.throwError = options && options.throwError; + this.throwFirst = options && options.throwFirst; + this.throwAll = options && options.throwAll; + this.disableFormat = options && options.disableFormat === true; + }; + ValidatorResult.prototype.addError = function addError(detail) { + var err; + if (typeof detail == "string") { + err = new ValidationError(detail, this.instance, this.schema, this.path); + } else { + if (!detail) throw new Error("Missing error detail"); + if (!detail.message) throw new Error("Missing error message"); + if (!detail.name) throw new Error("Missing validator type"); + err = new ValidationError(detail.message, this.instance, this.schema, this.path, detail.name, detail.argument); + } + this.errors.push(err); + if (this.throwFirst) { + throw new ValidatorResultError(this); + } else if (this.throwError) { + throw err; + } + return err; + }; + ValidatorResult.prototype.importErrors = function importErrors(res) { + if (typeof res == "string" || res && res.validatorType) { + this.addError(res); + } else if (res && res.errors) { + this.errors = this.errors.concat(res.errors); + } + }; + function stringizer(v, i) { + return i + ": " + v.toString() + "\n"; + } + ValidatorResult.prototype.toString = function toString2(res) { + return this.errors.map(stringizer).join(""); + }; + Object.defineProperty(ValidatorResult.prototype, "valid", { get: function() { + return !this.errors.length; + } }); + module2.exports.ValidatorResultError = ValidatorResultError; + function ValidatorResultError(result) { + if (Error.captureStackTrace) { + Error.captureStackTrace(this, ValidatorResultError); + } + this.instance = result.instance; + this.schema = result.schema; + this.options = result.options; + this.errors = result.errors; + } + ValidatorResultError.prototype = new Error(); + ValidatorResultError.prototype.constructor = ValidatorResultError; + ValidatorResultError.prototype.name = "Validation Error"; + var SchemaError = exports2.SchemaError = function SchemaError2(msg, schema2) { + this.message = msg; + this.schema = schema2; + Error.call(this, msg); + Error.captureStackTrace(this, SchemaError2); + }; + SchemaError.prototype = Object.create( + Error.prototype, + { + constructor: { value: SchemaError, enumerable: false }, + name: { value: "SchemaError", enumerable: false } + } + ); + var SchemaContext = exports2.SchemaContext = function SchemaContext2(schema2, options, path12, base, schemas) { + this.schema = schema2; + this.options = options; + if (Array.isArray(path12)) { + this.path = path12; + this.propertyPath = path12.reduce(function(sum, item) { + return sum + makeSuffix(item); + }, "instance"); + } else { + this.propertyPath = path12; + } + this.base = base; + this.schemas = schemas; + }; + SchemaContext.prototype.resolve = function resolve4(target) { + return uri.resolve(this.base, target); + }; + SchemaContext.prototype.makeChild = function makeChild(schema2, propertyName) { + var path12 = propertyName === void 0 ? this.path : this.path.concat([propertyName]); + var id = schema2.$id || schema2.id; + var base = uri.resolve(this.base, id || ""); + var ctx = new SchemaContext(schema2, this.options, path12, base, Object.create(this.schemas)); + if (id && !ctx.schemas[base]) { + ctx.schemas[base] = schema2; + } + return ctx; + }; + var FORMAT_REGEXPS = exports2.FORMAT_REGEXPS = { + // 7.3.1. Dates, Times, and Duration + "date-time": /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$/, + "date": /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])$/, + "time": /^(2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])$/, + "duration": /P(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S)|\d+(D|M(\d+D)?|Y(\d+M(\d+D)?)?)(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S))?|\d+W)/i, + // 7.3.2. Email Addresses + // TODO: fix the email production + "email": /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/, + "idn-email": /^("(?:[!#-\[\]-\u{10FFFF}]|\\[\t -\u{10FFFF}])*"|[!#-'*+\-/-9=?A-Z\^-\u{10FFFF}](?:\.?[!#-'*+\-/-9=?A-Z\^-\u{10FFFF}])*)@([!#-'*+\-/-9=?A-Z\^-\u{10FFFF}](?:\.?[!#-'*+\-/-9=?A-Z\^-\u{10FFFF}])*|\[[!-Z\^-\u{10FFFF}]*\])$/u, + // 7.3.3. Hostnames + // 7.3.4. IP Addresses + "ip-address": /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/, + // FIXME whitespace is invalid + "ipv6": /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4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-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + // 7.3.6. uri-template + "uri-template": /(%[0-9a-f]{2}|[!#$&(-;=?@\[\]_a-z~]|\{[!#&+,./;=?@|]?(%[0-9a-f]{2}|[0-9_a-z])(\.?(%[0-9a-f]{2}|[0-9_a-z]))*(:[1-9]\d{0,3}|\*)?(,(%[0-9a-f]{2}|[0-9_a-z])(\.?(%[0-9a-f]{2}|[0-9_a-z]))*(:[1-9]\d{0,3}|\*)?)*\})*/iu, + // 7.3.7. JSON Pointers + "json-pointer": /^(\/([\x00-\x2e0-@\[-}\x7f]|~[01])*)*$/iu, + "relative-json-pointer": /^\d+(#|(\/([\x00-\x2e0-@\[-}\x7f]|~[01])*)*)$/iu, + // hostname regex from: http://stackoverflow.com/a/1420225/5628 + "hostname": /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/, + "host-name": /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/, + "utc-millisec": function(input) { + return typeof input === "string" && parseFloat(input) === parseInt(input, 10) && !isNaN(input); + }, + // 7.3.8. regex + "regex": function(input) { + var result = true; + try { + new RegExp(input); + } catch (e) { + result = false; + } + return result; + }, + // Other definitions + // "style" was removed from JSON Schema in draft-4 and is deprecated + "style": /[\r\n\t ]*[^\r\n\t ][^:]*:[\r\n\t ]*[^\r\n\t ;]*[\r\n\t ]*;?/, + // "color" was removed from JSON Schema in draft-4 and is deprecated + "color": /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/, + "phone": /^\+(?:[0-9] ?){6,14}[0-9]$/, + "alpha": /^[a-zA-Z]+$/, + "alphanumeric": /^[a-zA-Z0-9]+$/ + }; + FORMAT_REGEXPS.regexp = FORMAT_REGEXPS.regex; + FORMAT_REGEXPS.pattern = FORMAT_REGEXPS.regex; + FORMAT_REGEXPS.ipv4 = FORMAT_REGEXPS["ip-address"]; + exports2.isFormat = function isFormat(input, format, validator) { + if (typeof input === "string" && FORMAT_REGEXPS[format] !== void 0) { + if (FORMAT_REGEXPS[format] instanceof RegExp) { + return FORMAT_REGEXPS[format].test(input); + } + if (typeof FORMAT_REGEXPS[format] === "function") { + return FORMAT_REGEXPS[format](input); + } + } else if (validator && validator.customFormats && typeof validator.customFormats[format] === "function") { + return validator.customFormats[format](input); + } + return true; + }; + var makeSuffix = exports2.makeSuffix = function makeSuffix2(key) { + key = key.toString(); + if (!key.match(/[.\s\[\]]/) && !key.match(/^[\d]/)) { + return "." + key; + } + if (key.match(/^\d+$/)) { + return "[" + key + "]"; + } + return "[" + JSON.stringify(key) + "]"; + }; + exports2.deepCompareStrict = function deepCompareStrict(a, b) { + if (typeof a !== typeof b) { + return false; + } + if (Array.isArray(a)) { + if (!Array.isArray(b)) { + return false; + } + if (a.length !== b.length) { + return false; + } + return a.every(function(v, i) { + return deepCompareStrict(a[i], b[i]); + }); + } + if (typeof a === "object") { + if (!a || !b) { + return a === b; + } + var aKeys = Object.keys(a); + var bKeys = Object.keys(b); + if (aKeys.length !== bKeys.length) { + return false; + } + return aKeys.every(function(v) { + return deepCompareStrict(a[v], b[v]); + }); + } + return a === b; + }; + function deepMerger(target, dst, e, i) { + if (typeof e === "object") { + dst[i] = deepMerge(target[i], e); + } else { + if (target.indexOf(e) === -1) { + dst.push(e); + } + } + } + function copyist(src, dst, key) { + dst[key] = src[key]; + } + function copyistWithDeepMerge(target, src, dst, key) { + if (typeof src[key] !== "object" || !src[key]) { + dst[key] = src[key]; + } else { + if (!target[key]) { + dst[key] = src[key]; + } else { + dst[key] = deepMerge(target[key], src[key]); + } + } + } + function deepMerge(target, src) { + var array = Array.isArray(src); + var dst = array && [] || {}; + if (array) { + target = target || []; + dst = dst.concat(target); + src.forEach(deepMerger.bind(null, target, dst)); + } else { + if (target && typeof target === "object") { + Object.keys(target).forEach(copyist.bind(null, target, dst)); + } + Object.keys(src).forEach(copyistWithDeepMerge.bind(null, target, src, dst)); + } + return dst; + } + module2.exports.deepMerge = deepMerge; + exports2.objectGetPath = function objectGetPath(o, s) { + var parts = s.split("/").slice(1); + var k; + while (typeof (k = parts.shift()) == "string") { + var n = decodeURIComponent(k.replace(/~0/, "~").replace(/~1/g, "/")); + if (!(n in o)) return; + o = o[n]; + } + return o; + }; + function pathEncoder(v) { + return "/" + encodeURIComponent(v).replace(/~/g, "%7E"); + } + exports2.encodePath = function encodePointer(a) { + return a.map(pathEncoder).join(""); + }; + exports2.getDecimalPlaces = function getDecimalPlaces(number) { + var decimalPlaces = 0; + if (isNaN(number)) return decimalPlaces; + if (typeof number !== "number") { + number = Number(number); + } + var parts = number.toString().split("e"); + if (parts.length === 2) { + if (parts[1][0] !== "-") { + return decimalPlaces; + } else { + decimalPlaces = Number(parts[1].slice(1)); + } + } + var decimalParts = parts[0].split("."); + if (decimalParts.length === 2) { + decimalPlaces += decimalParts[1].length; + } + return decimalPlaces; + }; + exports2.isSchema = function isSchema(val2) { + return typeof val2 === "object" && val2 || typeof val2 === "boolean"; + }; + } +}); + +// node_modules/jsonschema/lib/attribute.js +var require_attribute = __commonJS({ + "node_modules/jsonschema/lib/attribute.js"(exports2, module2) { + "use strict"; + var helpers = require_helpers3(); + var ValidatorResult = helpers.ValidatorResult; + var SchemaError = helpers.SchemaError; + var attribute = {}; + attribute.ignoreProperties = { + // informative properties + "id": true, + "default": true, + "description": true, + "title": true, + // arguments to other properties + "additionalItems": true, + "then": true, + "else": true, + // special-handled properties + "$schema": true, + "$ref": true, + "extends": true + }; + var validators = attribute.validators = {}; + validators.type = function validateType(instance, schema2, options, ctx) { + if (instance === void 0) { + return null; + } + var result = new ValidatorResult(instance, schema2, options, ctx); + var types = Array.isArray(schema2.type) ? schema2.type : [schema2.type]; + if (!types.some(this.testType.bind(this, instance, schema2, options, ctx))) { + var list = types.map(function(v) { + if (!v) return; + var id = v.$id || v.id; + return id ? "<" + id + ">" : v + ""; + }); + result.addError({ + name: "type", + argument: list, + message: "is not of a type(s) " + list + }); + } + return result; + }; + function testSchemaNoThrow(instance, options, ctx, callback, schema2) { + var throwError2 = options.throwError; + var throwAll = options.throwAll; + options.throwError = false; + options.throwAll = false; + var res = this.validateSchema(instance, schema2, options, ctx); + options.throwError = throwError2; + options.throwAll = throwAll; + if (!res.valid && callback instanceof Function) { + callback(res); + } + return res.valid; + } + validators.anyOf = function validateAnyOf(instance, schema2, options, ctx) { + if (instance === void 0) { + return null; + } + var result = new ValidatorResult(instance, schema2, options, ctx); + var inner = new ValidatorResult(instance, schema2, options, ctx); + if (!Array.isArray(schema2.anyOf)) { + throw new SchemaError("anyOf must be an array"); + } + if (!schema2.anyOf.some( + testSchemaNoThrow.bind( + this, + instance, + options, + ctx, + function(res) { + inner.importErrors(res); + } + ) + )) { + var list = schema2.anyOf.map(function(v, i) { + var id = v.$id || v.id; + if (id) return "<" + id + ">"; + return v.title && JSON.stringify(v.title) || v["$ref"] && "<" + v["$ref"] + ">" || "[subschema " + i + "]"; + }); + if (options.nestedErrors) { + result.importErrors(inner); + } + result.addError({ + name: "anyOf", + argument: list, + message: "is not any of " + list.join(",") + }); + } + return result; + }; + validators.allOf = function validateAllOf(instance, schema2, options, ctx) { + if (instance === void 0) { + return null; + } + if (!Array.isArray(schema2.allOf)) { + throw new SchemaError("allOf must be an array"); + } + var result = new ValidatorResult(instance, schema2, options, ctx); + var self2 = this; + schema2.allOf.forEach(function(v, i) { + var valid3 = self2.validateSchema(instance, v, options, ctx); + if (!valid3.valid) { + var id = v.$id || v.id; + var msg = id || v.title && JSON.stringify(v.title) || v["$ref"] && "<" + v["$ref"] + ">" || "[subschema " + i + "]"; + result.addError({ + name: "allOf", + argument: { id: msg, length: valid3.errors.length, valid: valid3 }, + message: "does not match allOf schema " + msg + " with " + valid3.errors.length + " error[s]:" + }); + result.importErrors(valid3); + } + }); + return result; + }; + validators.oneOf = function validateOneOf(instance, schema2, options, ctx) { + if (instance === void 0) { + return null; + } + if (!Array.isArray(schema2.oneOf)) { + throw new SchemaError("oneOf must be an array"); + } + var result = new ValidatorResult(instance, schema2, options, ctx); + var inner = new ValidatorResult(instance, schema2, options, ctx); + var count = schema2.oneOf.filter( + testSchemaNoThrow.bind( + this, + instance, + options, + ctx, + function(res) { + inner.importErrors(res); + } + ) + ).length; + var list = schema2.oneOf.map(function(v, i) { + var id = v.$id || v.id; + return id || v.title && JSON.stringify(v.title) || v["$ref"] && "<" + v["$ref"] + ">" || "[subschema " + i + "]"; + }); + if (count !== 1) { + if (options.nestedErrors) { + result.importErrors(inner); + } + result.addError({ + name: "oneOf", + argument: list, + message: "is not exactly one from " + list.join(",") + }); + } + return result; + }; + validators.if = function validateIf(instance, schema2, options, ctx) { + if (instance === void 0) return null; + if (!helpers.isSchema(schema2.if)) throw new Error('Expected "if" keyword to be a schema'); + var ifValid = testSchemaNoThrow.call(this, instance, options, ctx, null, schema2.if); + var result = new ValidatorResult(instance, schema2, options, ctx); + var res; + if (ifValid) { + if (schema2.then === void 0) return; + if (!helpers.isSchema(schema2.then)) throw new Error('Expected "then" keyword to be a schema'); + res = this.validateSchema(instance, schema2.then, options, ctx.makeChild(schema2.then)); + result.importErrors(res); + } else { + if (schema2.else === void 0) return; + if (!helpers.isSchema(schema2.else)) throw new Error('Expected "else" keyword to be a schema'); + res = this.validateSchema(instance, schema2.else, options, ctx.makeChild(schema2.else)); + result.importErrors(res); + } + return result; + }; + function getEnumerableProperty(object, key) { + if (Object.hasOwnProperty.call(object, key)) return object[key]; + if (!(key in object)) return; + while (object = Object.getPrototypeOf(object)) { + if (Object.propertyIsEnumerable.call(object, key)) return object[key]; + } + } + validators.propertyNames = function validatePropertyNames(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var subschema = schema2.propertyNames !== void 0 ? schema2.propertyNames : {}; + if (!helpers.isSchema(subschema)) throw new SchemaError('Expected "propertyNames" to be a schema (object or boolean)'); + for (var property in instance) { + if (getEnumerableProperty(instance, property) !== void 0) { + var res = this.validateSchema(property, subschema, options, ctx.makeChild(subschema)); + result.importErrors(res); + } + } + return result; + }; + validators.properties = function validateProperties(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var properties = schema2.properties || {}; + for (var property in properties) { + var subschema = properties[property]; + if (subschema === void 0) { + continue; + } else if (subschema === null) { + throw new SchemaError('Unexpected null, expected schema in "properties"'); + } + if (typeof options.preValidateProperty == "function") { + options.preValidateProperty(instance, property, subschema, options, ctx); + } + var prop = getEnumerableProperty(instance, property); + var res = this.validateSchema(prop, subschema, options, ctx.makeChild(subschema, property)); + if (res.instance !== result.instance[property]) result.instance[property] = res.instance; + result.importErrors(res); + } + return result; + }; + function testAdditionalProperty(instance, schema2, options, ctx, property, result) { + if (!this.types.object(instance)) return; + if (schema2.properties && schema2.properties[property] !== void 0) { + return; + } + if (schema2.additionalProperties === false) { + result.addError({ + name: "additionalProperties", + argument: property, + message: "is not allowed to have the additional property " + JSON.stringify(property) + }); + } else { + var additionalProperties = schema2.additionalProperties || {}; + if (typeof options.preValidateProperty == "function") { + options.preValidateProperty(instance, property, additionalProperties, options, ctx); + } + var res = this.validateSchema(instance[property], additionalProperties, options, ctx.makeChild(additionalProperties, property)); + if (res.instance !== result.instance[property]) result.instance[property] = res.instance; + result.importErrors(res); + } + } + validators.patternProperties = function validatePatternProperties(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var patternProperties = schema2.patternProperties || {}; + for (var property in instance) { + var test = true; + for (var pattern in patternProperties) { + var subschema = patternProperties[pattern]; + if (subschema === void 0) { + continue; + } else if (subschema === null) { + throw new SchemaError('Unexpected null, expected schema in "patternProperties"'); + } + try { + var regexp = new RegExp(pattern, "u"); + } catch (_e) { + regexp = new RegExp(pattern); + } + if (!regexp.test(property)) { + continue; + } + test = false; + if (typeof options.preValidateProperty == "function") { + options.preValidateProperty(instance, property, subschema, options, ctx); + } + var res = this.validateSchema(instance[property], subschema, options, ctx.makeChild(subschema, property)); + if (res.instance !== result.instance[property]) result.instance[property] = res.instance; + result.importErrors(res); + } + if (test) { + testAdditionalProperty.call(this, instance, schema2, options, ctx, property, result); + } + } + return result; + }; + validators.additionalProperties = function validateAdditionalProperties(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + if (schema2.patternProperties) { + return null; + } + var result = new ValidatorResult(instance, schema2, options, ctx); + for (var property in instance) { + testAdditionalProperty.call(this, instance, schema2, options, ctx, property, result); + } + return result; + }; + validators.minProperties = function validateMinProperties(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var keys = Object.keys(instance); + if (!(keys.length >= schema2.minProperties)) { + result.addError({ + name: "minProperties", + argument: schema2.minProperties, + message: "does not meet minimum property length of " + schema2.minProperties + }); + } + return result; + }; + validators.maxProperties = function validateMaxProperties(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var keys = Object.keys(instance); + if (!(keys.length <= schema2.maxProperties)) { + result.addError({ + name: "maxProperties", + argument: schema2.maxProperties, + message: "does not meet maximum property length of " + schema2.maxProperties + }); + } + return result; + }; + validators.items = function validateItems(instance, schema2, options, ctx) { + var self2 = this; + if (!this.types.array(instance)) return; + if (schema2.items === void 0) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + instance.every(function(value, i) { + if (Array.isArray(schema2.items)) { + var items = schema2.items[i] === void 0 ? schema2.additionalItems : schema2.items[i]; + } else { + var items = schema2.items; + } + if (items === void 0) { + return true; + } + if (items === false) { + result.addError({ + name: "items", + message: "additionalItems not permitted" + }); + return false; + } + var res = self2.validateSchema(value, items, options, ctx.makeChild(items, i)); + if (res.instance !== result.instance[i]) result.instance[i] = res.instance; + result.importErrors(res); + return true; + }); + return result; + }; + validators.contains = function validateContains(instance, schema2, options, ctx) { + var self2 = this; + if (!this.types.array(instance)) return; + if (schema2.contains === void 0) return; + if (!helpers.isSchema(schema2.contains)) throw new Error('Expected "contains" keyword to be a schema'); + var result = new ValidatorResult(instance, schema2, options, ctx); + var count = instance.some(function(value, i) { + var res = self2.validateSchema(value, schema2.contains, options, ctx.makeChild(schema2.contains, i)); + return res.errors.length === 0; + }); + if (count === false) { + result.addError({ + name: "contains", + argument: schema2.contains, + message: "must contain an item matching given schema" + }); + } + return result; + }; + validators.minimum = function validateMinimum(instance, schema2, options, ctx) { + if (!this.types.number(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + if (schema2.exclusiveMinimum && schema2.exclusiveMinimum === true) { + if (!(instance > schema2.minimum)) { + result.addError({ + name: "minimum", + argument: schema2.minimum, + message: "must be greater than " + schema2.minimum + }); + } + } else { + if (!(instance >= schema2.minimum)) { + result.addError({ + name: "minimum", + argument: schema2.minimum, + message: "must be greater than or equal to " + schema2.minimum + }); + } + } + return result; + }; + validators.maximum = function validateMaximum(instance, schema2, options, ctx) { + if (!this.types.number(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + if (schema2.exclusiveMaximum && schema2.exclusiveMaximum === true) { + if (!(instance < schema2.maximum)) { + result.addError({ + name: "maximum", + argument: schema2.maximum, + message: "must be less than " + schema2.maximum + }); + } + } else { + if (!(instance <= schema2.maximum)) { + result.addError({ + name: "maximum", + argument: schema2.maximum, + message: "must be less than or equal to " + schema2.maximum + }); + } + } + return result; + }; + validators.exclusiveMinimum = function validateExclusiveMinimum(instance, schema2, options, ctx) { + if (typeof schema2.exclusiveMinimum === "boolean") return; + if (!this.types.number(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var valid3 = instance > schema2.exclusiveMinimum; + if (!valid3) { + result.addError({ + name: "exclusiveMinimum", + argument: schema2.exclusiveMinimum, + message: "must be strictly greater than " + schema2.exclusiveMinimum + }); + } + return result; + }; + validators.exclusiveMaximum = function validateExclusiveMaximum(instance, schema2, options, ctx) { + if (typeof schema2.exclusiveMaximum === "boolean") return; + if (!this.types.number(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var valid3 = instance < schema2.exclusiveMaximum; + if (!valid3) { + result.addError({ + name: "exclusiveMaximum", + argument: schema2.exclusiveMaximum, + message: "must be strictly less than " + schema2.exclusiveMaximum + }); + } + return result; + }; + var validateMultipleOfOrDivisbleBy = function validateMultipleOfOrDivisbleBy2(instance, schema2, options, ctx, validationType, errorMessage) { + if (!this.types.number(instance)) return; + var validationArgument = schema2[validationType]; + if (validationArgument == 0) { + throw new SchemaError(validationType + " cannot be zero"); + } + var result = new ValidatorResult(instance, schema2, options, ctx); + var instanceDecimals = helpers.getDecimalPlaces(instance); + var divisorDecimals = helpers.getDecimalPlaces(validationArgument); + var maxDecimals = Math.max(instanceDecimals, divisorDecimals); + var multiplier = Math.pow(10, maxDecimals); + if (Math.round(instance * multiplier) % Math.round(validationArgument * multiplier) !== 0) { + result.addError({ + name: validationType, + argument: validationArgument, + message: errorMessage + JSON.stringify(validationArgument) + }); + } + return result; + }; + validators.multipleOf = function validateMultipleOf(instance, schema2, options, ctx) { + return validateMultipleOfOrDivisbleBy.call(this, instance, schema2, options, ctx, "multipleOf", "is not a multiple of (divisible by) "); + }; + validators.divisibleBy = function validateDivisibleBy(instance, schema2, options, ctx) { + return validateMultipleOfOrDivisbleBy.call(this, instance, schema2, options, ctx, "divisibleBy", "is not divisible by (multiple of) "); + }; + validators.required = function validateRequired(instance, schema2, options, ctx) { + var result = new ValidatorResult(instance, schema2, options, ctx); + if (instance === void 0 && schema2.required === true) { + result.addError({ + name: "required", + message: "is required" + }); + } else if (this.types.object(instance) && Array.isArray(schema2.required)) { + schema2.required.forEach(function(n) { + if (getEnumerableProperty(instance, n) === void 0) { + result.addError({ + name: "required", + argument: n, + message: "requires property " + JSON.stringify(n) + }); + } + }); + } + return result; + }; + validators.pattern = function validatePattern(instance, schema2, options, ctx) { + if (!this.types.string(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var pattern = schema2.pattern; + try { + var regexp = new RegExp(pattern, "u"); + } catch (_e) { + regexp = new RegExp(pattern); + } + if (!instance.match(regexp)) { + result.addError({ + name: "pattern", + argument: schema2.pattern, + message: "does not match pattern " + JSON.stringify(schema2.pattern.toString()) + }); + } + return result; + }; + validators.format = function validateFormat(instance, schema2, options, ctx) { + if (instance === void 0) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + if (!result.disableFormat && !helpers.isFormat(instance, schema2.format, this)) { + result.addError({ + name: "format", + argument: schema2.format, + message: "does not conform to the " + JSON.stringify(schema2.format) + " format" + }); + } + return result; + }; + validators.minLength = function validateMinLength(instance, schema2, options, ctx) { + if (!this.types.string(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var hsp = instance.match(/[\uDC00-\uDFFF]/g); + var length = instance.length - (hsp ? hsp.length : 0); + if (!(length >= schema2.minLength)) { + result.addError({ + name: "minLength", + argument: schema2.minLength, + message: "does not meet minimum length of " + schema2.minLength + }); + } + return result; + }; + validators.maxLength = function validateMaxLength(instance, schema2, options, ctx) { + if (!this.types.string(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + var hsp = instance.match(/[\uDC00-\uDFFF]/g); + var length = instance.length - (hsp ? hsp.length : 0); + if (!(length <= schema2.maxLength)) { + result.addError({ + name: "maxLength", + argument: schema2.maxLength, + message: "does not meet maximum length of " + schema2.maxLength + }); + } + return result; + }; + validators.minItems = function validateMinItems(instance, schema2, options, ctx) { + if (!this.types.array(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + if (!(instance.length >= schema2.minItems)) { + result.addError({ + name: "minItems", + argument: schema2.minItems, + message: "does not meet minimum length of " + schema2.minItems + }); + } + return result; + }; + validators.maxItems = function validateMaxItems(instance, schema2, options, ctx) { + if (!this.types.array(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + if (!(instance.length <= schema2.maxItems)) { + result.addError({ + name: "maxItems", + argument: schema2.maxItems, + message: "does not meet maximum length of " + schema2.maxItems + }); + } + return result; + }; + function testArrays(v, i, a) { + var j, len = a.length; + for (j = i + 1, len; j < len; j++) { + if (helpers.deepCompareStrict(v, a[j])) { + return false; + } + } + return true; + } + validators.uniqueItems = function validateUniqueItems(instance, schema2, options, ctx) { + if (schema2.uniqueItems !== true) return; + if (!this.types.array(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + if (!instance.every(testArrays)) { + result.addError({ + name: "uniqueItems", + message: "contains duplicate item" + }); + } + return result; + }; + validators.dependencies = function validateDependencies(instance, schema2, options, ctx) { + if (!this.types.object(instance)) return; + var result = new ValidatorResult(instance, schema2, options, ctx); + for (var property in schema2.dependencies) { + if (instance[property] === void 0) { + continue; + } + var dep = schema2.dependencies[property]; + var childContext = ctx.makeChild(dep, property); + if (typeof dep == "string") { + dep = [dep]; + } + if (Array.isArray(dep)) { + dep.forEach(function(prop) { + if (instance[prop] === void 0) { + result.addError({ + // FIXME there's two different "dependencies" errors here with slightly different outputs + // Can we make these the same? Or should we create different error types? + name: "dependencies", + argument: childContext.propertyPath, + message: "property " + prop + " not found, required by " + childContext.propertyPath + }); + } + }); + } else { + var res = this.validateSchema(instance, dep, options, childContext); + if (result.instance !== res.instance) result.instance = res.instance; + if (res && res.errors.length) { + result.addError({ + name: "dependencies", + argument: childContext.propertyPath, + message: "does not meet dependency required by " + childContext.propertyPath + }); + result.importErrors(res); + } + } + } + return result; + }; + validators["enum"] = function validateEnum(instance, schema2, options, ctx) { + if (instance === void 0) { + return null; + } + if (!Array.isArray(schema2["enum"])) { + throw new SchemaError("enum expects an array", schema2); + } + var result = new ValidatorResult(instance, schema2, options, ctx); + if (!schema2["enum"].some(helpers.deepCompareStrict.bind(null, instance))) { + result.addError({ + name: "enum", + argument: schema2["enum"], + message: "is not one of enum values: " + schema2["enum"].map(String).join(",") + }); + } + return result; + }; + validators["const"] = function validateEnum(instance, schema2, options, ctx) { + if (instance === void 0) { + return null; + } + var result = new ValidatorResult(instance, schema2, options, ctx); + if (!helpers.deepCompareStrict(schema2["const"], instance)) { + result.addError({ + name: "const", + argument: schema2["const"], + message: "does not exactly match expected constant: " + schema2["const"] + }); + } + return result; + }; + validators.not = validators.disallow = function validateNot(instance, schema2, options, ctx) { + var self2 = this; + if (instance === void 0) return null; + var result = new ValidatorResult(instance, schema2, options, ctx); + var notTypes = schema2.not || schema2.disallow; + if (!notTypes) return null; + if (!Array.isArray(notTypes)) notTypes = [notTypes]; + notTypes.forEach(function(type2) { + if (self2.testType(instance, schema2, options, ctx, type2)) { + var id = type2 && (type2.$id || type2.id); + var schemaId = id || type2; + result.addError({ + name: "not", + argument: schemaId, + message: "is of prohibited type " + schemaId + }); + } + }); + return result; + }; + module2.exports = attribute; + } +}); + +// node_modules/jsonschema/lib/scan.js +var require_scan2 = __commonJS({ + "node_modules/jsonschema/lib/scan.js"(exports2, module2) { + "use strict"; + var urilib = require("url"); + var helpers = require_helpers3(); + module2.exports.SchemaScanResult = SchemaScanResult; + function SchemaScanResult(found, ref) { + this.id = found; + this.ref = ref; + } + module2.exports.scan = function scan(base, schema2) { + function scanSchema(baseuri, schema3) { + if (!schema3 || typeof schema3 != "object") return; + if (schema3.$ref) { + var resolvedUri = urilib.resolve(baseuri, schema3.$ref); + ref[resolvedUri] = ref[resolvedUri] ? ref[resolvedUri] + 1 : 0; + return; + } + var id = schema3.$id || schema3.id; + var ourBase = id ? urilib.resolve(baseuri, id) : baseuri; + if (ourBase) { + if (ourBase.indexOf("#") < 0) ourBase += "#"; + if (found[ourBase]) { + if (!helpers.deepCompareStrict(found[ourBase], schema3)) { + throw new Error("Schema <" + ourBase + "> already exists with different definition"); + } + return found[ourBase]; + } + found[ourBase] = schema3; + if (ourBase[ourBase.length - 1] == "#") { + found[ourBase.substring(0, ourBase.length - 1)] = schema3; + } + } + scanArray(ourBase + "/items", Array.isArray(schema3.items) ? schema3.items : [schema3.items]); + scanArray(ourBase + "/extends", Array.isArray(schema3.extends) ? schema3.extends : [schema3.extends]); + scanSchema(ourBase + "/additionalItems", schema3.additionalItems); + scanObject(ourBase + "/properties", schema3.properties); + scanSchema(ourBase + "/additionalProperties", schema3.additionalProperties); + scanObject(ourBase + "/definitions", schema3.definitions); + scanObject(ourBase + "/patternProperties", schema3.patternProperties); + scanObject(ourBase + "/dependencies", schema3.dependencies); + scanArray(ourBase + "/disallow", schema3.disallow); + scanArray(ourBase + "/allOf", schema3.allOf); + scanArray(ourBase + "/anyOf", schema3.anyOf); + scanArray(ourBase + "/oneOf", schema3.oneOf); + scanSchema(ourBase + "/not", schema3.not); + } + function scanArray(baseuri, schemas) { + if (!Array.isArray(schemas)) return; + for (var i = 0; i < schemas.length; i++) { + scanSchema(baseuri + "/" + i, schemas[i]); + } + } + function scanObject(baseuri, schemas) { + if (!schemas || typeof schemas != "object") return; + for (var p in schemas) { + scanSchema(baseuri + "/" + p, schemas[p]); + } + } + var found = {}; + var ref = {}; + scanSchema(base, schema2); + return new SchemaScanResult(found, ref); + }; + } +}); + +// node_modules/jsonschema/lib/validator.js +var require_validator2 = __commonJS({ + "node_modules/jsonschema/lib/validator.js"(exports2, module2) { + "use strict"; + var urilib = require("url"); + var attribute = require_attribute(); + var helpers = require_helpers3(); + var scanSchema = require_scan2().scan; + var ValidatorResult = helpers.ValidatorResult; + var ValidatorResultError = helpers.ValidatorResultError; + var SchemaError = helpers.SchemaError; + var SchemaContext = helpers.SchemaContext; + var anonymousBase = "/"; + var Validator2 = function Validator3() { + this.customFormats = Object.create(Validator3.prototype.customFormats); + this.schemas = {}; + this.unresolvedRefs = []; + this.types = Object.create(types); + this.attributes = Object.create(attribute.validators); + }; + Validator2.prototype.customFormats = {}; + Validator2.prototype.schemas = null; + Validator2.prototype.types = null; + Validator2.prototype.attributes = null; + Validator2.prototype.unresolvedRefs = null; + Validator2.prototype.addSchema = function addSchema(schema2, base) { + var self2 = this; + if (!schema2) { + return null; + } + var scan = scanSchema(base || anonymousBase, schema2); + var ourUri = base || schema2.$id || schema2.id; + for (var uri in scan.id) { + this.schemas[uri] = scan.id[uri]; + } + for (var uri in scan.ref) { + this.unresolvedRefs.push(uri); + } + this.unresolvedRefs = this.unresolvedRefs.filter(function(uri2) { + return typeof self2.schemas[uri2] === "undefined"; + }); + return this.schemas[ourUri]; + }; + Validator2.prototype.addSubSchemaArray = function addSubSchemaArray(baseuri, schemas) { + if (!Array.isArray(schemas)) return; + for (var i = 0; i < schemas.length; i++) { + this.addSubSchema(baseuri, schemas[i]); + } + }; + Validator2.prototype.addSubSchemaObject = function addSubSchemaArray(baseuri, schemas) { + if (!schemas || typeof schemas != "object") return; + for (var p in schemas) { + this.addSubSchema(baseuri, schemas[p]); + } + }; + Validator2.prototype.setSchemas = function setSchemas(schemas) { + this.schemas = schemas; + }; + Validator2.prototype.getSchema = function getSchema(urn) { + return this.schemas[urn]; + }; + Validator2.prototype.validate = function validate(instance, schema2, options, ctx) { + if (typeof schema2 !== "boolean" && typeof schema2 !== "object" || schema2 === null) { + throw new SchemaError("Expected `schema` to be an object or boolean"); + } + if (!options) { + options = {}; + } + var id = schema2.$id || schema2.id; + var base = urilib.resolve(options.base || anonymousBase, id || ""); + if (!ctx) { + ctx = new SchemaContext(schema2, options, [], base, Object.create(this.schemas)); + if (!ctx.schemas[base]) { + ctx.schemas[base] = schema2; + } + var found = scanSchema(base, schema2); + for (var n in found.id) { + var sch = found.id[n]; + ctx.schemas[n] = sch; + } + } + if (options.required && instance === void 0) { + var result = new ValidatorResult(instance, schema2, options, ctx); + result.addError("is required, but is undefined"); + return result; + } + var result = this.validateSchema(instance, schema2, options, ctx); + if (!result) { + throw new Error("Result undefined"); + } else if (options.throwAll && result.errors.length) { + throw new ValidatorResultError(result); + } + return result; + }; + function shouldResolve(schema2) { + var ref = typeof schema2 === "string" ? schema2 : schema2.$ref; + if (typeof ref == "string") return ref; + return false; + } + Validator2.prototype.validateSchema = function validateSchema(instance, schema2, options, ctx) { + var result = new ValidatorResult(instance, schema2, options, ctx); + if (typeof schema2 === "boolean") { + if (schema2 === true) { + schema2 = {}; + } else if (schema2 === false) { + schema2 = { type: [] }; + } + } else if (!schema2) { + throw new Error("schema is undefined"); + } + if (schema2["extends"]) { + if (Array.isArray(schema2["extends"])) { + var schemaobj = { schema: schema2, ctx }; + schema2["extends"].forEach(this.schemaTraverser.bind(this, schemaobj)); + schema2 = schemaobj.schema; + schemaobj.schema = null; + schemaobj.ctx = null; + schemaobj = null; + } else { + schema2 = helpers.deepMerge(schema2, this.superResolve(schema2["extends"], ctx)); + } + } + var switchSchema = shouldResolve(schema2); + if (switchSchema) { + var resolved = this.resolve(schema2, switchSchema, ctx); + var subctx = new SchemaContext(resolved.subschema, options, ctx.path, resolved.switchSchema, ctx.schemas); + return this.validateSchema(instance, resolved.subschema, options, subctx); + } + var skipAttributes = options && options.skipAttributes || []; + for (var key in schema2) { + if (!attribute.ignoreProperties[key] && skipAttributes.indexOf(key) < 0) { + var validatorErr = null; + var validator = this.attributes[key]; + if (validator) { + validatorErr = validator.call(this, instance, schema2, options, ctx); + } else if (options.allowUnknownAttributes === false) { + throw new SchemaError("Unsupported attribute: " + key, schema2); + } + if (validatorErr) { + result.importErrors(validatorErr); + } + } + } + if (typeof options.rewrite == "function") { + var value = options.rewrite.call(this, instance, schema2, options, ctx); + result.instance = value; + } + return result; + }; + Validator2.prototype.schemaTraverser = function schemaTraverser(schemaobj, s) { + schemaobj.schema = helpers.deepMerge(schemaobj.schema, this.superResolve(s, schemaobj.ctx)); + }; + Validator2.prototype.superResolve = function superResolve(schema2, ctx) { + var ref = shouldResolve(schema2); + if (ref) { + return this.resolve(schema2, ref, ctx).subschema; + } + return schema2; + }; + Validator2.prototype.resolve = function resolve4(schema2, switchSchema, ctx) { + switchSchema = ctx.resolve(switchSchema); + if (ctx.schemas[switchSchema]) { + return { subschema: ctx.schemas[switchSchema], switchSchema }; + } + var parsed = urilib.parse(switchSchema); + var fragment = parsed && parsed.hash; + var document2 = fragment && fragment.length && switchSchema.substr(0, switchSchema.length - fragment.length); + if (!document2 || !ctx.schemas[document2]) { + throw new SchemaError("no such schema <" + switchSchema + ">", schema2); + } + var subschema = helpers.objectGetPath(ctx.schemas[document2], fragment.substr(1)); + if (subschema === void 0) { + throw new SchemaError("no such schema " + fragment + " located in <" + document2 + ">", schema2); + } + return { subschema, switchSchema }; + }; + Validator2.prototype.testType = function validateType(instance, schema2, options, ctx, type2) { + if (type2 === void 0) { + return; + } else if (type2 === null) { + throw new SchemaError('Unexpected null in "type" keyword'); + } + if (typeof this.types[type2] == "function") { + return this.types[type2].call(this, instance); + } + if (type2 && typeof type2 == "object") { + var res = this.validateSchema(instance, type2, options, ctx); + return res === void 0 || !(res && res.errors.length); + } + return true; + }; + var types = Validator2.prototype.types = {}; + types.string = function testString(instance) { + return typeof instance == "string"; + }; + types.number = function testNumber(instance) { + return typeof instance == "number" && isFinite(instance); + }; + types.integer = function testInteger(instance) { + return typeof instance == "number" && instance % 1 === 0; + }; + types.boolean = function testBoolean(instance) { + return typeof instance == "boolean"; + }; + types.array = function testArray(instance) { + return Array.isArray(instance); + }; + types["null"] = function testNull(instance) { + return instance === null; + }; + types.date = function testDate(instance) { + return instance instanceof Date; + }; + types.any = function testAny(instance) { + return true; + }; + types.object = function testObject(instance) { + return instance && typeof instance === "object" && !Array.isArray(instance) && !(instance instanceof Date); + }; + module2.exports = Validator2; + } +}); + +// node_modules/jsonschema/lib/index.js +var require_lib2 = __commonJS({ + "node_modules/jsonschema/lib/index.js"(exports2, module2) { + "use strict"; + var Validator2 = module2.exports.Validator = require_validator2(); + module2.exports.ValidatorResult = require_helpers3().ValidatorResult; + module2.exports.ValidatorResultError = require_helpers3().ValidatorResultError; + module2.exports.ValidationError = require_helpers3().ValidationError; + module2.exports.SchemaError = require_helpers3().SchemaError; + module2.exports.SchemaScanResult = require_scan2().SchemaScanResult; + module2.exports.scan = require_scan2().scan; + module2.exports.validate = function(instance, schema2, options) { + var v = new Validator2(); + return v.validate(instance, schema2, options); + }; + } +}); + // node_modules/@actions/tool-cache/lib/manifest.js var require_manifest = __commonJS({ "node_modules/@actions/tool-cache/lib/manifest.js"(exports2, module2) { @@ -85194,6 +86491,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; @@ -85677,6 +86979,9 @@ var cliErrorsConfig = { cliErrorMessageCandidates: [ new RegExp( "Query pack .* cannot be found\\. Check the spelling of the pack\\." + ), + new RegExp( + "is not a .ql file, .qls file, a directory, or a query pack specification." ) ] }, @@ -85759,6 +87064,7 @@ var supportedAnalysisKinds = new Set(Object.values(AnalysisKind)); var core8 = __toESM(require_core()); // src/config/db-config.ts +var jsonschema = __toESM(require_lib2()); var semver4 = __toESM(require_semver2()); var PACK_IDENTIFIER_PATTERN = (function() { const alphaNumeric = "[a-z0-9]"; diff --git a/lib/start-proxy-action-post.js b/lib/start-proxy-action-post.js index a1934501c..ef190f968 100644 --- a/lib/start-proxy-action-post.js +++ b/lib/start-proxy-action-post.js @@ -118711,6 +118711,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index c45359abb..6e54c4752 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -96825,6 +96825,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; diff --git a/lib/upload-lib.js b/lib/upload-lib.js index bae54aaa8..c14e2f503 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -89534,6 +89534,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; diff --git a/lib/upload-sarif-action-post.js b/lib/upload-sarif-action-post.js index 911c8c2ed..53cd97492 100644 --- a/lib/upload-sarif-action-post.js +++ b/lib/upload-sarif-action-post.js @@ -118877,6 +118877,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index cc36c1e7d..c1c7025e8 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -89446,6 +89446,11 @@ var featureConfig = { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0" + }, + ["validate_db_config" /* ValidateDbConfig */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: void 0 } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; diff --git a/src/config-utils.test.ts b/src/config-utils.test.ts index c7d20a46f..bf60b4902 100644 --- a/src/config-utils.test.ts +++ b/src/config-utils.test.ts @@ -148,6 +148,7 @@ test("load empty config", async (t) => { }); const config = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput: languages, repository: { owner: "github", repo: "example" }, @@ -187,6 +188,7 @@ test("load code quality config", async (t) => { }); const config = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ analysisKinds: [AnalysisKind.CodeQuality], languagesInput: languages, @@ -271,6 +273,7 @@ test("initActionState doesn't throw if there are queries configured in the repos await t.notThrowsAsync(async () => { const config = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ analysisKinds: [AnalysisKind.CodeQuality], languagesInput: languages, @@ -309,6 +312,7 @@ test("loading a saved config produces the same config", async (t) => { t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined); const config1 = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput: "javascript,python", tempDir, @@ -360,6 +364,7 @@ test("loading config with version mismatch throws", async (t) => { .returns("does-not-exist"); const config = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput: "javascript,python", tempDir, @@ -388,6 +393,7 @@ test("load input outside of workspace", async (t) => { return await withTmpDir(async (tempDir) => { try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ configFile: "../input", tempDir, @@ -415,6 +421,7 @@ test("load non-local input with invalid repo syntax", async (t) => { try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ configFile, tempDir, @@ -443,6 +450,7 @@ test("load non-existent input", async (t) => { try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput, configFile, @@ -526,6 +534,7 @@ test("load non-empty input", async (t) => { const configFilePath = createConfigFile(inputFileContents, tempDir); const actualConfig = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput, buildModeInput: "none", @@ -582,6 +591,7 @@ test("Using config input and file together, config input should be used.", async const languagesInput = "javascript"; const config = await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput, configFile: configFilePath, @@ -632,6 +642,7 @@ test("API client used when reading remote config", async (t) => { const languagesInput = "javascript"; await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput, configFile, @@ -652,6 +663,7 @@ test("Remote config handles the case where a directory is provided", async (t) = const repoReference = "octo-org/codeql-config/config.yaml@main"; try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ configFile: repoReference, tempDir, @@ -680,6 +692,7 @@ test("Invalid format of remote config handled correctly", async (t) => { const repoReference = "octo-org/codeql-config/config.yaml@main"; try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ configFile: repoReference, tempDir, @@ -709,6 +722,7 @@ test("No detected languages", async (t) => { try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ tempDir, codeql, @@ -731,6 +745,7 @@ test("Unknown languages", async (t) => { try { await configUtils.initConfig( + createFeatures([]), createTestInitConfigInputs({ languagesInput, tempDir, diff --git a/src/config-utils.ts b/src/config-utils.ts index 121eae324..f523213b1 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -531,6 +531,7 @@ async function loadUserConfig( workspacePath: string, apiDetails: api.GitHubApiCombinedDetails, tempDir: string, + validateConfig: boolean, ): Promise { if (isLocal(configFile)) { if (configFile !== userConfigFromActionPath(tempDir)) { @@ -543,9 +544,14 @@ async function loadUserConfig( ); } } - return getLocalConfig(logger, configFile); + return getLocalConfig(logger, configFile, validateConfig); } else { - return await getRemoteConfig(logger, configFile, apiDetails); + return await getRemoteConfig( + logger, + configFile, + apiDetails, + validateConfig, + ); } } @@ -781,7 +787,10 @@ function hasQueryCustomisation(userConfig: UserConfig): boolean { * This will parse the config from the user input if present, or generate * a default config. The parsed config is then stored to a known location. */ -export async function initConfig(inputs: InitConfigInputs): Promise { +export async function initConfig( + features: FeatureEnablement, + inputs: InitConfigInputs, +): Promise { const { logger, tempDir } = inputs; // if configInput is set, it takes precedence over configFile @@ -801,12 +810,14 @@ export async function initConfig(inputs: InitConfigInputs): Promise { logger.debug("No configuration file was provided"); } else { logger.debug(`Using configuration file: ${inputs.configFile}`); + const validateConfig = await features.getValue(Feature.ValidateDbConfig); userConfig = await loadUserConfig( logger, inputs.configFile, inputs.workspacePath, inputs.apiDetails, tempDir, + validateConfig, ); } @@ -900,7 +911,11 @@ function isLocal(configPath: string): boolean { return configPath.indexOf("@") === -1; } -function getLocalConfig(logger: Logger, configFile: string): UserConfig { +function getLocalConfig( + logger: Logger, + configFile: string, + validateConfig: boolean, +): UserConfig { // Error if the file does not exist if (!fs.existsSync(configFile)) { throw new ConfigurationError( @@ -912,6 +927,7 @@ function getLocalConfig(logger: Logger, configFile: string): UserConfig { logger, configFile, fs.readFileSync(configFile, "utf-8"), + validateConfig, ); } @@ -919,6 +935,7 @@ async function getRemoteConfig( logger: Logger, configFile: string, apiDetails: api.GitHubApiCombinedDetails, + validateConfig: boolean, ): Promise { // retrieve the various parts of the config location, and ensure they're present const format = new RegExp( @@ -958,6 +975,7 @@ async function getRemoteConfig( logger, configFile, Buffer.from(fileContents, "base64").toString("binary"), + validateConfig, ); } diff --git a/src/config/db-config.test.ts b/src/config/db-config.test.ts index a56c73134..7f2d642f4 100644 --- a/src/config/db-config.test.ts +++ b/src/config/db-config.test.ts @@ -409,6 +409,7 @@ test("parseUserConfig - successfully parses valid YAML", (t) => { - uses: foo some-unknown-option: true `, + true, ); t.truthy(result); if (t.truthy(result["paths-ignore"])) { @@ -433,6 +434,7 @@ test("parseUserConfig - throws a ConfigurationError if the file is not valid YAM queries: - foo `, + true, ), { instanceOf: ConfigurationError, @@ -454,6 +456,7 @@ test("parseUserConfig - throws a ConfigurationError if validation fails", (t) => - "some/path" queries: true `, + true, ), { instanceOf: ConfigurationError, @@ -465,3 +468,21 @@ test("parseUserConfig - throws a ConfigurationError if validation fails", (t) => const expectedMessages = ["instance.queries is not of a type(s) array"]; checkExpectedLogMessages(t, loggedMessages, expectedMessages); }); + +test("parseUserConfig - throws no ConfigurationError if validation should fail, but feature is disabled", (t) => { + const loggedMessages: LoggedMessage[] = []; + const logger = getRecordingLogger(loggedMessages); + + t.notThrows(() => + dbConfig.parseUserConfig( + logger, + "test", + ` + paths-ignore: + - "some/path" + queries: true + `, + false, + ), + ); +}); diff --git a/src/config/db-config.ts b/src/config/db-config.ts index 9ae423eb3..16cda3abf 100644 --- a/src/config/db-config.ts +++ b/src/config/db-config.ts @@ -483,6 +483,7 @@ export function generateCodeScanningConfig( * @param logger The logger to use. * @param pathInput The path to the file where `contents` was obtained from, for use in error messages. * @param contents The string contents of a YAML file to try and parse as a `UserConfig`. + * @param validateConfig Whether to validate the configuration file against the schema. * @returns The `UserConfig` corresponding to `contents`, if parsing was successful. * @throws A `ConfigurationError` if parsing failed. */ @@ -490,6 +491,7 @@ export function parseUserConfig( logger: Logger, pathInput: string, contents: string, + validateConfig: boolean, ): UserConfig { try { const schema = @@ -497,18 +499,21 @@ export function parseUserConfig( require("../../src/db-config-schema.json") as jsonschema.Schema; const doc = yaml.load(contents); - const result = new jsonschema.Validator().validate(doc, schema); - if (result.errors.length > 0) { - for (const error of result.errors) { - logger.error(error.stack); + if (validateConfig) { + const result = new jsonschema.Validator().validate(doc, schema); + + if (result.errors.length > 0) { + for (const error of result.errors) { + logger.error(error.stack); + } + throw new ConfigurationError( + errorMessages.getInvalidConfigFileMessage( + pathInput, + result.errors.map((e) => e.stack), + ), + ); } - throw new ConfigurationError( - errorMessages.getInvalidConfigFileMessage( - pathInput, - result.errors.map((e) => e.stack), - ), - ); } return doc as UserConfig; diff --git a/src/feature-flags.ts b/src/feature-flags.ts index 3a548ffa1..a1e2df6b8 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -77,6 +77,7 @@ export enum Feature { QaTelemetryEnabled = "qa_telemetry_enabled", ResolveSupportedLanguagesUsingCli = "resolve_supported_languages_using_cli", UseRepositoryProperties = "use_repository_properties", + ValidateDbConfig = "validate_db_config", } export const featureConfig: Record< @@ -287,6 +288,11 @@ export const featureConfig: Record< envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", minimumVersion: "2.23.0", }, + [Feature.ValidateDbConfig]: { + defaultValue: false, + envVar: "CODEQL_ACTION_VALIDATE_DB_CONFIG", + minimumVersion: undefined, + }, }; /** diff --git a/src/init-action.ts b/src/init-action.ts index 90971a1c1..8961b09f4 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -325,7 +325,7 @@ async function run() { } analysisKinds = await getAnalysisKinds(logger); - config = await initConfig({ + config = await initConfig(features, { analysisKinds, languagesInput: getOptionalInput("languages"), queriesInput: getOptionalInput("queries"), diff --git a/src/init.ts b/src/init.ts index 7ca6a3e39..b399ef8d9 100644 --- a/src/init.ts +++ b/src/init.ts @@ -61,10 +61,11 @@ export async function initCodeQL( } export async function initConfig( + features: FeatureEnablement, inputs: configUtils.InitConfigInputs, ): Promise { return await withGroupAsync("Load language configuration", async () => { - return await configUtils.initConfig(inputs); + return await configUtils.initConfig(features, inputs); }); }