Set precedence order for vhost wildcards (#2188)

This commit is contained in:
Xavier Guimard 2020-05-06 10:49:05 +02:00
parent ba86f7e2f5
commit 7d35953668
3 changed files with 21 additions and 1 deletions

View File

@ -277,6 +277,7 @@ sub locationRulesInit {
$orules ||= $conf->{locationRules};
$class->tsv->{vhostReg} = [];
my @lastReg;
foreach my $vhost ( keys %$orules ) {
my $rules = $orules->{$vhost};
@ -287,7 +288,7 @@ sub locationRulesInit {
push @{ $class->tsv->{vhostReg} }, [ qr/$expr/, $vhost ];
}
else {
push @{ $class->tsv->{vhostReg} }, [ qr/.+/, $vhost ];
push @lastReg, [ qr/.+/, $vhost ];
}
}
$class->tsv->{locationCount}->{$vhost} = 0;
@ -333,6 +334,14 @@ sub locationRulesInit {
$class->tsv->{defaultProtection}->{$vhost} = 0;
}
}
@{ $class->tsv->{vhostReg} } = sort {
my $av = $a->[1];
my $bv = $b->[1];
return -1 if $av =~ /^*/ and $bv !~ /^*/;
return 1 if $bv =~ /^*/ and $av !~ /^*/;
return length($a) <=> length($b);
} @{ $class->tsv->{vhostReg} };
push @{ $class->tsv->{vhostReg} }, @lastReg if @lastReg;
return 1;
}

View File

@ -187,6 +187,14 @@ ok($res = $client->_get( '/', undef, 'foo.example.fr', "lemonldap=$sessionId" ),
ok( $res->[0] == 302, ' Code is 302' ) or explain( $res, 302 );
count(2);
ok($res = $client->_get( '/orgdeny', undef, 'foo.example.org', "lemonldap=$sessionId" ), 'Reject "foo.example.org/orgdeny"');
ok( $res->[0] == 302, ' Code is 302' ) or explain( $res, 302 );
count(2);
ok($res = $client->_get( '/orgdeny', undef, 'afoo.example.org', "lemonldap=$sessionId" ), 'Accept "afoo.example.org/orgdeny"');
ok( $res->[0] == 200, ' Code is 200' ) or explain( $res, 200 );
count(2);
ok($res = $client->_get( '/', undef, 'test-foo.example.fr', "lemonldap=$sessionId" ), 'Accept "test*.example.fr"');
ok( $res->[0] == 200, ' Code is 200' ) or explain( $res, 200 );
count(2);

View File

@ -62,6 +62,9 @@
"^/orgdeny": "deny",
"default": "accept"
},
"a*.example.org": {
"default": "accept"
},
"test*.example.fr": {
"default": "accept"
}