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