Skip to content

Commit

Permalink
Validate key existence before proceeding
Browse files Browse the repository at this point in the history
  • Loading branch information
josegomezr committed Nov 14, 2023
1 parent eab84ba commit a9f3e19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/OpenQA/WebAPI/Plugin/ObsRsync.pm
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ sub _for_every_batch {

# Based on https://www.suse.com/c/multi-factor-authentication-on-suses-build-service/
sub _bs_ssh_sign ($key, $realm, $value) {

die "SSH Key File not found at $key" unless (-e $key || -z $key);
# This needs to be a bit portable for CI testing
my $tmp = Mojo::File::tempfile->spew($value);
my @lines = split "\n", qx/ssh-keygen -Y sign -f "$key" -q -n "$realm" < $tmp/;
Expand Down
18 changes: 16 additions & 2 deletions t/ui/27-plugin_obs_rsync_obs_status.t
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ $t->get_ok('/admin/obs_rsync/queue')->status_is(200, 'jobs list')->content_like(
$t->get_ok('/admin/obs_rsync/')->status_is(200, 'project list')->content_like(qr/published/)->content_like(qr/dirty/)
->content_like(qr/publishing/);

subtest 'test build service ssh authentication' => sub {
subtest 'build service ssh authentication' => sub {
is($helper->is_status_dirty('ProjWithAuth'), 1, 're-authenticate with ssh auth');
};

subtest 'test build service authentication signature generation' => sub {
subtest 'build service authentication: signature generation' => sub {
$mocked_time = 1664187470;
note "time right now: " . time();

Expand All @@ -228,6 +228,20 @@ subtest 'test build service authentication signature generation' => sub {
$mocked_time = undef;
};

subtest 'build service authentication: error handling' => sub {
$ssh_keyfile->remove();
throws_ok {
$helper->is_status_dirty('ProjTestingSignature')
}
qr/SSH Key File not found at/, 'Unexpected key detected';

$ssh_keyfile->touch();
throws_ok {
$helper->is_status_dirty('ProjTestingSignature')
}
qr/SSH Key File not found at/, 'Unexpected key detected';
};

$server_instance->stop;
done_testing();

Expand Down

0 comments on commit a9f3e19

Please sign in to comment.