File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ use Mojo::Base -base, -signatures;
6
6
7
7
use Exporter ' import' ;
8
8
9
+ # define regex for validating test names in accordance with `JobScenarios-01.yaml` and `JobTemplates-01.yaml`
10
+ use constant TEST_NAME_REGEX => qr / ^[A-Za-z\s 0-9_*.+-]+$ / ;
11
+
9
12
# job states
10
13
use constant {
11
14
# initial job state; the job is supposed to be assigned to a worker by the scheduler
@@ -103,6 +106,7 @@ use constant DEFAULT_JOB_PRIORITY => 50;
103
106
use constant TAG_ID_COLUMN => " concat(VERSION, '-', BUILD)" ;
104
107
105
108
our @EXPORT = qw(
109
+ TEST_NAME_REGEX
106
110
ASSIGNED
107
111
CANCELLED
108
112
COMPLETE_RESULTS
Original file line number Diff line number Diff line change @@ -125,9 +125,10 @@ sub create_from_settings {
125
125
die ' The ' . join (' ,' , @invalid_keys ) . " cannot include / in value\n " if @invalid_keys ;
126
126
127
127
# validate special settings
128
- my %special_settings = (_PRIORITY => delete $settings {_PRIORITY });
128
+ my %special_settings = (TEST => delete $settings { TEST }, _PRIORITY => delete $settings {_PRIORITY });
129
129
my $validator = Mojolicious::Validator-> new;
130
130
my $v = Mojolicious::Validator::Validation-> new(validator => $validator , input => \%special_settings );
131
+ my $test = $v -> required(' TEST' )-> like(TEST_NAME_REGEX)-> param;
131
132
my $prio = $v -> optional(' _PRIORITY' )-> num-> param;
132
133
die ' The following settings are invalid: ' . join (' , ' , @{$v -> failed}) . " \n " if $v -> has_error;
133
134
@@ -176,9 +177,9 @@ sub create_from_settings {
176
177
my $value = $settings {$key };
177
178
$settings {$key } = decode_utf8 encode_json $value if (ref $value eq ' ARRAY' || ref $value eq ' HASH' );
178
179
}
179
- $new_job_args {TEST } = $settings {TEST };
180
180
181
181
# move important keys from the settings directly to the job
182
+ $new_job_args {TEST } = $test ;
182
183
for my $key (OpenQA::Schema::Result::Jobs::MAIN_SETTINGS) {
183
184
if (my $value = delete $settings {$key }) { $new_job_args {$key } = $value }
184
185
}
Original file line number Diff line number Diff line change @@ -825,6 +825,16 @@ subtest 'get job status' => sub {
825
825
-> json_is(' /error_status' => 404, ' Status code correct' )-> json_is(' /error' => ' Job does not exist' );
826
826
};
827
827
828
+ subtest ' validation of test name' => sub {
829
+ my @disallowed = (' spam@eggs' , ' spam:eggs' );
830
+ my @allowed = (' spam.eggs' , ' spam+eggs' );
831
+ $t -> post_ok(' /api/v1/jobs' , form => {TEST => $_ })-> status_is(400, " test name $_ disallowed" ) for @disallowed ;
832
+ $t -> json_is(' /error' => ' The following settings are invalid: TEST' , ' error for invalid test name returned' );
833
+ $t -> post_ok(' /api/v1/jobs' , form => {TEST => $_ })-> status_is(200, " test name $_ allowed" ) for @allowed ;
834
+ is $jobs -> search({TEST => {-in => \@disallowed }})-> count, 0, ' no jobs with disallowed names created' ;
835
+ is $jobs -> search({TEST => {-in => \@allowed }})-> count, @allowed , ' all jobs with allowed names created' ;
836
+ };
837
+
828
838
subtest ' cancel job' => sub {
829
839
$t -> post_ok(' /api/v1/jobs/99963/cancel' )-> status_is(200);
830
840
is_deeply(
You can’t perform that action at this time.
0 commit comments