diff --git a/hydra-api.yaml b/hydra-api.yaml index 6b67a9fe..a2fb1bc3 100644 --- a/hydra-api.yaml +++ b/hydra-api.yaml @@ -688,18 +688,6 @@ components: 'type': description: The type of this input type: string - enum: - - bzr - - bzr-checkout - - bitbucketpulls - - darcs - - git - - githubpulls - - gitlabpulls - - hg - - path - - svn - - svn-checkout revision: nullable: true description: A Git/Mercurial commit hash or a Subversion revision number. diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index 24776994..ae0bb018 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -213,6 +213,22 @@ sub checkInputValue { } +sub knownInputTypes { + my ($c) = @_; + + my @keys = keys %{$c->stash->{inputTypes}}; + my $types = ""; + my $counter = 0; + + foreach my $key (@keys) { + $types = $types . "and ‘$key’" if ++$counter == scalar(@keys); + $types = $types . "‘$key’, " if $counter != scalar(@keys); + } + + return $types; +} + + sub updateJobset { my ($c, $jobset) = @_; @@ -275,9 +291,10 @@ sub updateJobset { my $type = $inputData->{type}; my $value = $inputData->{value}; my $emailresponsible = defined $inputData->{emailresponsible} ? 1 : 0; + my $types = knownInputTypes($c); - error($c, "Invalid input name ‘$name’.") unless $name =~ /^[[:alpha:]][\w-]*$/; - error($c, "Invalid input type ‘$type’.") unless defined $c->stash->{inputTypes}->{$type}; + badRequest($c, "Invalid input name ‘$name’.") unless $name =~ /^[[:alpha:]][\w-]*$/; + badRequest($c, "Invalid input type ‘$type’; valid types: $types.") unless defined $c->stash->{inputTypes}->{$type}; my $input = $jobset->jobsetinputs->create( { name => $name, diff --git a/t/Controller/Jobset/http.t b/t/Controller/Jobset/http.t index dc11c7a2..be2950f0 100644 --- a/t/Controller/Jobset/http.t +++ b/t/Controller/Jobset/http.t @@ -157,6 +157,36 @@ subtest 'Update jobset "job" to legacy type' => sub { }; +subtest 'Update jobset "job" to have an invalid input type' => sub { + my $jobsetupdate = request(PUT '/jobset/tests/job', + Accept => 'application/json', + Content_Type => 'application/json', + Cookie => $cookie, + Content => encode_json({ + enabled => 3, + visible => JSON::true, + name => "job", + type => 0, + nixexprinput => "ofborg", + nixexprpath => "release.nix", + inputs => { + ofborg => { + name => "ofborg", + type => "123", + value => "https://github.com/NixOS/ofborg.git released" + } + }, + description => "test jobset", + checkinterval => 0, + schedulingshares => 50, + keepnr => 1 + }) + ); + ok(!$jobsetupdate->is_success); + ok($jobsetupdate->content =~ m/Invalid input type.*valid types:/); +}; + + subtest 'Delete jobset "job"' => sub { my $jobsetinfo = request(DELETE '/jobset/tests/job', Accept => 'application/json',