Skip to content

Commit 1d1d8da

Browse files
committed
Respect http(s) protocol in folder mirrorlist
1 parent b89cdea commit 1d1d8da

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

lib/MirrorCache/Schema/ResultSet/Server.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ select x.id as mirror_id,
126126
case when support_scheme > 0 then '$capability' else '$capabilityx' end as scheme,
127127
hostname,
128128
urldir,
129-
folder_path,
130129
mtime,
131130
dist,
132131
case $weight_country_case when region $avoid_region= '$region' then 1 else 0 end rating_country,
@@ -138,8 +137,7 @@ support_ipv,
138137
rating_ipv
139138
from (
140139
select s.id, $hostname as hostname,
141-
left(concat(s.urldir),$MIRRORCACHE_MAX_PATH) as urldir,
142-
f.path as folder_path,
140+
left(concat(s.urldir, f.path),$MIRRORCACHE_MAX_PATH) as urldir,
143141
s.mtime,
144142
s.lat as lat,
145143
s.lng as lng,

lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sub register {
4646
}
4747
my $limit = 8;
4848
eval {
49-
$limit = $app->mcconfig->limit_mirrorlist_folder // $limit;
49+
$limit = $app->mcconfig->limit_mirrorlist_folder || $limit;
5050
};
5151
my (@mirrors_country, @mirrors_region, @mirrors_rest);
5252
my $project_id = $c->mcproject->get_id($path);
@@ -782,16 +782,16 @@ sub _collect_mirrors {
782782
my $vpn = $dm->vpn;
783783
my ($lat, $lng) = $dm->coord;
784784
my $avoid_countries = $dm->avoid_countries;
785-
my $mirrorlist = $dm->mirrorlist;
785+
my $schemastrict = 1;
786+
$schemastrict = 0 if $dm->mirrorlist && $file_name;
786787
my $ipvstrict = $dm->ipvstrict;
787-
my $metalink = $dm->metalink || $dm->meta4 || $dm->zsync;
788788
my $rs = $dm->c->schema->resultset('Server');
789789

790790
my $m;
791791
$m = $rs->mirrors_query(
792792
$country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id,
793793
$scheme, $ipv, $lat, $lng, $avoid_countries, $limit, 0,
794-
!$mirrorlist, $ipvstrict, $vpn, $dm->path
794+
$schemastrict, $ipvstrict, $vpn, $dm->path
795795
) if $country;
796796

797797
if ($m && scalar(@$m)) {
@@ -807,7 +807,7 @@ sub _collect_mirrors {
807807
$m = $rs->mirrors_query(
808808
$country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id,
809809
$scheme, $ipv, $lat, $lng, \@avoid_countries, $limit, 0,
810-
!$mirrorlist, $ipvstrict, $vpn, $dm->path
810+
$schemastrict, $ipvstrict, $vpn, $dm->path
811811
);
812812
my $found_more;
813813

@@ -826,7 +826,7 @@ sub _collect_mirrors {
826826
$m = $rs->mirrors_query(
827827
$country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id,
828828
$scheme, $ipv, $lat, $lng, $avoid_countries, $limit, 1,
829-
!$mirrorlist, $ipvstrict, $vpn, $dm->path
829+
$schemastrict, $ipvstrict, $vpn, $dm->path
830830
);
831831
my $found_more;
832832
$found_more = scalar(@$m) if $m;
@@ -842,9 +842,13 @@ sub _collect_mirrors {
842842
my $path = $dm->path . $dm->trailing_slash;
843843
for $m (@$mirrors_country, @$mirrors_region, @$mirrors_rest) {
844844
if ($file_name) {
845-
$m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($m->{urldir} . $m->{folder_path} . '/' . $file_name, '^A-Za-z0-9\-._~/');
845+
$m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($m->{urldir} . '/' . $file_name, '^A-Za-z0-9\-._~/');
846846
} else {
847-
$m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($m->{urldir} . $path, '^A-Za-z0-9\-._~/');
847+
my $urldir = $m->{urldir};
848+
if ( '/repodata' eq substr($urldir, -length('/repodata')) && '/repodata' ne substr($dm->path, -length('/repodata'))) {
849+
$urldir = substr($urldir, 0, -length('/repodata'));
850+
}
851+
$m->{url} = $m->{scheme} . '://' . $m->{hostname} . Mojo::Util::url_escape($urldir . $dm->trailing_slash, '^A-Za-z0-9\-._~/');
848852
}
849853
}
850854
return $found_count;

t/environ/10-https-probe.sh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ ap7=$(environ ap7)
4444
$ap7/configure_ssl
4545

4646
for x in $mc $ap7 $ap8; do
47-
mkdir -p $x/dt/{folder1,folder2,folder3}
48-
echo $x/dt/{folder1,folder2,folder3}/{file1.1,file2.1}.dat | xargs -n 1 touch
47+
mkdir -p $x/dt/{folder1,folder2,folder3}/repodata/
48+
echo $x/dt/{folder1,folder2,folder3}/repodata/{file1.1,file2.1}.dat | xargs -n 1 touch
49+
echo $x/dt/{folder1,folder2,folder3}/file.dat | xargs -n 1 touch
4950
done
5051

5152
$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
6869
$mc/db/sql "insert into server_capability_force(server_id,capability,dt) select 1,'http',now()"
6970
$mc/db/sql "insert into server_capability_force(server_id,capability,dt) select 2,'https',now()"
7071

71-
$ap9/curl_https --cacert ca/ca.pem -I /download/folder1/file1.1.dat
72+
$ap9/curl_https --cacert ca/ca.pem -I /download/folder1/repodata/file1.1.dat
73+
$ap9/curl_https --cacert ca/ca.pem -I /download/folder1/file.dat
7274

7375
$mc/backstage/job folder_sync_schedule_from_misses
7476
$mc/backstage/job folder_sync_schedule
@@ -77,10 +79,19 @@ $mc/backstage/job mirror_scan_schedule
7779
$mc/backstage/shoot
7880

7981
# make sure https redirects to https
80-
$ap9/curl_https -I /download/folder1/file1.1.dat | grep https:// | grep $($ap7/print_address)
81-
$ap9/curl -I /download/folder1/file1.1.dat | grep http:// | grep $($ap8/print_address)
82+
$ap9/curl_https -I /download/folder1/repodata/file1.1.dat | grep https:// | grep $($ap7/print_address)
83+
$ap9/curl -I /download/folder1/repodata/file1.1.dat | grep http:// | grep $($ap8/print_address)
8284

83-
$ap9/curl_https /download/folder1/file1.1.dat.metalink | grep 'origin="https://metalink_publisher.net/folder1/file1.1.dat.metalink"'
84-
$ap9/curl /download/folder1/file1.1.dat.metalink | grep 'origin="http://metalink_publisher.net/folder1/file1.1.dat.metalink"'
85-
$ap9/curl_https /download/folder1/file1.1.dat.mirrorlist | grep Origin | grep https://metalink_publisher.net/folder1/file1.1.dat
86-
$ap9/curl /download/folder1/file1.1.dat.mirrorlist | grep Origin | grep http://metalink_publisher.net/folder1/file1.1.dat
85+
$ap9/curl_https /download/folder1/repodata/file1.1.dat.metalink | grep 'origin="https://metalink_publisher.net/folder1/repodata/file1.1.dat.metalink"'
86+
$ap9/curl /download/folder1/repodata/file1.1.dat.metalink | grep 'origin="http://metalink_publisher.net/folder1/repodata/file1.1.dat.metalink"'
87+
$ap9/curl_https /download/folder1/repodata/file1.1.dat.mirrorlist | grep Origin | grep https://metalink_publisher.net/folder1/repodata/file1.1.dat
88+
$ap9/curl /download/folder1/repodata/file1.1.dat.mirrorlist | grep Origin | grep http://metalink_publisher.net/folder1/repodata/file1.1.dat
89+
90+
91+
echo make sure https protocol is respected in folder mirrorlist
92+
$ap9/curl /download/folder1/repodata/?mirrorlist | grep -F '"http:\/\/127.0.0.1:1314\/folder1\/repodata\/"' | grep -v "127.0.0.1:1304"
93+
$ap9/curl_https /download/folder1/repodata/?mirrorlist | grep -F '"https:\/\/127.0.0.1:1304\/folder1\/repodata\/"' | grep -v "127.0.0.1:1314"
94+
$ap9/curl /download/folder1/?mirrorlist | grep -F '"http:\/\/127.0.0.1:1314\/folder1\/"' | grep -v "127.0.0.1:1304"
95+
$ap9/curl_https /download/folder1/?mirrorlist | grep -F '"https:\/\/127.0.0.1:1304\/folder1\/"' | grep -v "127.0.0.1:1314"
96+
97+
echo success

0 commit comments

Comments
 (0)