Skip to content

Commit

Permalink
Disallow trailing newlines in test names
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Feb 21, 2025
1 parent f088b72 commit 6cbf8d9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/OpenQA/Jobs/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Exporter 'import';
# define regex for validating test names in accordance with `JobScenarios-01.yaml` and `JobTemplates-01.yaml`
# note: In contrast to the YAML schema a few more characters are allowed here as they are useful for manually
# triggered jobs, e.g. via `openqa-clone-custom-git-refspec`.
use constant TEST_NAME_REGEX => qr|^[A-Za-z 0-9_*.+,:/#@%"'-]+$|;
use constant TEST_NAME_REGEX => qr|^[A-Za-z 0-9_*.+,:/#@%"'-]+\z|;

# job states
use constant {
Expand Down
2 changes: 1 addition & 1 deletion t/api/04-jobs.t
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ subtest 'get job status' => sub {
};

subtest 'validation of test name' => sub {
my @disallowed = ('spam=eggs', "spam\teggs");
my @disallowed = ('spam=eggs', "spam\teggs", "spam\neggs", "spam eggs\n");
my @allowed = ('spam.eggs', 'spam+eggs', 'spam:"eggs"', 'spam@eggs', "spam 'eggs'");
$t->post_ok('/api/v1/jobs', form => {TEST => $_})->status_is(400, "test name $_ disallowed") for @disallowed;
$t->json_is('/error' => 'The following settings are invalid: TEST', 'error for invalid test name returned');
Expand Down

0 comments on commit 6cbf8d9

Please sign in to comment.