Merge commit 'v7.10.23' into WebGUI8. Tests need fixing.
This commit is contained in:
commit
a2a821822d
72 changed files with 578 additions and 132 deletions
|
|
@ -20,27 +20,49 @@ use WebGUI::Group;
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $session1 = WebGUI::Test->session;
|
||||
my $session2 = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
### Updates by DRT test that group membership is restricted by user session
|
||||
### ...specifically for Visitors to have separate scratch group memberships
|
||||
|
||||
plan tests => 5; # Increment this number for each test you create
|
||||
plan tests => 14; # Increment this number for each test you create
|
||||
|
||||
my $group = WebGUI::Group->new($session, 'new');
|
||||
my $group = WebGUI::Group->new($session1, 'new');
|
||||
WebGUI::Test->addToCleanup($group);
|
||||
$group->scratchFilter("itchy=test_value");
|
||||
is( $group->scratchFilter(), "itchy=test_value",'Group->scratchFilter is properly set and retrieved');
|
||||
$group->groupCacheTimeout(0);
|
||||
is( $group->groupCacheTimeout(), 0, 'set groupCacheTimeout to 0');
|
||||
|
||||
$session->user({userId => 1});
|
||||
ok( !$session->user->isInGroup($group->getId), 'Visitor is NOT in the group BEFORE scratch value is set');
|
||||
$session->scratch->set('itchy', 'test_value');
|
||||
is ($group->hasScratchUser($session->user->getId), 1, 'Group->hasScratchUser correctly returns 1 immediately after scratch is set');
|
||||
$session1->user({userId => 1});
|
||||
$session2->user({userId => 1});
|
||||
|
||||
##Simulate another page view by clearing stow, which is volatile
|
||||
$session->stow->deleteAll;
|
||||
$session->scratch->delete('itchy');
|
||||
is ($group->hasScratchUser($session->user->getId), 0, 'after clearing scratch, user is not in the group any longer');
|
||||
### Test group membership before scratch is set
|
||||
### NOTE: test hasScratchUser first, because isInGroup sets stow & cache
|
||||
is ($group->hasScratchUser($session1->user->getId,$session1->user->session->getId), 0, 'Group->hasScratchUser correctly returns 0 for Visitor 1 before scratch is set');
|
||||
is ($group->hasScratchUser($session2->user->getId,$session2->user->session->getId), 0, 'Group->hasScratchUser correctly returns 0 for Visitor 2 before scratch is set');
|
||||
ok( !$session1->user->isInGroup($group->getId), 'user1->isInGroup correctly returns 0 before scratch is set');
|
||||
ok( !$session2->user->isInGroup($group->getId), 'user2->isInGroup correctly returns 0 before scratch is set');
|
||||
|
||||
### Test group membership after scratch is set
|
||||
### Clear stow, which is volatile, to simulate new page view
|
||||
$session1->stow->deleteAll;
|
||||
$session2->stow->deleteAll;
|
||||
$session1->scratch->set('itchy', 'test_value');
|
||||
is ($group->hasScratchUser($session1->user->getId,$session1->user->session->getId), 1, 'Group->hasScratchUser correctly returns 1 for Visitor 1 after scratch for Visitor 1 is set');
|
||||
is ($group->hasScratchUser($session2->user->getId,$session2->user->session->getId), 0, 'Group->hasScratchUser correctly returns 0 for Visitor 2 after scratch for Visitor 1 is set');
|
||||
ok( $session1->user->isInGroup($group->getId), 'user1->isInGroup correctly returns 1 after scratch for Visitor 1 is set');
|
||||
ok( !$session2->user->isInGroup($group->getId), 'user2->isInGroup correctly returns 0 after scratch for Visitor 1 is set');
|
||||
|
||||
### Test group membership after scratch is deleted
|
||||
### Clear stow, which is volatile, to simulate new page view
|
||||
$session1->stow->deleteAll;
|
||||
$session2->stow->deleteAll;
|
||||
$session1->scratch->delete('itchy');
|
||||
is ($group->hasScratchUser($session1->user->getId,$session1->user->session->getId), 0, 'Group->hasScratchUser for Visitor 1 correctly returns 0 after clearing scratch for Visitor 1');
|
||||
is ($group->hasScratchUser($session2->user->getId,$session2->user->session->getId), 0, 'Group->hasScratchUser for Visitor 2 correctly returns 0 after clearing scratch for Visitor 1');
|
||||
ok( !$session1->user->isInGroup($group->getId), 'user1->isInGroup correctly returns 0 after scratch for Visitor 1 is deleted');
|
||||
ok( !$session2->user->isInGroup($group->getId), 'user2->isInGroup correctly returns 0 after scratch for Visitor 1 is deleted');
|
||||
|
|
|
|||
101
t/Group/ldap_groups.t
Normal file
101
t/Group/ldap_groups.t
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Utility;
|
||||
|
||||
use WebGUI::User;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Cache;
|
||||
|
||||
use Test::More skip_all => 'Disabled until the test LDAP server is rejuvenated';
|
||||
use Test::Deep;
|
||||
|
||||
my @ldapTests = (
|
||||
{
|
||||
dn => 'uid=Byron Hadley,o=shawshank',
|
||||
comment => 'bad dn for group',
|
||||
expect => 0,
|
||||
},
|
||||
{
|
||||
dn => 'uid=Andy Dufresne,o=shawshank',
|
||||
comment => 'good dn for group',
|
||||
expect => 1,
|
||||
},
|
||||
{
|
||||
dn => 'uid=Bogs Diamond,o=shawshank',
|
||||
comment => 'another good dn for group',
|
||||
expect => 1,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
################################################################
|
||||
#
|
||||
# LDAP specific group properties
|
||||
# These tests have to be done on an isolated group that will NEVER
|
||||
# have getGroups called on it
|
||||
#
|
||||
################################################################
|
||||
|
||||
my $ldapProps = WebGUI::Test->getSmokeLDAPProps();
|
||||
$session->db->setRow('ldapLink', 'ldapLinkId', $ldapProps, $ldapProps->{ldapLinkId});
|
||||
my $ldap = WebGUI::LDAPLink->new($session, $ldapProps->{ldapLinkId});
|
||||
is($ldap->getValue("ldapLinkId"),$ldapProps->{ldapLinkId},'ldap link created properly');
|
||||
WebGUI::Test->addToCleanup($ldap);
|
||||
|
||||
my @shawshank;
|
||||
|
||||
foreach my $idx (0..$#ldapTests) {
|
||||
$shawshank[$idx] = WebGUI::User->new($session, "new");
|
||||
$shawshank[$idx]->username("shawshank$idx");
|
||||
$shawshank[$idx]->authMethod("LDAP");
|
||||
my $auth = $shawshank[$idx]->authInstance;
|
||||
$auth->saveParams($shawshank[$idx]->getId,$shawshank[$idx]->authMethod,{
|
||||
connectDN => $ldapTests[$idx]->{dn},
|
||||
ldapConnection => $ldap->getValue("ldapLinkId"),
|
||||
ldapUrl => $ldap->getValue("ldapUrl"),
|
||||
});
|
||||
}
|
||||
|
||||
WebGUI::Test->addToCleanup(@shawshank);
|
||||
|
||||
my $lGroup = WebGUI::Group->new($session, 'new');
|
||||
|
||||
$lGroup->ldapGroup('cn=Convicts,o=shawshank');
|
||||
is($lGroup->ldapGroup(), 'cn=Convicts,o=shawshank', 'ldapGroup set and fetched correctly');
|
||||
|
||||
$lGroup->ldapGroupProperty('member');
|
||||
is($lGroup->ldapGroupProperty(), 'member', 'ldapGroup set and fetched correctly');
|
||||
|
||||
$lGroup->ldapLinkId($ldapProps->{ldapLinkId});
|
||||
is($lGroup->ldapLinkId(),$ldapProps->{ldapLinkId}, 'ldapLinkId set and fetched correctly');
|
||||
|
||||
is_deeply(
|
||||
[ (map { $lGroup->hasLDAPUser($_->getId) } @shawshank) ],
|
||||
[0, 1, 1],
|
||||
'shawshank user 2, and 3 found in lGroup users from LDAP'
|
||||
);
|
||||
|
||||
$lGroup->ldapRecursiveProperty('LDAP recursive property');
|
||||
is($lGroup->ldapRecursiveProperty(), 'LDAP recursive property', 'ldapRecursiveProperty set and fetched correctly');
|
||||
|
||||
$lGroup->ldapRecursiveFilter('LDAP recursive filter');
|
||||
is($lGroup->ldapRecursiveFilter(), 'LDAP recursive filter', 'ldapRecursiveFilter set and fetched correctly');
|
||||
|
||||
$lGroup->delete;
|
||||
|
||||
done_testing;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue