Compare commits

..

No commits in common. "8d5d4942e11ce20ecb9b11727a8ccf54f05382e1" and "fd7fd0ad65078ab819563585111d60948a9c1afc" have entirely different histories.

5 changed files with 21 additions and 51 deletions

View file

@ -619,6 +619,8 @@ private:
void addRoot(const nix::StorePath & storePath); void addRoot(const nix::StorePath & storePath);
void runMetricsExporter();
public: public:
void showStatus(); void showStatus();

View file

@ -242,35 +242,23 @@ sub push : Chained('api') PathPart('push') Args(0) {
$c->{stash}->{json}->{jobsetsTriggered} = []; $c->{stash}->{json}->{jobsetsTriggered} = [];
my $force = exists $c->request->query_params->{force}; my $force = exists $c->request->query_params->{force};
my @jobsetNames = split /,/, ($c->request->query_params->{jobsets} // ""); my @jobsets = split /,/, ($c->request->query_params->{jobsets} // "");
my @jobsets; foreach my $s (@jobsets) {
foreach my $s (@jobsetNames) {
my ($p, $j) = parseJobsetName($s); my ($p, $j) = parseJobsetName($s);
my $jobset = $c->model('DB::Jobsets')->find($p, $j); my $jobset = $c->model('DB::Jobsets')->find($p, $j);
push @jobsets, $jobset if defined $jobset; next unless defined $jobset && ($force || ($jobset->project->enabled && $jobset->enabled));
triggerJobset($self, $c, $jobset, $force);
} }
my @repos = split /,/, ($c->request->query_params->{repos} // ""); my @repos = split /,/, ($c->request->query_params->{repos} // "");
foreach my $r (@repos) { foreach my $r (@repos) {
foreach ($c->model('DB::Jobsets')->search( triggerJobset($self, $c, $_, $force) foreach $c->model('DB::Jobsets')->search(
{ 'project.enabled' => 1, 'me.enabled' => 1 }, { 'project.enabled' => 1, 'me.enabled' => 1 },
{ {
join => 'project', join => 'project',
where => \ [ 'exists (select 1 from JobsetInputAlts where project = me.project and jobset = me.name and value = ?)', [ 'value', $r ] ], where => \ [ 'exists (select 1 from JobsetInputAlts where project = me.project and jobset = me.name and value = ?)', [ 'value', $r ] ],
order_by => 'me.id DESC' order_by => 'me.id DESC'
})) { });
push @jobsets, $_;
}
}
foreach my $jobset (@jobsets) {
requireRestartPrivileges($c, $jobset->project);
}
foreach my $jobset (@jobsets) {
next unless defined $jobset && ($force || ($jobset->project->enabled && $jobset->enabled));
triggerJobset($self, $c, $jobset, $force);
} }
$self->status_ok( $self->status_ok(

View file

@ -35,17 +35,6 @@ my $queuedBuilds = $ctx->makeAndEvaluateJobset(
build => 0 build => 0
); );
# Login and save cookie for future requests
my $req = request(POST '/login',
Referer => 'http://localhost/',
Content => {
username => 'root',
password => 'rootPassword'
}
);
is($req->code, 302, "Logging in gets a 302");
my $cookie = $req->header("set-cookie");
subtest "/api/queue" => sub { subtest "/api/queue" => sub {
my $response = request(GET '/api/queue?nr=1'); my $response = request(GET '/api/queue?nr=1');
ok($response->is_success, "The API enpdoint showing the queue returns 200."); ok($response->is_success, "The API enpdoint showing the queue returns 200.");
@ -113,17 +102,6 @@ subtest "/api/nrbuilds" => sub {
}; };
subtest "/api/push" => sub { subtest "/api/push" => sub {
subtest "without authentication" => sub {
my $build = $finishedBuilds->{"one_job"};
my $jobset = $build->jobset;
my $projectName = $jobset->project->name;
my $jobsetName = $jobset->name;
is($jobset->forceeval, undef, "The existing jobset is not set to be forced to eval");
my $response = request(GET "/api/push?jobsets=$projectName:$jobsetName&force=1");
is($response->code, 403, "The API enpdoint for triggering jobsets requires authentication.");
};
subtest "with a specific jobset" => sub { subtest "with a specific jobset" => sub {
my $build = $finishedBuilds->{"one_job"}; my $build = $finishedBuilds->{"one_job"};
my $jobset = $build->jobset; my $jobset = $build->jobset;
@ -131,8 +109,7 @@ subtest "/api/push" => sub {
my $jobsetName = $jobset->name; my $jobsetName = $jobset->name;
is($jobset->forceeval, undef, "The existing jobset is not set to be forced to eval"); is($jobset->forceeval, undef, "The existing jobset is not set to be forced to eval");
my $response = request(GET "/api/push?jobsets=$projectName:$jobsetName&force=1", my $response = request(GET "/api/push?jobsets=$projectName:$jobsetName&force=1");
Cookie => $cookie);
ok($response->is_success, "The API enpdoint for triggering jobsets returns 200."); ok($response->is_success, "The API enpdoint for triggering jobsets returns 200.");
my $data = is_json($response); my $data = is_json($response);
@ -151,8 +128,7 @@ subtest "/api/push" => sub {
print STDERR $repo; print STDERR $repo;
my $response = request(GET "/api/push?repos=$repo&force=1", my $response = request(GET "/api/push?repos=$repo&force=1");
Cookie => $cookie);
ok($response->is_success, "The API enpdoint for triggering jobsets returns 200."); ok($response->is_success, "The API enpdoint for triggering jobsets returns 200.");
my $data = is_json($response); my $data = is_json($response);

View file

@ -11,14 +11,20 @@ my $ctx = test_context();
Catalyst::Test->import('Hydra'); Catalyst::Test->import('Hydra');
$ctx->db(); # Ensure DB initialization. my $user = $ctx->db()->resultset('Users')->create({
username => 'alice',
emailaddress => 'root@invalid.org',
password => '!'
});
$user->setPassword('foobar');
$user->userroles->update_or_create({ role => 'admin' });
# Login and save cookie for future requests # Login and save cookie for future requests
my $req = request(POST '/login', my $req = request(POST '/login',
Referer => 'http://localhost/', Referer => 'http://localhost/',
Content => { Content => {
username => 'root', username => 'alice',
password => 'rootPassword' password => 'foobar'
} }
); );
is($req->code, 302, "Logging in gets a 302"); is($req->code, 302, "Logging in gets a 302");

View file

@ -115,13 +115,11 @@ sub db {
$self->{_db} = Hydra::Model::DB->new(); $self->{_db} = Hydra::Model::DB->new();
if (!(defined $setup && $setup == 0)) { if (!(defined $setup && $setup == 0)) {
my $user = $self->{_db}->resultset('Users')->create({ $self->{_db}->resultset('Users')->create({
username => "root", username => "root",
emailaddress => 'root@invalid.org', emailaddress => 'root@invalid.org',
password => '!' password => ''
}); });
$user->setPassword('rootPassword');
$user->userroles->update_or_create({ role => 'admin' });
} }
} }