diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/validators | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/gitlab/utils/zoom_url_validator.rb | 22 | ||||
-rw-r--r-- | app/validators/json_schemas/security_scan_info.json | 28 | ||||
-rw-r--r-- | app/validators/json_schemas/vulnerability_finding_details.json | 266 | ||||
-rw-r--r-- | app/validators/zoom_url_validator.rb | 18 |
4 files changed, 239 insertions, 95 deletions
diff --git a/app/validators/gitlab/utils/zoom_url_validator.rb b/app/validators/gitlab/utils/zoom_url_validator.rb new file mode 100644 index 00000000000..57e30dcefa6 --- /dev/null +++ b/app/validators/gitlab/utils/zoom_url_validator.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Gitlab::Utils::ZoomUrlValidator +# +# Custom validator for zoom urls +# +module Gitlab + module Utils + class ZoomUrlValidator < ActiveModel::EachValidator + ALLOWED_SCHEMES = %w(https).freeze + + def validate_each(record, attribute, value) + links_count = Gitlab::ZoomLinkExtractor.new(value).links.size + valid = Gitlab::UrlSanitizer.valid?(value, allowed_schemes: ALLOWED_SCHEMES) + + return if links_count == 1 && valid + + record.errors.add(:url, 'must contain one valid Zoom URL') + end + end + end +end diff --git a/app/validators/json_schemas/security_scan_info.json b/app/validators/json_schemas/security_scan_info.json new file mode 100644 index 00000000000..c8932c1870d --- /dev/null +++ b/app/validators/json_schemas/security_scan_info.json @@ -0,0 +1,28 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "Security::Scan#info schema", + "description": "The schema validates the content of the Security::Scan#info attribute", + "additionalProperties": false, + "properties": { + "errors": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + }, + "required": [ + "type", + "message" + ] + } + } + } +} diff --git a/app/validators/json_schemas/vulnerability_finding_details.json b/app/validators/json_schemas/vulnerability_finding_details.json index f2940866f4b..2ba1fc9e9db 100644 --- a/app/validators/json_schemas/vulnerability_finding_details.json +++ b/app/validators/json_schemas/vulnerability_finding_details.json @@ -6,60 +6,67 @@ "^.*$": { "allOf": [ { "$ref": "#/definitions/named_field" }, - { "$ref": "#/definitions/type_list" } + { "$ref": "#/definitions/detail_type" } ] } }, "definitions": { - "type_list": { + "detail_type": { "oneOf": [ { "$ref": "#/definitions/named_list" }, { "$ref": "#/definitions/list" }, { "$ref": "#/definitions/table" }, - { "$ref": "#/definitions/text" }, { "$ref": "#/definitions/url" }, { "$ref": "#/definitions/code" }, - { "$ref": "#/definitions/int" }, - + { "$ref": "#/definitions/value" }, + { "$ref": "#/definitions/diff" }, + { "$ref": "#/definitions/markdown" }, { "$ref": "#/definitions/commit" }, { "$ref": "#/definitions/file_location" }, { "$ref": "#/definitions/module_location" } ] }, - "lang_text": { - "type": "object", - "required": [ "value", "lang" ], - "properties": { - "lang": { "type": "string" }, - "value": { "type": "string" } - } - }, - "lang_text_list": { - "type": "array", - "items": { "$ref": "#/definitions/lang_text" } + "text_value": { + "type": "string" }, "named_field": { "type": "object", - "required": [ "name" ], + "required": [ + "name" + ], "properties": { - "name": { "$ref": "#/definitions/lang_text_list" }, - "description": { "$ref": "#/definitions/lang_text_list" } + "name": { + "$ref": "#/definitions/text_value", + "minLength": 1 + }, + "description": { + "$ref": "#/definitions/text_value" + } } }, "named_list": { "type": "object", "description": "An object with named and typed fields", - "required": [ "type", "items" ], + "required": [ + "type", + "items" + ], "properties": { - "type": { "const": "named-list" }, + "type": { + "const": "named-list" + }, "items": { "type": "object", "patternProperties": { "^.*$": { "allOf": [ - { "$ref": "#/definitions/named_field" }, - { "$ref": "#/definitions/type_list" } + { + "$ref": "#/definitions/named_field" + }, + { + "$ref": "#/definitions/detail_type" + } ] } } @@ -69,38 +76,45 @@ "list": { "type": "object", "description": "A list of typed fields", - "required": [ "type", "items" ], + "required": [ + "type", + "items" + ], "properties": { - "type": { "const": "list" }, + "type": { + "const": "list" + }, "items": { "type": "array", - "items": { "$ref": "#/definitions/type_list" } + "items": { + "$ref": "#/definitions/detail_type" + } } } }, "table": { "type": "object", "description": "A table of typed fields", - "required": [], + "required": [ + "type", + "rows" + ], "properties": { - "type": { "const": "table" }, - "items": { - "type": "object", - "properties": { - "header": { - "type": "array", - "items": { - "$ref": "#/definitions/type_list" - } - }, - "rows": { - "type": "array", - "items": { - "type": "array", - "items": { - "$ref": "#/definitions/type_list" - } - } + "type": { + "const": "table" + }, + "header": { + "type": "array", + "items": { + "$ref": "#/definitions/detail_type" + } + }, + "rows": { + "type": "array", + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/detail_type" } } } @@ -109,73 +123,171 @@ "text": { "type": "object", "description": "Raw text", - "required": [ "type", "value" ], + "required": [ + "type", + "value" + ], "properties": { - "type": { "const": "text" }, - "value": { "$ref": "#/definitions/lang_text_list" } + "type": { + "const": "text" + }, + "value": { + "$ref": "#/definitions/text_value" + } } }, "url": { "type": "object", "description": "A single URL", - "required": [ "type", "href" ], + "required": [ + "type", + "href" + ], "properties": { - "type": { "const": "url" }, - "text": { "$ref": "#/definitions/lang_text_list" }, - "href": { "type": "string" } + "type": { + "const": "url" + }, + "text": { + "$ref": "#/definitions/text_value" + }, + "href": { + "type": "string", + "minLength": 1, + "examples": ["http://mysite.com"] + } } }, "code": { "type": "object", "description": "A codeblock", - "required": [ "type", "value" ], + "required": [ + "type", + "value" + ], "properties": { - "type": { "const": "code" }, - "value": { "type": "string" }, - "lang": { "type": "string" } + "type": { + "const": "code" + }, + "value": { + "type": "string" + }, + "lang": { + "type": "string", + "description": "A programming language" + } } }, - "int": { + "value": { "type": "object", - "description": "An integer", - "required": [ "type", "value" ], + "description": "A field that can store a range of types of value", + "required": ["type", "value"], "properties": { - "type": { "const": "int" }, - "value": { "type": "integer" }, - "format": { - "type": "string", - "enum": [ "default", "hex" ] + "type": { "const": "value" }, + "value": { + "type": ["number", "string", "boolean"] + } + } + }, + "diff": { + "type": "object", + "description": "A diff", + "required": [ + "type", + "before", + "after" + ], + "properties": { + "type": { + "const": "diff" + }, + "before": { + "type": "string" + }, + "after": { + "type": "string" + } + } + }, + "markdown": { + "type": "object", + "description": "GitLab flavoured markdown, see https://docs.gitlab.com/ee/user/markdown.html", + "required": [ + "type", + "value" + ], + "properties": { + "type": { + "const": "markdown" + }, + "value": { + "$ref": "#/definitions/text_value", + "examples": ["Here is markdown `inline code` #1 [test](gitlab.com)\n\n![GitLab Logo](https://about.gitlab.com/images/press/logo/preview/gitlab-logo-white-preview.png)"] } } }, "commit": { "type": "object", - "description": "A specific commit within the project", - "required": [ "type", "value" ], + "description": "A commit/tag/branch within the GitLab project", + "required": [ + "type", + "value" + ], "properties": { - "type": { "const": "commit" }, - "value": { "type": "string", "description": "The commit SHA" } + "type": { + "const": "commit" + }, + "value": { + "type": "string", + "description": "The commit SHA", + "minLength": 1 + } } }, "file_location": { "type": "object", "description": "A location within a file in the project", - "required": [ "type", "file_name", "line_start" ], + "required": [ + "type", + "file_name", + "line_start" + ], "properties": { - "type": { "const": "file-location" }, - "file_name": { "type": "string" }, - "line_start": { "type": "integer" }, - "line_end": { "type": "integer" } + "type": { + "const": "file-location" + }, + "file_name": { + "type": "string", + "minLength": 1 + }, + "line_start": { + "type": "integer" + }, + "line_end": { + "type": "integer" + } } }, "module_location": { "type": "object", "description": "A location within a binary module of the form module+relative_offset", - "required": [ "type", "module_name", "offset" ], + "required": [ + "type", + "module_name", + "offset" + ], "properties": { - "type": { "const": "module-location" }, - "module_name": { "type": "string" }, - "offset": { "type": "integer" } + "type": { + "const": "module-location" + }, + "module_name": { + "type": "string", + "minLength": 1, + "examples": ["compiled_binary"] + }, + "offset": { + "type": "integer", + "examples": [100] + } } } } diff --git a/app/validators/zoom_url_validator.rb b/app/validators/zoom_url_validator.rb deleted file mode 100644 index e0f8e4e34a2..00000000000 --- a/app/validators/zoom_url_validator.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# ZoomUrlValidator -# -# Custom validator for zoom urls -# -class ZoomUrlValidator < ActiveModel::EachValidator - ALLOWED_SCHEMES = %w(https).freeze - - def validate_each(record, attribute, value) - links_count = Gitlab::ZoomLinkExtractor.new(value).links.size - valid = Gitlab::UrlSanitizer.valid?(value, allowed_schemes: ALLOWED_SCHEMES) - - return if links_count == 1 && valid - - record.errors.add(:url, 'must contain one valid Zoom URL') - end -end |