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