Blame 0004-parse_url_settings-don-t-parse-value-for-non-asset-t.patch

8c41f40
From 0340774523d7b11bd54c59780e1504d12d697f3d Mon Sep 17 00:00:00 2001
8c41f40
From: Adam Williamson <awilliam@redhat.com>
8c41f40
Date: Wed, 18 Nov 2020 10:02:08 -0800
8c41f40
Subject: [PATCH 4/4] parse_url_settings: don't parse value for non-asset types
8c41f40
8c41f40
If a test sets NOT_ASSET_URL: http://some/parseable.url , we don't
8c41f40
actually want to parse that to NOT_ASSET: parseable.url , because
8c41f40
we aren't going to download it later. We had this bug back in 2016
8c41f40
and fixed it specifically in f54a18f , then regressed it again in
8c41f40
391f95e3 because we needed to pass the parsed file name to the
8c41f40
asset type check.
8c41f40
8c41f40
When we split up `parse_url_settings` and `create_downloads_list`
8c41f40
the asset type check wound up in `create_downloads_list`. To fix
8c41f40
the bug we can't avoid duplicating it here - we do have to check
8c41f40
it in both places, here to avoid setting $settings->{$short} if
8c41f40
it's not an asset type, and there to avoid doing the download if
8c41f40
somehow both NOT_ASSET_URL and NOT_ASSET wind up being set by
8c41f40
templates or the scheduler. It's not worth splitting the check to
8c41f40
a shared utility function as you still need flow control. I don't
8c41f40
think the log message will ever be duplicated as we should never
8c41f40
manage to reach and fail the check *both* times (only one or the
8c41f40
other).
8c41f40
8c41f40
Signed-off-by: Adam Williamson <awilliam@redhat.com>
8c41f40
---
8c41f40
 lib/OpenQA/JobSettings.pm | 13 +++++++++----
8c41f40
 t/api/02-iso-download.t   |  1 +
8c41f40
 2 files changed, 10 insertions(+), 4 deletions(-)
8c41f40
8c41f40
diff --git a/lib/OpenQA/JobSettings.pm b/lib/OpenQA/JobSettings.pm
8c41f40
index c3c7d97c9..335c8d1ef 100644
8c41f40
--- a/lib/OpenQA/JobSettings.pm
8c41f40
+++ b/lib/OpenQA/JobSettings.pm
8c41f40
@@ -21,7 +21,7 @@ use File::Basename;
8c41f40
 use Mojo::URL;
8c41f40
 use Mojo::Util 'url_unescape';
8c41f40
 use OpenQA::Log 'log_debug';
8c41f40
-use OpenQA::Utils 'get_url_short';
8c41f40
+use OpenQA::Utils qw(asset_type_from_setting get_url_short);
8c41f40
 
8c41f40
 sub generate_settings {
8c41f40
     my ($params) = @_;
8c41f40
@@ -113,9 +113,9 @@ sub handle_plus_in_settings {
8c41f40
 
8c41f40
 # Given a hashref of settings, parse any whose names end in _URL
8c41f40
 # to the short name, then if there is not already a setting with
8c41f40
-# the short name, set it to the filename from the URL (with the
8c41f40
-# compression extension removed in the case of _DECOMPRESS_URL).
8c41f40
-# This has to happen *before* generate_jobs
8c41f40
+# the short name and the setting is an asset type, set it to the
8c41f40
+# filename from the URL (with the compression extension removed
8c41f40
+# in the case of _DECOMPRESS_URL).
8c41f40
 sub parse_url_settings {
8c41f40
     my ($settings) = @_;
8c41f40
     for my $setting (keys %$settings) {
8c41f40
@@ -137,6 +137,11 @@ sub parse_url_settings {
8c41f40
             log_debug("Unable to get filename from $url. Ignoring $setting");
8c41f40
             next;
8c41f40
         }
8c41f40
+        # We shouldn't set the short setting for non-asset types
8c41f40
+        unless (asset_type_from_setting($short, $filename)) {
8c41f40
+            log_debug("_URL downloading only allowed for asset types! $short is not an asset type");
8c41f40
+            next;
8c41f40
+        }
8c41f40
         $settings->{$short} = $filename;
8c41f40
     }
8c41f40
     return undef;
8c41f40
diff --git a/t/api/02-iso-download.t b/t/api/02-iso-download.t
8c41f40
index 914d30552..a718ef154 100644
8c41f40
--- a/t/api/02-iso-download.t
8c41f40
+++ b/t/api/02-iso-download.t
8c41f40
@@ -158,6 +158,7 @@ check_job_setting($t, $rsp, 'KERNEL', 'callitvmlinuz',
8c41f40
 $rsp = schedule_iso({%params, NO_ASSET_URL => 'http://localhost/nonexistent.iso'});
8c41f40
 is($rsp->json->{count}, $expected_job_count, 'a regular ISO post creates the expected number of jobs');
8c41f40
 check_download_asset('non-asset _URL');
8c41f40
+check_job_setting($t, $rsp, 'NO_ASSET', undef, 'NO_ASSET is not parsed from NO_ASSET_URL');
8c41f40
 
8c41f40
 # Using asset _URL but without filename extractable from URL create warning in log file, jobs, but no gru job
8c41f40
 $rsp = schedule_iso({%iso, ISO_URL => 'http://localhost'});
8c41f40
-- 
8c41f40
2.29.2
8c41f40