aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/authpdo/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2016-01-29 21:25:50 +0100
committerAndreas Gohr <andi@splitbrain.org>2016-01-29 21:25:50 +0100
commitf64dbc90055403db700941e4691ea451bb971cef (patch)
tree0d2e3a89290c2c658cf3cf1cc69767d0011a6027 /lib/plugins/authpdo/_test
parentef89d2cdf605240572d5c20ce836571c2ba87742 (diff)
downloaddokuwiki-f64dbc90055403db700941e4691ea451bb971cef.tar.gz
dokuwiki-f64dbc90055403db700941e4691ea451bb971cef.zip
began work on PDO auth plugin
Diffstat (limited to 'lib/plugins/authpdo/_test')
-rw-r--r--lib/plugins/authpdo/_test/general.test.php33
-rw-r--r--lib/plugins/authpdo/_test/sqlite.test.php49
-rw-r--r--lib/plugins/authpdo/_test/test.sqlite3bin0 -> 14336 bytes
3 files changed, 82 insertions, 0 deletions
diff --git a/lib/plugins/authpdo/_test/general.test.php b/lib/plugins/authpdo/_test/general.test.php
new file mode 100644
index 000000000..6c48b6957
--- /dev/null
+++ b/lib/plugins/authpdo/_test/general.test.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * General tests for the authpdo plugin
+ *
+ * @group plugin_authpdo
+ * @group plugins
+ */
+class general_plugin_authpdo_test extends DokuWikiTest {
+
+ /**
+ * Simple test to make sure the plugin.info.txt is in correct format
+ */
+ public function test_plugininfo() {
+ $file = __DIR__.'/../plugin.info.txt';
+ $this->assertFileExists($file);
+
+ $info = confToHash($file);
+
+ $this->assertArrayHasKey('base', $info);
+ $this->assertArrayHasKey('author', $info);
+ $this->assertArrayHasKey('email', $info);
+ $this->assertArrayHasKey('date', $info);
+ $this->assertArrayHasKey('name', $info);
+ $this->assertArrayHasKey('desc', $info);
+ $this->assertArrayHasKey('url', $info);
+
+ $this->assertEquals('authpdo', $info['base']);
+ $this->assertRegExp('/^https?:\/\//', $info['url']);
+ $this->assertTrue(mail_isvalid($info['email']));
+ $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
+ $this->assertTrue(false !== strtotime($info['date']));
+ }
+}
diff --git a/lib/plugins/authpdo/_test/sqlite.test.php b/lib/plugins/authpdo/_test/sqlite.test.php
new file mode 100644
index 000000000..b60072d94
--- /dev/null
+++ b/lib/plugins/authpdo/_test/sqlite.test.php
@@ -0,0 +1,49 @@
+<?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';
+ }
+
+ 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')));
+
+ }
+}
diff --git a/lib/plugins/authpdo/_test/test.sqlite3 b/lib/plugins/authpdo/_test/test.sqlite3
new file mode 100644
index 000000000..403bf5f72
--- /dev/null
+++ b/lib/plugins/authpdo/_test/test.sqlite3
Binary files differ