diff --git a/lib/MirrorCache/Schema/ResultSet/Server.pm b/lib/MirrorCache/Schema/ResultSet/Server.pm index 5e669304..9434e968 100644 --- a/lib/MirrorCache/Schema/ResultSet/Server.pm +++ b/lib/MirrorCache/Schema/ResultSet/Server.pm @@ -126,7 +126,6 @@ select x.id as mirror_id, case when support_scheme > 0 then '$capability' else '$capabilityx' end as scheme, hostname, urldir, -folder_path, mtime, dist, case $weight_country_case when region $avoid_region= '$region' then 1 else 0 end rating_country, @@ -138,8 +137,7 @@ support_ipv, rating_ipv from ( select s.id, $hostname as hostname, - left(concat(s.urldir),$MIRRORCACHE_MAX_PATH) as urldir, - f.path as folder_path, + left(concat(s.urldir, f.path),$MIRRORCACHE_MAX_PATH) as urldir, s.mtime, s.lat as lat, s.lng as lng, diff --git a/lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm b/lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm index 5752313d..e9c55383 100644 --- a/lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm +++ b/lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm @@ -46,7 +46,7 @@ sub register { } my $limit = 8; eval { - $limit = $app->mcconfig->limit_mirrorlist_folder // $limit; + $limit = $app->mcconfig->limit_mirrorlist_folder || $limit; }; my (@mirrors_country, @mirrors_region, @mirrors_rest); my $project_id = $c->mcproject->get_id($path); @@ -782,16 +782,16 @@ sub _collect_mirrors { my $vpn = $dm->vpn; my ($lat, $lng) = $dm->coord; my $avoid_countries = $dm->avoid_countries; - my $mirrorlist = $dm->mirrorlist; + my $schemastrict = 1; + $schemastrict = 0 if $dm->mirrorlist && $file_name; my $ipvstrict = $dm->ipvstrict; - my $metalink = $dm->metalink || $dm->meta4 || $dm->zsync; my $rs = $dm->c->schema->resultset('Server'); my $m; $m = $rs->mirrors_query( $country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id, $scheme, $ipv, $lat, $lng, $avoid_countries, $limit, 0, - !$mirrorlist, $ipvstrict, $vpn, $dm->path + $schemastrict, $ipvstrict, $vpn, $dm->path ) if $country; if ($m && scalar(@$m)) { @@ -807,7 +807,7 @@ sub _collect_mirrors { $m = $rs->mirrors_query( $country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id, $scheme, $ipv, $lat, $lng, \@avoid_countries, $limit, 0, - !$mirrorlist, $ipvstrict, $vpn, $dm->path + $schemastrict, $ipvstrict, $vpn, $dm->path ); my $found_more; @@ -826,7 +826,7 @@ sub _collect_mirrors { $m = $rs->mirrors_query( $country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id, $scheme, $ipv, $lat, $lng, $avoid_countries, $limit, 1, - !$mirrorlist, $ipvstrict, $vpn, $dm->path + $schemastrict, $ipvstrict, $vpn, $dm->path ); my $found_more; $found_more = scalar(@$m) if $m; @@ -842,9 +842,13 @@ sub _collect_mirrors { my $path = $dm->path . $dm->trailing_slash; for $m (@$mirrors_country, @$mirrors_region, @$mirrors_rest) { if ($file_name) { - $m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($m->{urldir} . $m->{folder_path} . '/' . $file_name, '^A-Za-z0-9\-._~/'); + $m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($m->{urldir} . '/' . $file_name, '^A-Za-z0-9\-._~/'); } else { - $m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($m->{urldir} . $path, '^A-Za-z0-9\-._~/'); + my $urldir = $m->{urldir}; + if ( '/repodata' eq substr($urldir, -length('/repodata')) && '/repodata' ne substr($dm->path, -length('/repodata'))) { + $urldir = substr($urldir, 0, -length('/repodata')); + } + $m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($urldir . $dm->trailing_slash, '^A-Za-z0-9\-._~/'); } } return $found_count; diff --git a/t/environ/10-https-probe.sh b/t/environ/10-https-probe.sh index 1204a2ef..625c6673 100755 --- a/t/environ/10-https-probe.sh +++ b/t/environ/10-https-probe.sh @@ -44,8 +44,9 @@ ap7=$(environ ap7) $ap7/configure_ssl for x in $mc $ap7 $ap8; do - mkdir -p $x/dt/{folder1,folder2,folder3} - echo $x/dt/{folder1,folder2,folder3}/{file1.1,file2.1}.dat | xargs -n 1 touch + mkdir -p $x/dt/{folder1,folder2,folder3}/repodata/ + echo $x/dt/{folder1,folder2,folder3}/repodata/{file1.1,file2.1}.dat | xargs -n 1 touch + echo $x/dt/{folder1,folder2,folder3}/file.dat | xargs -n 1 touch done $ap9/curl_https /download/ | grep folder1 @@ -68,7 +69,8 @@ $mc/sql_test 1 == "select 1 from server_capability_check where server_id=2 and c $mc/db/sql "insert into server_capability_force(server_id,capability,dt) select 1,'http',now()" $mc/db/sql "insert into server_capability_force(server_id,capability,dt) select 2,'https',now()" -$ap9/curl_https --cacert ca/ca.pem -I /download/folder1/file1.1.dat +$ap9/curl_https --cacert ca/ca.pem -I /download/folder1/repodata/file1.1.dat +$ap9/curl_https --cacert ca/ca.pem -I /download/folder1/file.dat $mc/backstage/job folder_sync_schedule_from_misses $mc/backstage/job folder_sync_schedule @@ -77,10 +79,19 @@ $mc/backstage/job mirror_scan_schedule $mc/backstage/shoot # make sure https redirects to https -$ap9/curl_https -I /download/folder1/file1.1.dat | grep https:// | grep $($ap7/print_address) -$ap9/curl -I /download/folder1/file1.1.dat | grep http:// | grep $($ap8/print_address) +$ap9/curl_https -I /download/folder1/repodata/file1.1.dat | grep https:// | grep $($ap7/print_address) +$ap9/curl -I /download/folder1/repodata/file1.1.dat | grep http:// | grep $($ap8/print_address) -$ap9/curl_https /download/folder1/file1.1.dat.metalink | grep 'origin="https://metalink_publisher.net/folder1/file1.1.dat.metalink"' -$ap9/curl /download/folder1/file1.1.dat.metalink | grep 'origin="http://metalink_publisher.net/folder1/file1.1.dat.metalink"' -$ap9/curl_https /download/folder1/file1.1.dat.mirrorlist | grep Origin | grep https://metalink_publisher.net/folder1/file1.1.dat -$ap9/curl /download/folder1/file1.1.dat.mirrorlist | grep Origin | grep http://metalink_publisher.net/folder1/file1.1.dat +$ap9/curl_https /download/folder1/repodata/file1.1.dat.metalink | grep 'origin="https://metalink_publisher.net/folder1/repodata/file1.1.dat.metalink"' +$ap9/curl /download/folder1/repodata/file1.1.dat.metalink | grep 'origin="http://metalink_publisher.net/folder1/repodata/file1.1.dat.metalink"' +$ap9/curl_https /download/folder1/repodata/file1.1.dat.mirrorlist | grep Origin | grep https://metalink_publisher.net/folder1/repodata/file1.1.dat +$ap9/curl /download/folder1/repodata/file1.1.dat.mirrorlist | grep Origin | grep http://metalink_publisher.net/folder1/repodata/file1.1.dat + + +echo make sure https protocol is respected in folder mirrorlist +$ap9/curl /download/folder1/repodata/?mirrorlist | grep -F '"http:\/\/127.0.0.1:1314\/folder1\/repodata\/"' | grep -v "127.0.0.1:1304" +$ap9/curl_https /download/folder1/repodata/?mirrorlist | grep -F '"https:\/\/127.0.0.1:1304\/folder1\/repodata\/"' | grep -v "127.0.0.1:1314" +$ap9/curl /download/folder1/?mirrorlist | grep -F '"http:\/\/127.0.0.1:1314\/folder1\/"' | grep -v "127.0.0.1:1304" +$ap9/curl_https /download/folder1/?mirrorlist | grep -F '"https:\/\/127.0.0.1:1304\/folder1\/"' | grep -v "127.0.0.1:1314" + +echo success