Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job templates: Escape dot in regex #3104

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions public/schema/JobTemplates-01.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ required:
- products
- scenarios
patternProperties:
"^.[a-z0-9_]+$":
'^\.[a-z0-9_]+$':
type: object
description: Definitions that can be re-used

Expand All @@ -17,11 +17,11 @@ properties:
type: object
additionalProperties: false
patternProperties:
"^[a-z0-9_]+$":
'^[a-z0-9_]+$':
type: object
description: The architecture of the test suite(s) eg. ppc64le
patternProperties:
"^.*$":
'^.*$':
type: array
description: The product to run the test suite(s) on
items:
Expand All @@ -33,7 +33,7 @@ properties:
description: A test suite with machine and/ or priority specified, or a custom job template name if testsuite was specified
additionalProperties: false
patternProperties:
&testsuite-pattern "^[A-Za-z\\s0-9_*.+-]+$":
&testsuite-pattern '^[A-Za-z\s0-9_*.+-]+$':
type: object
additionalProperties: false
properties:
Expand All @@ -50,7 +50,7 @@ properties:
description: Additional test variables to be set
additionalProperties: false
patternProperties:
"^[A-Z_+]+[A-Z0-9_]*$":
'^[A-Z_+]+[A-Z0-9_]*$':
type: string
testsuite:
type: [string, 'null']
Expand All @@ -65,7 +65,7 @@ properties:
type: object
additionalProperties: false
patternProperties:
"^[a-z0-9_]+$":
'^[a-z0-9_]+$':
type: object
description: The architecture to define a default configuration for eg. ppc64le
required:
Expand All @@ -81,7 +81,7 @@ properties:
type: object
additionalProperties: false
patternProperties:
"^[A-Za-z0-9._*-]+$":
'^[A-Za-z0-9._*-]+$':
type: object
description: The name of a product (medium)
required:
Expand Down
16 changes: 12 additions & 4 deletions t/16-utils-job-templates.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use lib "$Bin/lib";
use OpenQA::YAML qw(load_yaml validate_data);
use Mojo::File qw(path tempdir tempfile);

my $schema = "$Bin/../public/schema/JobTemplates-01.yaml";
my $template_openqa = "$Bin/data/job-templates/openqa.yaml";
my $template_openqa_null = "$Bin/data/job-templates/openqa-null.yaml";
my %default_args = (schema_file => $schema);
my $schema = "$Bin/../public/schema/JobTemplates-01.yaml";
my $template_openqa = "$Bin/data/job-templates/openqa.yaml";
my $template_openqa_null = "$Bin/data/job-templates/openqa-null.yaml";
my $template_openqa_invalid = "$Bin/data/job-templates/openqa-invalid.yaml";
my %default_args = (schema_file => $schema);

my $invalid_schema = "$Bin/data/job-templates/schema-invalid.yaml";

Expand All @@ -50,4 +51,11 @@ if (@$errors) {
}
is scalar @$errors, 0, "Valid template with testsuite null - no errors";

$errors = validate_data(%default_args, data => load_yaml(file => $template_openqa_invalid));
is scalar @$errors, 1, "Invalid toplevel key detected"
or do {
diag "Error: $_" for @$errors;
};
like($errors->[0], qr{/: Properties not allowed: invalid.}, 'Invalid toplevel key error message');

done_testing;
15 changes: 15 additions & 0 deletions t/data/job-templates/openqa-invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
invalid:
toplevel: key

products:
foo:
distri: openqa
flavor: dev
version: '*'
scenarios:
x86_64:
foo:
- bar:
testsuite: null
settings:
FOO: BAR