Skip to content

Commit

Permalink
Handle OBS missing feature errors gracefully when checking for embargo
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 14, 2024
1 parent 7440830 commit 727c794
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/Cavil/OBS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ sub check_for_embargo ($self, $api, $request) {
croak "$url: " . $res->code unless $res->is_success;

for my $project ($res->dom->find('action [project]')->map('attr', 'project')->uniq->each) {
my $url = _url($api, 'public', 'source', $project, '_attribute');
my $res = $self->_get($url);
next if $res->code == 404;
my $url = _url($api, 'public', 'source', $project, '_attribute');
my $res = $self->_get($url);
my $code = $res->code;
next if $code == 404;

# Looks like OBS has repo types that do not support attributes yet and produces a bad 400 response in such cases
# (501 is supposed to treplace it in the future)
next if $code == 400 && $res->dom->at('status[code=remote_project]');
next if $code == 501;

croak "$url: " . $res->code unless $res->is_success;
return 1 if $res->dom->at('attributes attribute[name=EmbargoDate]');
}
Expand Down
36 changes: 36 additions & 0 deletions t/obs.t
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,40 @@ get '/public/source/:project/_attribute' => [project => 'SUSE:Maintenance:34725'
</attributes>
EOF

get '/public/request/5678' => {text => <<'EOF'};
<request id="5678" creator="test2">
<action type="maintenance_release">
<source project="SUSE:Maintenance:5678" package="perl-Mojolicious.SUSE_SLE-15-SP2_Update"
rev="961b20692bc318a3c6ab3166312425dc"/>
<target project="SUSE:SLE-15-SP2:Update" package="curl-perl-Mojolicious.33128"/>
</action>
<description>requesting release</description>
</request>
EOF

get '/public/source/:project/_attribute' => [project => 'SUSE:Maintenance:5678'] => {status => 400, text => <<'EOF'};
<status code="remote_project">
<summary>Attribute access to remote project is not yet supported</summary>
</status
EOF

get '/public/request/6789' => {text => <<'EOF'};
<request id="5678" creator="test2">
<action type="maintenance_release">
<source project="SUSE:Maintenance:6789" package="perl-Mojolicious.SUSE_SLE-15-SP2_Update"
rev="961b20692bc318a3c6ab3166312425df"/>
<target project="SUSE:SLE-15-SP2:Update" package="curl-perl-Mojolicious.33129"/>
</action>
<description>requesting release</description>
</request>
EOF

get '/public/source/:project/_attribute' => [project => 'SUSE:Maintenance:6789'] => {status => 501, text => <<'EOF'};
<status code="remote_project">
<summary>Attribute access to remote project is not yet supported</summary>
</status
EOF

my $AUTHENTICATED = 0;
get '/source/:project/kernel-default' => [project => ['openSUSE:Factory']] => (query => {view => 'info'}) => sub ($c) {
if (($c->req->headers->authorization // '') =~ /^Signature keyId="legaldb",algorithm="ssh",.+,created="\d+"$/) {
Expand Down Expand Up @@ -659,6 +693,8 @@ subtest 'Embargo' => sub {
is $obs->check_for_embargo($api, 1234), 1, 'embargoed';
is $obs->check_for_embargo($api, 1235), 0, 'not embargoed';
is $obs->check_for_embargo($api, 324874), 1, 'embargoed';
is $obs->check_for_embargo($api, 5678), 0, 'not embargoed';
is $obs->check_for_embargo($api, 6789), 0, 'not embargoed';
};

subtest 'Bot API (with Minion background jobs)' => sub {
Expand Down

0 comments on commit 727c794

Please sign in to comment.