diff --git a/lib/OpenQA/WebAPI/Controller/Step.pm b/lib/OpenQA/WebAPI/Controller/Step.pm index 23100d512e2..55cfb9201b5 100644 --- a/lib/OpenQA/WebAPI/Controller/Step.pm +++ b/lib/OpenQA/WebAPI/Controller/Step.pm @@ -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); diff --git a/t/27-errorpages.t b/t/27-errorpages.t index 59538d63a68..7a3ea5d21db 100644 --- a/t/27-errorpages.t +++ b/t/27-errorpages.t @@ -34,7 +34,7 @@ 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", @@ -42,6 +42,9 @@ subtest 'error pages shown for OpenQA::WebAPI::Controller::Step' => sub { $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); }; };