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