Skip to content

Commit

Permalink
added fluxbb dump to the tests.
Browse files Browse the repository at this point in the history
now all capabilities are covered
  • Loading branch information
splitbrain committed Feb 12, 2016
1 parent 07a11e2 commit df01249
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 3 deletions.
55 changes: 52 additions & 3 deletions lib/plugins/authpdo/_test/mysql.test.php
Expand Up @@ -90,17 +90,47 @@ protected function importDatabase($file) {
* @param array $users
*/
protected function runGeneralTests(auth_plugin_authpdo $auth, $users) {
$this->assertTrue($auth->success, 'intialize auth');
global $conf;
$info = 'DSN: ' . $auth->getConf('dsn');
$this->assertTrue($auth->success, $info);

if($auth->canDo('getUsers')) {
$list = $auth->retrieveUsers();
$this->assertGreaterThanOrEqual(count($users), count($list));
$this->assertGreaterThanOrEqual(count($users), count($list), $info);
}

if($auth->canDo('getGroups')) {
$list = $auth->retrieveGroups();
$this->assertGreaterThanOrEqual(1, $list, $info);
}

if($auth->canDo('getUserCount')) {
$count = $auth->getUserCount();
$this->assertGreaterThanOrEqual(count($users), $count);
}

if($auth->canDo('addUser')) {
$newuser = array(
'user' => 'newuserfoobar',
'name' => 'First LastFoobar',
'pass' => 'password',
'mail' => 'newuserfoobar@example.com',
'grps' => array('acompletelynewgroup')
);
$ok = $auth->createUser(
$newuser['user'],
$newuser['pass'],
$newuser['name'],
$newuser['mail'],
$newuser['grps']
);
$this->assertTrue($ok, $info);
$check = $auth->getUserData($newuser['user']);
$this->assertEquals($newuser['user'], $check['user'], $info);
$this->assertEquals($newuser['mail'], $check['mail'], $info);
$groups = array_merge($newuser['grps'], array($conf['defaultgroup']));
$this->assertEquals($groups, $check['grps'], $info);
}
}

/**
Expand All @@ -111,7 +141,7 @@ protected function runGeneralTests(auth_plugin_authpdo $auth, $users) {
*/
protected function runUserTests(auth_plugin_authpdo $auth, $user) {
global $conf;
$info = 'testing ' . $user['user'];
$info = 'DSN: ' . $auth->getConf('dsn') . ' User:' . $user['user'];

// minimal setup
$this->assertTrue($auth->checkPass($user['user'], $user['pass']), $info);
Expand Down Expand Up @@ -142,6 +172,15 @@ protected function runUserTests(auth_plugin_authpdo $auth, $user) {
$this->assertGreaterThanOrEqual(1, $count);
}

// modGroups
if($auth->canDo('modGroups')) {
$newgroup = 'foobar';
$ok = $auth->modifyUser($user['user'], array('grps' => array($newgroup)));
$this->assertTrue($ok, $info);
$check = $auth->getUserData($user['user']);
$this->assertTrue(in_array($newgroup, $check['grps']), $info);
}

// modPass
if($auth->canDo('modPass')) {
$newpass = 'foobar';
Expand Down Expand Up @@ -175,8 +214,17 @@ protected function runUserTests(auth_plugin_authpdo $auth, $user) {
$this->assertTrue($ok, $info);
$check = $auth->getUserData($newuser);
$this->assertEquals($newuser, $check['user'], $info);
// rename back
$ok = $auth->modifyUser($newuser, array('user' => $user['user']));
$this->assertTrue($ok, $info);
}

// delUser
if($auth->canDo('delUser')) {
$num = $auth->deleteUsers(array($user['user']));
$this->assertEquals(1, $num, $info);
$this->assertFalse($auth->getUserData($user['user']), $info);
}
}

/**
Expand All @@ -190,6 +238,7 @@ public function test_mysql() {
$files = glob(__DIR__ . '/mysql/*.php');
foreach($files as $file) {
$dump = preg_replace('/\.php$/', '.sql', $file);
$this->database = 'authpdo_testing_' . basename($file, '.php');

$this->createDatabase();
$this->importDatabase($dump);
Expand Down
104 changes: 104 additions & 0 deletions lib/plugins/authpdo/_test/mysql/fluxbb.php
@@ -0,0 +1,104 @@
<?php
/**
* Confiuration for fluxbb. They have a very simplistic model. There is no separate display name and a user can
* only be in a single group.
*/
/** @noinspection SqlResolve */
$data = array(
'passcrypt' => 'sha1',
'conf' => array(
'select-user' => '
SELECT id AS uid,
username AS user,
username AS name,
password AS hash,
email AS mail
FROM fluy_users
WHERE username = :user
',
'select-user-groups' => '
SELECT g_title AS `group`
FROM fluy_groups G, fluy_users U
WHERE U.id = :uid
AND U.group_id = G.g_id
',
'select-groups' => '
SELECT g_id AS gid, g_title AS `group`
FROM fluy_groups
',
'insert-user' => '
INSERT INTO fluy_users
(group_id, username, password, email)
VALUES (0, :user, :hash, :mail)
',
'delete-user' => '
DELETE FROM fluy_users
WHERE id = :uid
',
'list-users' => '
SELECT DISTINCT username AS user
FROM fluy_users U, fluy_groups G
WHERE U.id = G.g_id
AND G.g_title LIKE :group
AND U.username LIKE :user
AND U.username LIKE :name
AND U.email LIKE :mail
ORDER BY username
LIMIT :limit
OFFSET :start
',
'count-users' => '
SELECT COUNT(DISTINCT username) AS `count`
FROM fluy_users U, fluy_groups G
WHERE U.id = G.g_id
AND G.g_title LIKE :group
AND U.username LIKE :user
AND U.username LIKE :name
AND U.email LIKE :mail
',
'update-user-info' => '', // we can't do this because username = displayname
'update-user-login' => '
UPDATE fluy_users
SET username = :newlogin
WHERE id = :uid
',
'update-user-pass' => '
UPDATE fluy_users
SET password = :hash
WHERE id = :uid
',
'insert-group' => '
INSERT INTO fluy_groups (g_title) VALUES (:group)
',
'join-group' => '
UPDATE fluy_users
SET group_id = :gid
WHERE id = :uid
',
'leave-group' => '
SELECT 1
', // we do a no-op for this
),
'users' => array(
array(
'user' => 'admin',
'pass' => 'pass',
'name' => 'admin',
'mail' => 'admin@example.com',
'grps' =>
array(
0 => 'Administrators',
),
),
array(
'user' => 'test1',
'pass' => 'password',
'name' => 'test1',
'mail' => 'test1@example.com',
'grps' =>
array(
0 => 'test',
),
),
),
);
136 changes: 136 additions & 0 deletions lib/plugins/authpdo/_test/mysql/fluxbb.sql
@@ -0,0 +1,136 @@
-- phpMyAdmin SQL Dump
-- version 4.0.10.7
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: Feb 12, 2016 at 03:06 PM
-- Server version: 10.0.23-MariaDB
-- PHP Version: 5.4.31

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `dokuwiki_flux570`
--

-- --------------------------------------------------------

--
-- Table structure for table `fluy_groups`
--

CREATE TABLE IF NOT EXISTS `fluy_groups` (
`g_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`g_title` varchar(50) NOT NULL DEFAULT '',
`g_user_title` varchar(50) DEFAULT NULL,
`g_promote_min_posts` int(10) unsigned NOT NULL DEFAULT '0',
`g_promote_next_group` int(10) unsigned NOT NULL DEFAULT '0',
`g_moderator` tinyint(1) NOT NULL DEFAULT '0',
`g_mod_edit_users` tinyint(1) NOT NULL DEFAULT '0',
`g_mod_rename_users` tinyint(1) NOT NULL DEFAULT '0',
`g_mod_change_passwords` tinyint(1) NOT NULL DEFAULT '0',
`g_mod_ban_users` tinyint(1) NOT NULL DEFAULT '0',
`g_mod_promote_users` tinyint(1) NOT NULL DEFAULT '0',
`g_read_board` tinyint(1) NOT NULL DEFAULT '1',
`g_view_users` tinyint(1) NOT NULL DEFAULT '1',
`g_post_replies` tinyint(1) NOT NULL DEFAULT '1',
`g_post_topics` tinyint(1) NOT NULL DEFAULT '1',
`g_edit_posts` tinyint(1) NOT NULL DEFAULT '1',
`g_delete_posts` tinyint(1) NOT NULL DEFAULT '1',
`g_delete_topics` tinyint(1) NOT NULL DEFAULT '1',
`g_post_links` tinyint(1) NOT NULL DEFAULT '1',
`g_set_title` tinyint(1) NOT NULL DEFAULT '1',
`g_search` tinyint(1) NOT NULL DEFAULT '1',
`g_search_users` tinyint(1) NOT NULL DEFAULT '1',
`g_send_email` tinyint(1) NOT NULL DEFAULT '1',
`g_post_flood` smallint(6) NOT NULL DEFAULT '30',
`g_search_flood` smallint(6) NOT NULL DEFAULT '30',
`g_email_flood` smallint(6) NOT NULL DEFAULT '60',
`g_report_flood` smallint(6) NOT NULL DEFAULT '60',
PRIMARY KEY (`g_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `fluy_groups`
--

INSERT INTO `fluy_groups` (`g_id`, `g_title`, `g_user_title`, `g_promote_min_posts`, `g_promote_next_group`, `g_moderator`, `g_mod_edit_users`, `g_mod_rename_users`, `g_mod_change_passwords`, `g_mod_ban_users`, `g_mod_promote_users`, `g_read_board`, `g_view_users`, `g_post_replies`, `g_post_topics`, `g_edit_posts`, `g_delete_posts`, `g_delete_topics`, `g_post_links`, `g_set_title`, `g_search`, `g_search_users`, `g_send_email`, `g_post_flood`, `g_search_flood`, `g_email_flood`, `g_report_flood`) VALUES
(1, 'Administrators', 'Administrator', 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0),
(2, 'Moderators', 'Moderator', 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0),
(3, 'Guests', NULL, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 60, 30, 0, 0),
(4, 'Members', NULL, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 60, 30, 60, 60),
(5, 'test', NULL, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 60, 30, 60, 60);

-- --------------------------------------------------------

--
-- Table structure for table `fluy_users`
--

CREATE TABLE IF NOT EXISTS `fluy_users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`group_id` int(10) unsigned NOT NULL DEFAULT '3',
`username` varchar(200) NOT NULL DEFAULT '',
`password` varchar(40) NOT NULL DEFAULT '',
`email` varchar(80) NOT NULL DEFAULT '',
`title` varchar(50) DEFAULT NULL,
`realname` varchar(40) DEFAULT NULL,
`url` varchar(100) DEFAULT NULL,
`jabber` varchar(80) DEFAULT NULL,
`icq` varchar(12) DEFAULT NULL,
`msn` varchar(80) DEFAULT NULL,
`aim` varchar(30) DEFAULT NULL,
`yahoo` varchar(30) DEFAULT NULL,
`location` varchar(30) DEFAULT NULL,
`signature` text,
`disp_topics` tinyint(3) unsigned DEFAULT NULL,
`disp_posts` tinyint(3) unsigned DEFAULT NULL,
`email_setting` tinyint(1) NOT NULL DEFAULT '1',
`notify_with_post` tinyint(1) NOT NULL DEFAULT '0',
`auto_notify` tinyint(1) NOT NULL DEFAULT '0',
`show_smilies` tinyint(1) NOT NULL DEFAULT '1',
`show_img` tinyint(1) NOT NULL DEFAULT '1',
`show_img_sig` tinyint(1) NOT NULL DEFAULT '1',
`show_avatars` tinyint(1) NOT NULL DEFAULT '1',
`show_sig` tinyint(1) NOT NULL DEFAULT '1',
`timezone` float NOT NULL DEFAULT '0',
`dst` tinyint(1) NOT NULL DEFAULT '0',
`time_format` tinyint(1) NOT NULL DEFAULT '0',
`date_format` tinyint(1) NOT NULL DEFAULT '0',
`language` varchar(25) NOT NULL DEFAULT 'English',
`style` varchar(25) NOT NULL DEFAULT 'Air',
`num_posts` int(10) unsigned NOT NULL DEFAULT '0',
`last_post` int(10) unsigned DEFAULT NULL,
`last_search` int(10) unsigned DEFAULT NULL,
`last_email_sent` int(10) unsigned DEFAULT NULL,
`last_report_sent` int(10) unsigned DEFAULT NULL,
`registered` int(10) unsigned NOT NULL DEFAULT '0',
`registration_ip` varchar(39) NOT NULL DEFAULT '0.0.0.0',
`last_visit` int(10) unsigned NOT NULL DEFAULT '0',
`admin_note` varchar(30) DEFAULT NULL,
`activate_string` varchar(80) DEFAULT NULL,
`activate_key` varchar(8) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `fluy_users_username_idx` (`username`(25)),
KEY `fluy_users_registered_idx` (`registered`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `fluy_users`
--

INSERT INTO `fluy_users` (`id`, `group_id`, `username`, `password`, `email`, `title`, `realname`, `url`, `jabber`, `icq`, `msn`, `aim`, `yahoo`, `location`, `signature`, `disp_topics`, `disp_posts`, `email_setting`, `notify_with_post`, `auto_notify`, `show_smilies`, `show_img`, `show_img_sig`, `show_avatars`, `show_sig`, `timezone`, `dst`, `time_format`, `date_format`, `language`, `style`, `num_posts`, `last_post`, `last_search`, `last_email_sent`, `last_report_sent`, `registered`, `registration_ip`, `last_visit`, `admin_note`, `activate_string`, `activate_key`) VALUES
(1, 3, 'Guest', 'Guest', 'Guest', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 'English', 'Air', 0, NULL, NULL, NULL, NULL, 0, '0.0.0.0', 0, NULL, NULL, NULL),
(2, 1, 'admin', '9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684', 'admin@example.com', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 'English', 'Air', 1, 1455307304, NULL, NULL, NULL, 1455307304, '86.56.56.211', 1455307448, NULL, NULL, NULL),
(3, 5, 'test1', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'test1@example.com', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 'English', 'Air', 0, NULL, NULL, NULL, NULL, 1455307527, '86.56.56.217', 1455307529, NULL, NULL, NULL);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

0 comments on commit df01249

Please sign in to comment.