#116 URI validation does not work
Opened by lholecek. Modified

Script validate.py accepts invalid URIs but they should be properly check according to a field in schema with format: uri.

This makes it harder for user to validate their messages against schemas. The seemingly valid messages would be rejected by another services that uses schamas from this repo too (it does not use the jsonschema Python library).

Reproduced with:

make convert
./scripts/validate.py tmp/error.json <(echo '{"reason": "CI pipeline aborted", "issue_url": "unknown"}')

Contents of tmp/error.json (generated by make convert from schemas/error.yaml):

 jq < tmp/error.json 
{
  "$id": "error",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Information related to error reporting.",
  "properties": {
    "issue_url": {
      "description": "If the CI system is able to automatically file an issue/ticket for the error, put the URL here.",
      "examples": [
        "http://sentry.somewhere.com/baseos/production/issues/1149/"
      ],
      "type": "string",
      "format": "uri"
    },
    "reason": {
      "description": "Reason of the error.",
      "examples": [
        "CI pipeline aborted.",
        "No test results available after 24 hours."
      ],
      "type": "string"
    }
  },
  "required": [
    "reason"
  ],
  "type": "object"
}

Note: The invalid message was rejected later in an internal service that uploads results to ResultsDB. The error was:

$.error.issue_url: does not match the uri pattern (^[a-zA-Z][a-zA-Z0-9+-.]*:[^\s]*$)|(^//[^\s]*$)

After installing Python package rfc3987 (or rfc3986-validator) the validation fails as expected but only prints "Validation failed".

Another problem is that there is no indication that the URI is not checked when the package is not installed.

Well, feels like at least adding that package is always better then just pass? No idea currently about fixing the problem with not sufficient validation error.

Well, feels like at least adding that package is always better then just pass? No idea currently about fixing the problem with not sufficient validation error.

I think I figured everything out. :) There can be a dummy import in the validation script to ensure that the required package is installed.

See: #116

Metadata
Related Pull Requests