Commit a6fc1a56 authored by Clément OUDOT's avatar Clément OUDOT
Browse files

Manage vhost aliases in portal menu (#LEMONLDAP-755)

git-svn-id: svn://svn.forge.objectweb.org/svnroot/lemonldap/branches/lemonldap-ng_version_1_4-bugfixes@3533 1dbb9719-a921-0410-b57f-c3a383c2c641
parent 5b7b8b84
...@@ -7,7 +7,7 @@ package Lemonldap::NG::Portal::_LibAccess; ...@@ -7,7 +7,7 @@ package Lemonldap::NG::Portal::_LibAccess;
use strict; use strict;
our $VERSION = '1.2.0'; our $VERSION = '1.4.2';
# Global variables # Global variables
our ( $defaultCondition, $locationCondition, $locationRegexp, $cfgNum ) = our ( $defaultCondition, $locationCondition, $locationRegexp, $cfgNum ) =
...@@ -79,24 +79,29 @@ sub _compileRules { ...@@ -79,24 +79,29 @@ sub _compileRules {
my $self = shift; my $self = shift;
foreach my $vhost ( keys %{ $self->{locationRules} } ) { foreach my $vhost ( keys %{ $self->{locationRules} } ) {
my $i = 0; my $i = 0;
$self->lmLog( "Compiling rules for $vhost", 'debug' ); foreach
foreach ( keys %{ $self->{locationRules}->{$vhost} } ) { my $alias ( @{ $self->_getAliases( $vhost, $self->{vhostOptions} ) } )
if ( $_ eq 'default' ) { {
$defaultCondition->{$vhost} = $self->lmLog( "Compiling rules for $alias", 'debug' );
$self->_conditionSub( foreach ( keys %{ $self->{locationRules}->{$vhost} } ) {
$self->{locationRules}->{$vhost}->{$_} ); if ( $_ eq 'default' ) {
$defaultCondition->{$alias} =
$self->_conditionSub(
$self->{locationRules}->{$vhost}->{$_} );
}
else {
$locationCondition->{$alias}->[$i] =
$self->_conditionSub(
$self->{locationRules}->{$vhost}->{$_} );
$locationRegexp->{$alias}->[$i] = qr/$_/;
$i++;
}
} }
else {
$locationCondition->{$vhost}->[$i] =
$self->_conditionSub(
$self->{locationRules}->{$vhost}->{$_} );
$locationRegexp->{$vhost}->[$i] = qr/$_/;
$i++;
}
}
# Default policy # Default policy
$defaultCondition->{$vhost} ||= $self->_conditionSub('accept'); $defaultCondition->{$alias} ||= $self->_conditionSub('accept');
}
} }
$cfgNum = $self->{cfgNum}; $cfgNum = $self->{cfgNum};
1; 1;
...@@ -116,4 +121,23 @@ sub _conditionSub { ...@@ -116,4 +121,23 @@ sub _conditionSub {
return $self->safe->reval($sub); return $self->safe->reval($sub);
} }
## @method arrayref _getAliases(scalar vhost, hashref options)
# Check aliases of a vhost
# @param vhost vhost name
# @param options vhostOptions configuration item
# @return arrayref of vhost and aliases
sub _getAliases {
my ( $self, $vhost, $options ) = splice @_;
my $aliases = [$vhost];
if ( $options->{$vhost}->{vhostAliases} ) {
foreach ( split /\s+/, $options->{$vhost}->{vhostAliases} ) {
push @$aliases, $_;
$self->lmLog( "$_ is an alias for $vhost", 'debug' );
}
}
return $aliases;
}
1; 1;
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# change 'tests => 1' to 'tests => last_test_to_print'; # change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 9; use Test::More tests => 10;
BEGIN { use_ok('Lemonldap::NG::Portal::Menu') } BEGIN { use_ok('Lemonldap::NG::Portal::Menu') }
######################### #########################
...@@ -35,6 +35,8 @@ my $p = Lemonldap::NG::Portal::Simple->new( ...@@ -35,6 +35,8 @@ my $p = Lemonldap::NG::Portal::Simple->new(
}, },
cfgNum => 42, cfgNum => 42,
sessionInfo => { uid => "coudot", }, sessionInfo => { uid => "coudot", },
vhostOptions =>
{ 'test.example.com' => { vhostAliases => 'alias.example.com' }, },
} }
); );
...@@ -86,6 +88,14 @@ $p->{applicationList} = { ...@@ -86,6 +88,14 @@ $p->{applicationList} = {
display => 'off', display => 'off',
}, },
}, },
testalias => {
type => 'application',
options => {
uri => 'http://alias.example.com/ok/login.php',
name => 'Test application',
display => 'auto',
},
},
}, },
empty => { empty => {
type => 'category', type => 'category',
...@@ -107,29 +117,32 @@ $appLoop = $p->appslist(); ...@@ -107,29 +117,32 @@ $appLoop = $p->appslist();
# Check empty category # Check empty category
# Check display off and on # Check display off and on
# Check display auto ok and nok # Check display auto ok and nok
my $emptyCat = 0; my $emptyCat = 0;
my $displayOn = 0; my $displayOn = 0;
my $displayOff = 0; my $displayOff = 0;
my $displayOk = 0; my $displayOk = 0;
my $displayNok = 0; my $displayNok = 0;
my $displayAlias = 0;
foreach (@$appLoop) { foreach (@$appLoop) {
$emptyCat++ if $_->{catid} eq "empty"; $emptyCat++ if $_->{catid} eq "empty";
if ( $_->{catid} eq "test" ) { if ( $_->{catid} eq "test" ) {
foreach ( @{ $_->{'applications'} } ) { foreach ( @{ $_->{'applications'} } ) {
$displayOn++ if $_->{appid} eq "teston"; $displayOn++ if $_->{appid} eq "teston";
$displayOff++ if $_->{appid} eq "testoff"; $displayOff++ if $_->{appid} eq "testoff";
$displayOk++ if $_->{appid} eq "testautook"; $displayOk++ if $_->{appid} eq "testautook";
$displayNok++ if $_->{appid} eq "testautonok"; $displayNok++ if $_->{appid} eq "testautonok";
$displayAlias++ if $_->{appid} eq "testalias";
} }
} }
} }
ok( $emptyCat == 0, 'Hide empty category' ); ok( $emptyCat == 0, 'Hide empty category' );
ok( $displayOn != 0, 'Display on' ); ok( $displayOn != 0, 'Display on' );
ok( $displayOff == 0, 'Display off' ); ok( $displayOff == 0, 'Display off' );
ok( $displayOk != 0, 'Display auto ok' ); ok( $displayOk != 0, 'Display auto ok' );
ok( $displayNok == 0, 'Display auto nok' ); ok( $displayNok == 0, 'Display auto nok' );
ok( $displayAlias != 0, 'Display alias ok' );
# Connect as another user with different rights # Connect as another user with different rights
$p->{sessionInfo}->{uid} = "toto"; $p->{sessionInfo}->{uid} = "toto";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment