Manage vhost aliases in portal menu (#755)

environments/ppa-mbqj77/deployments/1
Clément Oudot 11 years ago
parent 4662938bd2
commit 5bb0f01de4
  1. 58
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_LibAccess.pm
  2. 43
      lemonldap-ng-portal/t/50-Lemonldap-NG-Portal-Menu.t

@ -7,7 +7,7 @@ package Lemonldap::NG::Portal::_LibAccess;
use strict;
our $VERSION = '1.2.0';
our $VERSION = '1.4.2';
# Global variables
our ( $defaultCondition, $locationCondition, $locationRegexp, $cfgNum ) =
@ -79,24 +79,29 @@ sub _compileRules {
my $self = shift;
foreach my $vhost ( keys %{ $self->{locationRules} } ) {
my $i = 0;
$self->lmLog( "Compiling rules for $vhost", 'debug' );
foreach ( keys %{ $self->{locationRules}->{$vhost} } ) {
if ( $_ eq 'default' ) {
$defaultCondition->{$vhost} =
$self->_conditionSub(
$self->{locationRules}->{$vhost}->{$_} );
foreach
my $alias ( @{ $self->_getAliases( $vhost, $self->{vhostOptions} ) } )
{
$self->lmLog( "Compiling rules for $alias", 'debug' );
foreach ( keys %{ $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
$defaultCondition->{$vhost} ||= $self->_conditionSub('accept');
# Default policy
$defaultCondition->{$alias} ||= $self->_conditionSub('accept');
}
}
$cfgNum = $self->{cfgNum};
1;
@ -116,4 +121,23 @@ sub _conditionSub {
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;

@ -5,7 +5,7 @@
# 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') }
#########################
@ -35,6 +35,8 @@ my $p = Lemonldap::NG::Portal::Simple->new(
},
cfgNum => 42,
sessionInfo => { uid => "coudot", },
vhostOptions =>
{ 'test.example.com' => { vhostAliases => 'alias.example.com' }, },
}
);
@ -86,6 +88,14 @@ $p->{applicationList} = {
display => 'off',
},
},
testalias => {
type => 'application',
options => {
uri => 'http://alias.example.com/ok/login.php',
name => 'Test application',
display => 'auto',
},
},
},
empty => {
type => 'category',
@ -107,29 +117,32 @@ $appLoop = $p->appslist();
# Check empty category
# Check display off and on
# Check display auto ok and nok
my $emptyCat = 0;
my $displayOn = 0;
my $displayOff = 0;
my $displayOk = 0;
my $displayNok = 0;
my $emptyCat = 0;
my $displayOn = 0;
my $displayOff = 0;
my $displayOk = 0;
my $displayNok = 0;
my $displayAlias = 0;
foreach (@$appLoop) {
$emptyCat++ if $_->{catid} eq "empty";
if ( $_->{catid} eq "test" ) {
foreach ( @{ $_->{'applications'} } ) {
$displayOn++ if $_->{appid} eq "teston";
$displayOff++ if $_->{appid} eq "testoff";
$displayOk++ if $_->{appid} eq "testautook";
$displayNok++ if $_->{appid} eq "testautonok";
$displayOn++ if $_->{appid} eq "teston";
$displayOff++ if $_->{appid} eq "testoff";
$displayOk++ if $_->{appid} eq "testautook";
$displayNok++ if $_->{appid} eq "testautonok";
$displayAlias++ if $_->{appid} eq "testalias";
}
}
}
ok( $emptyCat == 0, 'Hide empty category' );
ok( $displayOn != 0, 'Display on' );
ok( $displayOff == 0, 'Display off' );
ok( $displayOk != 0, 'Display auto ok' );
ok( $displayNok == 0, 'Display auto nok' );
ok( $emptyCat == 0, 'Hide empty category' );
ok( $displayOn != 0, 'Display on' );
ok( $displayOff == 0, 'Display off' );
ok( $displayOk != 0, 'Display auto ok' );
ok( $displayNok == 0, 'Display auto nok' );
ok( $displayAlias != 0, 'Display alias ok' );
# Connect as another user with different rights
$p->{sessionInfo}->{uid} = "toto";

Loading…
Cancel
Save