xref: /plugin/pureldap/_test/AuthTest.php (revision fb75804e73edf4af608854927a231691f3206614)
1<?php
2
3namespace dokuwiki\plugin\pureldap\test;
4
5/**
6 * @group plugin_pureldap
7 * @group plugins
8 */
9class AuthTest extends \DokuWikiTest {
10
11    public function setUp(): void
12    {
13        parent::setUp();
14
15        global $conf;
16        $conf['auth'] = 'pureldap';
17        $conf['plugin']['pureldap']['base_dn'] = 'DC=example,DC=local';
18        $conf['plugin']['pureldap']['suffix'] = 'example.local';
19        $conf['plugin']['pureldap']['servers'] = ['localhost'];
20        $conf['plugin']['pureldap']['port'] = 7636;
21        $conf['plugin']['pureldap']['admin_username'] = 'vagrant';
22        $conf['plugin']['pureldap']['admin_password'] = 'vagrant';
23        $conf['plugin']['pureldap']['encryption'] = 'ssl';
24        $conf['plugin']['pureldap']['validate'] = 'self';
25    }
26
27    public function testADlogin() {
28        $auth = new \auth_plugin_pureldap();
29        $this->assertTrue($auth->checkPass('a.legrand', 'Foo_b_ar123!'));
30        $this->assertFalse($auth->checkPass('a.legrand', 'wrong password'));
31    }
32
33    public function testADLongUserLogin()
34    {
35        $auth = new \auth_plugin_pureldap();
36
37        // sam account name
38        $this->assertTrue($auth->checkPass('longlong', 'Foo_b_ar123!'));
39        $this->assertFalse($auth->checkPass('longlong', 'wrong password'));
40
41        $this->assertTrue($auth->checkPass('averylongusernamethatisverylong', 'Foo_b_ar123!'));
42        $this->assertFalse($auth->checkPass('averylongusernamethatisverylong', 'wrong password'));
43    }
44
45    public function testADloginSSO() {
46        global $conf;
47        $conf['plugin']['pureldap']['sso'] = 1;
48
49        $_SERVER['REMOTE_USER'] = 'a.legrand';
50
51        $auth = new \auth_plugin_pureldap();
52        $this->assertTrue($auth->checkPass('a.legrand', 'sso-only'));
53    }
54}
55