Skip to content

Commit

Permalink
Merge pull request #5512 from perlpunk/module-not-found
Browse files Browse the repository at this point in the history
Return 404 if module not found
  • Loading branch information
okurz authored Mar 14, 2024
2 parents 40a3af5 + 1ded57c commit 4177e32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/OpenQA/WebAPI/Controller/Step.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use Mojo::JSON 'decode_json';
sub _init ($self) {
return 0 unless my $job = $self->app->schema->resultset('Jobs')->find($self->param('testid'));
my %attrs = (rows => 1, order_by => {-desc => 'id'});
my $module = $job->modules->find({name => $self->param('moduleid')}, \%attrs);
my $module = $job->modules->find({name => $self->param('moduleid')}, \%attrs) or return 0;
$self->stash(job => $job);
$self->stash(testname => $job->name);
$self->stash(distri => $job->DISTRI);
Expand Down
5 changes: 4 additions & 1 deletion t/27-errorpages.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ subtest 'error pages shown for OpenQA::WebAPI::Controller::Step' => sub {
->content_type_is('text/plain;charset=UTF-8');
$t->get_ok("/tests/$existing_job/modules/installer_timezone/steps/1/edit")->status_is(200);

subtest 'get error 404 if job not found (instead of 500 and Perl warnings)' => sub {
subtest 'get error 404 if job or module not found' => sub {
my $non_existing_job = 99999;
$t->get_ok("/tests/$non_existing_job/modules/installer_timezone/steps/1")->status_is(302, 'redirection');
$t->get_ok("/tests/$non_existing_job/modules/installer_timezone/steps/1",
{'X-Requested-With' => 'XMLHttpRequest'})->status_is(404);
$t->get_ok("/tests/$non_existing_job/modules/installer_timezone/steps/1/src")->status_is(404);
$t->get_ok("/tests/$non_existing_job/modules/installer_timezone/steps/1/src.txt")->status_is(404);
$t->get_ok("/tests/$non_existing_job/modules/installer_timezone/steps/1/edit")->status_is(404);
$t->get_ok("/tests/$existing_job/modules/nonexistingmodule/steps/1/src")->status_is(404);
$t->get_ok("/tests/$existing_job/modules/nonexistingmodule/steps/1/src.txt")->status_is(404);
$t->get_ok("/tests/$existing_job/modules/nonexistingmodule/steps/1/edit")->status_is(404);
};
};

Expand Down

0 comments on commit 4177e32

Please sign in to comment.