Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/MirrorCache/Schema/ResultSet/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
29 changes: 20 additions & 9 deletions t/environ/10-https-probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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