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