modified plugin AuthLDAP
version 2.4.2
This commit is contained in:
168
wp-content/plugins/authLdap-2.4.2/tests/LDAPBaseTest.php
Normal file
168
wp-content/plugins/authLdap-2.4.2/tests/LDAPBaseTest.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (c) 2016-2016} Andreas Heigl<andreas@heigl.org>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author Andreas Heigl<andreas@heigl.org>
|
||||
* @copyright 2016-2016 Andreas Heigl
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT-License
|
||||
* @version 0.0
|
||||
* @since 07.06.2016
|
||||
* @link http://github.com/heiglandreas/authLDAP
|
||||
*/
|
||||
namespace Org_Heigl\AuthLdapTest;
|
||||
|
||||
use Org_Heigl\AuthLdap\LDAP;
|
||||
use Org_Heigl\AuthLdap\LdapList;
|
||||
use Org_Heigl\AuthLdap\LdapUri;
|
||||
use phpmock\spy\Spy;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LDAPBaseTest extends TestCase
|
||||
{
|
||||
/** @var Spy */
|
||||
private $ldap_connect_spy;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->ldap_connect_spy = new Spy('Org_Heigl\AuthLdap', 'ldap_connect');
|
||||
$this->ldap_connect_spy->enable();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->ldap_connect_spy->disable();
|
||||
}
|
||||
/** @dataProvider bindingWithPasswordProvider */
|
||||
public function testThatBindingWithPasswordWorks($user, $password, $filter, $uri)
|
||||
{
|
||||
$ldap = new LDAP(LdapUri::fromString($uri));
|
||||
$this->assertTrue($ldap->authenticate($user, $password, $filter));
|
||||
}
|
||||
|
||||
public function bindingWithPasswordProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'user3',
|
||||
'user!"',
|
||||
'uid=%s',
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
], [
|
||||
'admin',
|
||||
'insecure',
|
||||
'cn=%s',
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
], [
|
||||
'user1',
|
||||
'user1',
|
||||
'uid=%s',
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
], [
|
||||
'user 4',
|
||||
'user!"',
|
||||
'uid=%s',
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
], [
|
||||
'user 5',
|
||||
'user!"',
|
||||
'uid=%s',
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=test%20space,dc=example,dc=org'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uri
|
||||
* @dataProvider initialBindingToLdapServerWorksProvider
|
||||
*/
|
||||
public function testThatInitialBindingWorks($uri)
|
||||
{
|
||||
$ldap = new LDAP(LdapUri::fromString($uri));
|
||||
$this->assertInstanceof(LDAP::class, $ldap->bind());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uri
|
||||
* @dataProvider initialBindingToLdapServerWorksProvider
|
||||
*/
|
||||
public function testThatInitialBindingToMultipleLdapsWorks($uri)
|
||||
{
|
||||
$list = new LdapList();
|
||||
$list->addLDAP(new LDAP(LdapUri::fromString($uri)));
|
||||
$this->assertTrue($list->bind());
|
||||
}
|
||||
|
||||
public function initialBindingToLdapServerWorksProvider()
|
||||
{
|
||||
return [
|
||||
['ldap://uid=user%205,dc=test%20space,dc=example,dc=org:user!"' .
|
||||
'@127.0.0.1:3389/dc=test%20space,dc=example,dc=org'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider bindingWithPasswordProvider */
|
||||
public function testThatBindingWithAddedSlashesFailsWorks($user, $password, $filter)
|
||||
{
|
||||
$newpassword = addslashes($password);
|
||||
$ldap = new LDAP(LdapUri::fromString(
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
));
|
||||
if ($newpassword === $password) {
|
||||
$this->assertTrue($ldap->authenticate($user, $password, $filter));
|
||||
} else {
|
||||
$this->assertFalse($ldap->authenticate($user, $newpassword, $filter));
|
||||
}
|
||||
}
|
||||
|
||||
/** @dataProvider serchingForGroupsProvider */
|
||||
public function testThatSearchingForGoupsWorks($filter, $user, $groups)
|
||||
{
|
||||
// (&(objectCategory=group)(member=<USER_DN>))
|
||||
$ldap = new LDAP(LdapUri::fromString(
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
));
|
||||
$ldap->bind();
|
||||
$this->assertContains($groups, $ldap->search(sprintf($filter, $user), ['cn'])[0]);
|
||||
}
|
||||
|
||||
public function serchingForGroupsProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'(&(objectclass=groupOfUniqueNames)(uniqueMember=%s))',
|
||||
'uid=user 4,dc=example,dc=org',
|
||||
['count' => 1, 0 => 'group4'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testThatSettingLDAPSActuallyGivesTheCorrectPort()
|
||||
{
|
||||
|
||||
$ldap = new LDAP(LdapUri::fromString(
|
||||
'ldaps://cn=admin,dc=example,dc=org:insecure@127.0.0.1/dc=example,dc=org'
|
||||
));
|
||||
$ldap->connect();
|
||||
|
||||
$this->assertEquals(
|
||||
'ldaps://127.0.0.1:636',
|
||||
$this->ldap_connect_spy->getInvocations()[0]->getArguments()[0]
|
||||
);
|
||||
}
|
||||
}
|
71
wp-content/plugins/authLdap-2.4.2/tests/LDAPListBaseTest.php
Normal file
71
wp-content/plugins/authLdap-2.4.2/tests/LDAPListBaseTest.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (c) 2016-2016} Andreas Heigl<andreas@heigl.org>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author Andreas Heigl<andreas@heigl.org>
|
||||
* @copyright 2016-2016 Andreas Heigl
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT-License
|
||||
* @version 0.0
|
||||
* @since 07.06.2016
|
||||
* @link http://github.com/heiglandreas/authLDAP
|
||||
*/
|
||||
namespace Org_Heigl\AuthLdapTest;
|
||||
|
||||
use Org_Heigl\AuthLdap\LDAP;
|
||||
use Org_Heigl\AuthLdap\LdapUri;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LDAPListBaseTest extends TestCase
|
||||
{
|
||||
/** @dataProvider bindingWithPasswordProvider */
|
||||
public function testThatBindingWithPasswordWorks($user, $password, $filter)
|
||||
{
|
||||
require_once __DIR__ . '/../src/LdapList.php';
|
||||
$ldaplist = new \Org_Heigl\AuthLdap\LdapList();
|
||||
$ldaplist->addLdap(new LDAP(LdapUri::fromString(
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
)));
|
||||
$this->assertTrue($ldaplist->authenticate($user, $password, $filter));
|
||||
}
|
||||
|
||||
public function bindingWithPasswordProvider()
|
||||
{
|
||||
return [
|
||||
['user3', 'user!"', 'uid=%s'],
|
||||
['admin', 'insecure', 'cn=%s'],
|
||||
['user1', 'user1', 'uid=%s'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider bindingWithPasswordProvider */
|
||||
public function testThatBindingWithAddedSlashesFailsWorks($user, $password, $filter)
|
||||
{
|
||||
$newpassword = addslashes($password);
|
||||
require_once __DIR__ . '/../src/LdapList.php';
|
||||
$ldaplist = new \Org_Heigl\AuthLdap\LdapList();
|
||||
$ldaplist->addLdap(new LDAP(LdapUri::fromString(
|
||||
'ldap://cn=admin,dc=example,dc=org:insecure@127.0.0.1:3389/dc=example,dc=org'
|
||||
)));
|
||||
if ($newpassword === $password) {
|
||||
$this->assertTrue($ldaplist->authenticate($user, $password, $filter));
|
||||
} else {
|
||||
$this->assertFalse($ldaplist->authenticate($user, $newpassword, $filter));
|
||||
}
|
||||
}
|
||||
}
|
194
wp-content/plugins/authLdap-2.4.2/tests/LdapTest.php
Normal file
194
wp-content/plugins/authLdap-2.4.2/tests/LdapTest.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: LdapTest.php 292156 2010-09-21 19:32:01Z heiglandreas $
|
||||
*
|
||||
* authLdap - Authenticate Wordpress against an LDAP-Backend.
|
||||
* Copyright (c) 2008 Andreas Heigl<andreas@heigl.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* This file tests the basic LDAP-Tasks
|
||||
*
|
||||
* @category authLdap
|
||||
* @package authLdap
|
||||
* @subpackage UnitTests
|
||||
* @author Andreas Heigl<andreas@heigl.org>
|
||||
* @copyright 2010 Andreas Heigl<andreas@heigl.org>
|
||||
* @license GPL
|
||||
* @since 21.09.2010
|
||||
*/
|
||||
|
||||
namespace Org_Heigl\AuthLdapTest;
|
||||
|
||||
use Exception;
|
||||
use Generator;
|
||||
use Org_Heigl\AuthLdap\LdapUri;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Org_Heigl\AuthLdap\LDAP;
|
||||
|
||||
class LdapTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @dataProvider dpInstantiateLdapClass
|
||||
* @param array $expected
|
||||
* @param array $given
|
||||
*/
|
||||
public function testInstantiateLdapClass($ldapUri, $debug, $startTls)
|
||||
{
|
||||
$ldap = new LDAP(LdapUri::fromString($ldapUri), $debug, $startTls);
|
||||
self::assertInstanceOf(LDAP::class, $ldap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dpExceptionsWhenInstantiatingLdapClass
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testExceptionsWhenInstantiatingLdapClass(string $expected)
|
||||
{
|
||||
self::expectException(Exception::class);
|
||||
new LDAP(LdapUri::fromString($expected));
|
||||
}
|
||||
|
||||
public function dpInstantiateLdapClass(): Generator
|
||||
{
|
||||
yield [
|
||||
'ldap://uid=jondoe,cn=users,cn=example,c=org:secret@ldap.example.org/cn=example,c=org',
|
||||
true,
|
||||
false,
|
||||
[
|
||||
'username' => 'uid=jondoe,cn=users,cn=example,c=org',
|
||||
'password' => 'secret',
|
||||
'server' => 'ldap.example.org',
|
||||
'baseDn' => 'cn=example,c=org',
|
||||
'debug' => true
|
||||
]
|
||||
];
|
||||
yield [
|
||||
'ldap://uid=jondoe,cn=users,cn=example,c=org@ldap.example.org/cn=example,c=org',
|
||||
true,
|
||||
false,
|
||||
[
|
||||
'username' => 'uid=jondoe,cn=users,cn=example,c=org',
|
||||
'password' => '',
|
||||
'server' => 'ldap.example.org',
|
||||
'baseDn' => 'cn=example,c=org',
|
||||
'debug' => true
|
||||
]
|
||||
];
|
||||
yield [
|
||||
'ldap://ldap.example.org/cn=example,c=org',
|
||||
true,
|
||||
false,
|
||||
[
|
||||
'username' => 'anonymous',
|
||||
'password' => '',
|
||||
'server' => 'ldap.example.org',
|
||||
'baseDn' => 'cn=example,c=org',
|
||||
'debug' => true
|
||||
]
|
||||
];
|
||||
// yield [
|
||||
// 'ldap://ldap.example.org',
|
||||
// true,
|
||||
// false,
|
||||
// [
|
||||
// 'username' => 'anonymous',
|
||||
// 'password' => '',
|
||||
// 'server' => 'ldap.example.org',
|
||||
// 'baseDn' => '',
|
||||
// 'debug' => true
|
||||
// ]
|
||||
// ];
|
||||
yield [
|
||||
'ldap://uid=jondoe,cn=users,cn=example,c=org:secret@ldap.example.org/cn=example,c=org',
|
||||
false,
|
||||
false,
|
||||
[
|
||||
'username' => 'uid=jondoe,cn=users,cn=example,c=org',
|
||||
'password' => 'secret',
|
||||
'server' => 'ldap.example.org',
|
||||
'baseDn' => 'cn=example,c=org',
|
||||
'debug' => false
|
||||
],
|
||||
];
|
||||
yield [
|
||||
'ldap://ldap.example.org/cn=test%20example,c=org',
|
||||
false,
|
||||
false,
|
||||
[
|
||||
'username' => 'anonymous',
|
||||
'password' => '',
|
||||
'server' => 'ldap.example.org',
|
||||
'baseDn' => 'cn=test example,c=org',
|
||||
'debug' => false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function dpExceptionsWhenInstantiatingLdapClass(): Generator
|
||||
{
|
||||
yield ['ldap://ldap.example.org'];
|
||||
yield ['ldap://foo:bar@/cn=example,c=org'];
|
||||
yield ['http://ldap.example.org'];
|
||||
yield ['fooBar'];
|
||||
yield ['ldap://ldap.example.org/'];
|
||||
yield ['()123üäö'];
|
||||
}
|
||||
|
||||
public function testThatGroupMappingWorks()
|
||||
{
|
||||
$groups = [
|
||||
'count' => 1,
|
||||
0 => [
|
||||
'dn' => 'dn-1',
|
||||
'count' => 1,
|
||||
0 => 'group',
|
||||
'group' => [
|
||||
'count' => 2,
|
||||
0 => '7310T270:Překladatelství:čeština - angličtina@ff.cuni.cz',
|
||||
1 => '7310T033:Český jazyk a literatura@ff.cuni.cz',
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$grp = array();
|
||||
for ($i = 0; $i < $groups ['count']; $i++) {
|
||||
for ($k = 0; $k < $groups[$i][strtolower('group')]['count']; $k++) {
|
||||
$grp[] = $groups[$i][strtolower('group')][$k];
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals([
|
||||
'7310T270:Překladatelství:čeština - angličtina@ff.cuni.cz',
|
||||
'7310T033:Český jazyk a literatura@ff.cuni.cz',
|
||||
], $grp);
|
||||
|
||||
$role = '';
|
||||
foreach ([
|
||||
'testrole' => '7310T031:Český jazyk a literatura@ff.cuni.cz,7310T033:Český jazyk a literatura@ff.cuni.cz'
|
||||
] as $key => $val) {
|
||||
$currentGroup = explode(',', $val);
|
||||
// Remove whitespaces around the group-ID
|
||||
$currentGroup = array_map('trim', $currentGroup);
|
||||
if (0 < count(array_intersect($currentGroup, $grp))) {
|
||||
$role = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals('testrole', $role);
|
||||
}
|
||||
}
|
53
wp-content/plugins/authLdap-2.4.2/tests/LdapUriTest.php
Normal file
53
wp-content/plugins/authLdap-2.4.2/tests/LdapUriTest.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Org_Heigl\AuthLdapTest;
|
||||
|
||||
use Generator;
|
||||
use Org_Heigl\AuthLdap\Exception\InvalidLdapUri;
|
||||
use Org_Heigl\AuthLdap\LdapUri;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LdapUriTest extends TestCase
|
||||
{
|
||||
public function toStringProvider(): Generator
|
||||
{
|
||||
yield ['ldaps://foo:bar@foo.bar/baz', 'ldaps://foo:bar@foo.bar/baz'];
|
||||
yield ['env:LDAP_URI', 'ldaps://foo:bar@foo.bar/baz', [
|
||||
'LDAP_URI' => 'ldaps://foo:bar@foo.bar/baz'
|
||||
]];
|
||||
yield ['ldaps://foo:%env:LDAP_PASSWORD%@foo.bar/baz', 'ldaps://foo:bar@foo.bar/baz', [
|
||||
'LDAP_PASSWORD' => 'bar'
|
||||
]];
|
||||
yield ['ldaps://foo:%env:LDAP_PASSWORD%@foo.bar/baz', 'ldaps://foo:ba%20r@foo.bar/baz', [
|
||||
'LDAP_PASSWORD' => 'ba r'
|
||||
]];
|
||||
}
|
||||
|
||||
public function fromStringProvider(): Generator
|
||||
{
|
||||
yield ['ldaps://foo:bar@foo.bar/baz', false];
|
||||
yield ['env:LDAP_URI', false];
|
||||
yield ['foo:MyLdapUri', true];
|
||||
}
|
||||
|
||||
/** @dataProvider toStringProvider */
|
||||
public function testToString(string $uri, string $result, array $env = []): void
|
||||
{
|
||||
foreach ($env as $key => $value) {
|
||||
putenv("$key=$value");
|
||||
}
|
||||
$ldapUri = LdapUri::fromString($uri);
|
||||
Assert::assertSame($result, $ldapUri->toString());
|
||||
}
|
||||
|
||||
/** @dataProvider fromStringProvider */
|
||||
public function testFromString(string $uri, bool $failure = false): void
|
||||
{
|
||||
if ($failure) {
|
||||
self::expectException(InvalidLdapUri::class);
|
||||
}
|
||||
$ldapUri = LdapUri::fromString($uri);
|
||||
self::assertInstanceOf(LdapUri::class, $ldapUri);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user