xref: /dokuwiki/lib/plugins/authpdo/_test/sqlite.test.php (revision 70a89417b85aed070861be4f936ffa8844eb63dd)
1<?php
2
3/**
4 * General tests for the authpdo plugin
5 *
6 * @group plugin_authpdo
7 * @group plugins
8 */
9class sqlite_plugin_authpdo_test extends DokuWikiTest {
10
11    protected $dbfile;
12
13    public function setUp() {
14        parent::setUp();
15        $this->dbfile = tempnam('/tmp/', 'pluginpdo_test_');
16        copy(__DIR__ . '/test.sqlite3', $this->dbfile);
17
18        global $conf;
19
20        $conf['plugin']['authpdo']['debug'] = 1;
21        $conf['plugin']['authpdo']['dsn']  = 'sqlite:' . $this->dbfile;
22        $conf['plugin']['authpdo']['user'] = '';
23        $conf['plugin']['authpdo']['pass'] = '';
24
25
26        $conf['plugin']['authpdo']['select-user'] = 'SELECT id as uid, login as user, name, pass as clear, mail FROM user WHERE login = :user';
27        $conf['plugin']['authpdo']['select-user-groups'] = 'SELECT * FROM member AS m, "group" AS g  WHERE m.gid = g.id AND  m.uid = :uid';
28
29    }
30
31    public function tearDown() {
32        parent::tearDown();
33        unlink($this->dbfile);
34    }
35
36    public function test_userinfo() {
37        global $conf;
38        $auth = new auth_plugin_authpdo();
39
40        // clear text pasword (with default config above
41        $this->assertFalse($auth->checkPass('nobody', 'nope'));
42        $this->assertFalse($auth->checkPass('admin', 'nope'));
43        $this->assertTrue($auth->checkPass('admin', 'password'));
44
45        // now with a hashed password
46        $conf['plugin']['authpdo']['select-user'] = 'SELECT id as uid, login as user, name, pass as hash, mail FROM user WHERE login = :user';
47        $this->assertFalse($auth->checkPass('admin', 'password'));
48        $this->assertFalse($auth->checkPass('user', md5('password')));
49
50        // access user data
51        $info = $auth->getUserData('admin');
52        $this->assertEquals('admin', $info['user']);
53        $this->assertEquals('The Admin', $info['name']);
54        $this->assertEquals('admin@example.com', $info['mail']);
55        $this->assertEquals(array('admin','user'), $info['grps']);
56    }
57}
58