Loading dbee.module +12 −6 Changes for dbee.module: 12 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -403,12 +403,14 @@ function dbee_module_implements_alter(&$implementations, $hook) { * replace this function by the custom function * (dbee_user_account_form_validate()). The dbee_query_alter() is going to * encrypt any dynamic tagged query that contains the mail or init field into the * where clause. This function add 2 tags on queries informing that some fields * may probably need to be decrypted from the result set : 'dbee_mail' and * 'dbee_init' tags for the 'mail' and 'init' fields. Concerning core fuctions, * this function is only used for fixing the user_load_by_mail() function. The * dbee_query_alter() function improves the dbee module compatibility with * custom modules that would use dynamic tagged queries. * where clause. Acting on tags : * - if the query contains the tag 'dbee_disabled' no alteration will occure. * - if the query contains the tags 'dbee_mail_disable_insensitive_case' or * 'dbee_init_disable_insensitive_case' : the search will be sensitive case * (it is not the default behavior on mysql, read code and issue below). * Tags added by the dbee module : * - 'dbee_mail' if the query contains users.mail field on where clause. * - 'dbee_init' if the query contains users.init field on where clause. */ function dbee_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) { Loading Loading @@ -465,8 +467,12 @@ function dbee_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) } // Now take care of the WHERE clause. // The 'dbee_disabled' tag disable all dbee stuff on queries. if (empty($query->alterTags['dbee_disabled'])) { _dbee_where_clause($query, $users_alias, $dbee_alias); } } } /** Loading src/Tests/DbeeQueryUsersTestCase.php +39 −24 Changes for src/Tests/DbeeQueryUsersTestCase.php: 39 added lines, 24 removed lines. Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ namespace Drupal\dbee\Tests; * * @group dbee */ class DbeeQueryUsersTestCase extends DbeeWebTestBase { class DbeeQueryUsersTestCase extends DbeeWebTestBaseSwitch { protected $user_2; protected $user_3; protected $user_4; Loading Loading @@ -51,80 +51,84 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { if (!$dbee) { // uninstall the dbee module. $this->drupalLogin($this->admin_modules_account); $edit1 = array('uninstall[dbee]' => TRUE); $this->drupalPostForm('admin/modules/uninstall', $edit1, t('Uninstall')); // Confirmation page. $this->drupalPostForm('admin/modules/uninstall/confirm', array(), t('Uninstall')); $this->rebuildContainer(); $this->assertFalse($this->container->get('module_handler')->moduleExists('dbee'), 'dbee module uninstalled.'); $this->dbee_enabling_disabling_dbee_module(FALSE); } $this->drupalLogin($this->user_view_users); foreach (array('mail', 'init') as $dbee_field) { $result_uids = array(); for ($test = 1; $test <= 14; $test++) { for ($test = 1; $test <= 16; $test++) { $result_uids = array(); switch ($test) { case 1: // Look for NULL. $test_title[$test] = 'querying empty mail or init value, operator \'IS NULL\'.'; $operator = 'IS NULL'; break; case 2: // Look for NOT NULL. $test_title[$test] = 'querying empty mail or init value, operator \'IS NOT NULL\'.'; $operator = 'IS NOT NULL'; break; case 3: // Look for empty sting. $test_title[$test] = 'querying empty mail or init value, operator \'=\'.'; $keys = ''; $operator = '='; break; case 2: case 4: // Look for empty sting. $test_title[$test] = 'querying empty mail or init value, operator \'<>\'.'; // $keys same than test 1. $operator = '<>'; break; case 3: case 5: // Test searching 1 whole email. $test_title[$test] = 'querying a user by mail or init exact value, operator \'=\'.'; $keys = $this->user_2->$dbee_field->value; $operator = '='; break; case 4: case 6: // Test searching 1 whole email. $test_title[$test] = 'querying a user by mail or init exact value, operator \'<>\'.'; // $keys same than test 3. $operator = '<>'; break; case 5: case 7: // Test searching 1 whole mail email value changing case. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'=\'.'; $keys = \Drupal\Component\Utility\Unicode::strtoupper($this->user_2->$dbee_field->value); $operator = '='; break; case 6: case 8: // Test searching 1 whole mail email value changing case. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'<>\'.'; // $keys same than test 5. $operator = '<>'; break; case 7: case 9: // Test searching an mail email value changing case with 'like' operator. // $keys is the same as test 5 and 6. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'LIKE\'.'; $operator = 'LIKE'; break; case 8: case 10: // Test searching an mail email value changing case with 'like' operator. // $keys is the same as test 5, 6 and 7. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'NOT LIKE\'.'; $operator = 'NOT LIKE'; break; case 9: case 11: // Test searching 2 whole email. $test_title[$test] = 'querying 2 user by mail or init exact value, operator \'IN\'.'; $keys = array( Loading @@ -134,35 +138,35 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { $operator = 'IN'; break; case 10: case 12: // Test searching 2 whole email. // $keys is the same than test 9. $test_title[$test] = 'querying 2 user by mail or init exact value, operator \'NOT IN\'.'; $operator = 'NOT IN'; break; case 11: case 13: // Test searching 3 users by a partial key. $keys = '%exAM_le.com%'; $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\'), operator \'LIKE\'.'; $operator = 'LIKE'; break; case 12: case 14: // Test searching 3 users by a partial key. // $keys is the same than test 11. $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\'), operator \'NOT LIKE\'.'; $operator = 'NOT LIKE'; break; case 13: case 15: // Using nested conditions. $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\') on nested conditions, operator \'LIKE\'.'; // $keys is the same than test 11 and 12. $operator = 'LIKE'; break; case 14: case 16: // Using nested conditions. $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\') on nested conditions, operator \'NOT LIKE\'.'; // $keys is the same than test 11, 12 and 13. Loading @@ -171,12 +175,20 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { } $query = db_select('users_field_data', 'u'); $query = \Drupal::database()->select('users_field_data', 'u'); $query->fields('u', array('uid', 'mail', 'name', 'status', 'created', 'access')); if ($test < 13) { if ($test < 15) { if (!in_array($operator, array('IS NULL', 'IS NOT NULL'))) { $query->condition("u.$dbee_field", $keys, $operator); } elseif ($operator == 'IS NULL') { $query->isNull("u.$dbee_field"); } elseif ($operator == 'IS NOT NULL') { $query->isNotNull("u.$dbee_field"); } } else { $query->condition(db_or()-> condition('name', 'Not exists', '=')-> Loading @@ -184,6 +196,9 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { } // The hook_query_alter function only works on dynamic tagged queries. $query->addTag('test'); if (!$dbee) { $query->addTag('dbee_disabled'); } $query->orderBy('uid'); $result = $query->execute(); $result_uids = array(); Loading src/Tests/DbeeSearchUserTestCase.php +8 −20 Changes for src/Tests/DbeeSearchUserTestCase.php: 8 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ use Drupal\Core\Link; * * @group dbee */ class DbeeSearchUserTestCase extends DbeeWebTestBase { class DbeeSearchUserTestCase extends DbeeWebTestBaseSwitch { protected $existing_user1; protected $existing_user2; protected $existing_user3; Loading Loading @@ -54,7 +54,14 @@ class DbeeSearchUserTestCase extends DbeeWebTestBase { protected function testSearchUser() { // Test the feature : search user using an existing email address : first // without the dbee module, then with dbee module enable. $this->searchUsers(); // Enable the dbee module. $this->dbee_enabling_disabling_dbee_module(TRUE); // Search again. $this->searchUsers(); } protected function searchUsers() { $this->drupalLogin($this->search_users_account); // Search the completed email address. $edit1 = array('keys' => \Drupal\Component\Utility\Unicode::strtoupper($this->existing_user1->mail->value)); Loading @@ -74,24 +81,5 @@ class DbeeSearchUserTestCase extends DbeeWebTestBase { $link4 = Link::fromTextAndUrl($this->existing_user3->name->value . ' (' . $this->existing_user3->mail->value . ')', \Drupal\Core\Url::fromRoute('entity.user.canonical', ['user' => $this->existing_user3->id()], array('absolute' => TRUE)))->toString(); $this->assertNoRaw($link4, 'searching user by partial email address succeed (third user not finded)'); // Install dbee module. $this->drupalLogin($this->admin_modules_account); $edit3 = array('modules[dbee][enable]' => TRUE); $this->drupalPostForm('admin/modules', $edit3, t('Install')); $this->rebuildContainer(); $this->assertTrue($this->container->get('module_handler')->moduleExists('dbee'), 'dbee module installed.'); // Search again. $this->drupalLogin($this->search_users_account); $this->drupalPostForm('search/user', array('keys' => $mail1), t('Search')); $this->assertRaw($link1, 'searching user by completed email address still succeed'); // Search the partial email address. $this->drupalPostForm('search/user', $edit2, t('Search')); $this->assertRaw($link2, 'searching user by partial email address still succeed (first user finded)'); $this->assertRaw($link3, 'searching user by partial email address still succeed (second user finded)'); $this->assertNoRaw($link4, 'searching user by partial email address still succeed (third user not finded)'); } } Loading
dbee.module +12 −6 Changes for dbee.module: 12 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -403,12 +403,14 @@ function dbee_module_implements_alter(&$implementations, $hook) { * replace this function by the custom function * (dbee_user_account_form_validate()). The dbee_query_alter() is going to * encrypt any dynamic tagged query that contains the mail or init field into the * where clause. This function add 2 tags on queries informing that some fields * may probably need to be decrypted from the result set : 'dbee_mail' and * 'dbee_init' tags for the 'mail' and 'init' fields. Concerning core fuctions, * this function is only used for fixing the user_load_by_mail() function. The * dbee_query_alter() function improves the dbee module compatibility with * custom modules that would use dynamic tagged queries. * where clause. Acting on tags : * - if the query contains the tag 'dbee_disabled' no alteration will occure. * - if the query contains the tags 'dbee_mail_disable_insensitive_case' or * 'dbee_init_disable_insensitive_case' : the search will be sensitive case * (it is not the default behavior on mysql, read code and issue below). * Tags added by the dbee module : * - 'dbee_mail' if the query contains users.mail field on where clause. * - 'dbee_init' if the query contains users.init field on where clause. */ function dbee_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) { Loading Loading @@ -465,8 +467,12 @@ function dbee_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) } // Now take care of the WHERE clause. // The 'dbee_disabled' tag disable all dbee stuff on queries. if (empty($query->alterTags['dbee_disabled'])) { _dbee_where_clause($query, $users_alias, $dbee_alias); } } } /** Loading
src/Tests/DbeeQueryUsersTestCase.php +39 −24 Changes for src/Tests/DbeeQueryUsersTestCase.php: 39 added lines, 24 removed lines. Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ namespace Drupal\dbee\Tests; * * @group dbee */ class DbeeQueryUsersTestCase extends DbeeWebTestBase { class DbeeQueryUsersTestCase extends DbeeWebTestBaseSwitch { protected $user_2; protected $user_3; protected $user_4; Loading Loading @@ -51,80 +51,84 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { if (!$dbee) { // uninstall the dbee module. $this->drupalLogin($this->admin_modules_account); $edit1 = array('uninstall[dbee]' => TRUE); $this->drupalPostForm('admin/modules/uninstall', $edit1, t('Uninstall')); // Confirmation page. $this->drupalPostForm('admin/modules/uninstall/confirm', array(), t('Uninstall')); $this->rebuildContainer(); $this->assertFalse($this->container->get('module_handler')->moduleExists('dbee'), 'dbee module uninstalled.'); $this->dbee_enabling_disabling_dbee_module(FALSE); } $this->drupalLogin($this->user_view_users); foreach (array('mail', 'init') as $dbee_field) { $result_uids = array(); for ($test = 1; $test <= 14; $test++) { for ($test = 1; $test <= 16; $test++) { $result_uids = array(); switch ($test) { case 1: // Look for NULL. $test_title[$test] = 'querying empty mail or init value, operator \'IS NULL\'.'; $operator = 'IS NULL'; break; case 2: // Look for NOT NULL. $test_title[$test] = 'querying empty mail or init value, operator \'IS NOT NULL\'.'; $operator = 'IS NOT NULL'; break; case 3: // Look for empty sting. $test_title[$test] = 'querying empty mail or init value, operator \'=\'.'; $keys = ''; $operator = '='; break; case 2: case 4: // Look for empty sting. $test_title[$test] = 'querying empty mail or init value, operator \'<>\'.'; // $keys same than test 1. $operator = '<>'; break; case 3: case 5: // Test searching 1 whole email. $test_title[$test] = 'querying a user by mail or init exact value, operator \'=\'.'; $keys = $this->user_2->$dbee_field->value; $operator = '='; break; case 4: case 6: // Test searching 1 whole email. $test_title[$test] = 'querying a user by mail or init exact value, operator \'<>\'.'; // $keys same than test 3. $operator = '<>'; break; case 5: case 7: // Test searching 1 whole mail email value changing case. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'=\'.'; $keys = \Drupal\Component\Utility\Unicode::strtoupper($this->user_2->$dbee_field->value); $operator = '='; break; case 6: case 8: // Test searching 1 whole mail email value changing case. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'<>\'.'; // $keys same than test 5. $operator = '<>'; break; case 7: case 9: // Test searching an mail email value changing case with 'like' operator. // $keys is the same as test 5 and 6. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'LIKE\'.'; $operator = 'LIKE'; break; case 8: case 10: // Test searching an mail email value changing case with 'like' operator. // $keys is the same as test 5, 6 and 7. $test_title[$test] = 'querying a user by mail or init with sensitive case conflict value, operator \'NOT LIKE\'.'; $operator = 'NOT LIKE'; break; case 9: case 11: // Test searching 2 whole email. $test_title[$test] = 'querying 2 user by mail or init exact value, operator \'IN\'.'; $keys = array( Loading @@ -134,35 +138,35 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { $operator = 'IN'; break; case 10: case 12: // Test searching 2 whole email. // $keys is the same than test 9. $test_title[$test] = 'querying 2 user by mail or init exact value, operator \'NOT IN\'.'; $operator = 'NOT IN'; break; case 11: case 13: // Test searching 3 users by a partial key. $keys = '%exAM_le.com%'; $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\'), operator \'LIKE\'.'; $operator = 'LIKE'; break; case 12: case 14: // Test searching 3 users by a partial key. // $keys is the same than test 11. $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\'), operator \'NOT LIKE\'.'; $operator = 'NOT LIKE'; break; case 13: case 15: // Using nested conditions. $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\') on nested conditions, operator \'LIKE\'.'; // $keys is the same than test 11 and 12. $operator = 'LIKE'; break; case 14: case 16: // Using nested conditions. $test_title[$test] = 'querying users by mail or init value using wildcard (\'' . $keys . '\') on nested conditions, operator \'NOT LIKE\'.'; // $keys is the same than test 11, 12 and 13. Loading @@ -171,12 +175,20 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { } $query = db_select('users_field_data', 'u'); $query = \Drupal::database()->select('users_field_data', 'u'); $query->fields('u', array('uid', 'mail', 'name', 'status', 'created', 'access')); if ($test < 13) { if ($test < 15) { if (!in_array($operator, array('IS NULL', 'IS NOT NULL'))) { $query->condition("u.$dbee_field", $keys, $operator); } elseif ($operator == 'IS NULL') { $query->isNull("u.$dbee_field"); } elseif ($operator == 'IS NOT NULL') { $query->isNotNull("u.$dbee_field"); } } else { $query->condition(db_or()-> condition('name', 'Not exists', '=')-> Loading @@ -184,6 +196,9 @@ class DbeeQueryUsersTestCase extends DbeeWebTestBase { } // The hook_query_alter function only works on dynamic tagged queries. $query->addTag('test'); if (!$dbee) { $query->addTag('dbee_disabled'); } $query->orderBy('uid'); $result = $query->execute(); $result_uids = array(); Loading
src/Tests/DbeeSearchUserTestCase.php +8 −20 Changes for src/Tests/DbeeSearchUserTestCase.php: 8 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ use Drupal\Core\Link; * * @group dbee */ class DbeeSearchUserTestCase extends DbeeWebTestBase { class DbeeSearchUserTestCase extends DbeeWebTestBaseSwitch { protected $existing_user1; protected $existing_user2; protected $existing_user3; Loading Loading @@ -54,7 +54,14 @@ class DbeeSearchUserTestCase extends DbeeWebTestBase { protected function testSearchUser() { // Test the feature : search user using an existing email address : first // without the dbee module, then with dbee module enable. $this->searchUsers(); // Enable the dbee module. $this->dbee_enabling_disabling_dbee_module(TRUE); // Search again. $this->searchUsers(); } protected function searchUsers() { $this->drupalLogin($this->search_users_account); // Search the completed email address. $edit1 = array('keys' => \Drupal\Component\Utility\Unicode::strtoupper($this->existing_user1->mail->value)); Loading @@ -74,24 +81,5 @@ class DbeeSearchUserTestCase extends DbeeWebTestBase { $link4 = Link::fromTextAndUrl($this->existing_user3->name->value . ' (' . $this->existing_user3->mail->value . ')', \Drupal\Core\Url::fromRoute('entity.user.canonical', ['user' => $this->existing_user3->id()], array('absolute' => TRUE)))->toString(); $this->assertNoRaw($link4, 'searching user by partial email address succeed (third user not finded)'); // Install dbee module. $this->drupalLogin($this->admin_modules_account); $edit3 = array('modules[dbee][enable]' => TRUE); $this->drupalPostForm('admin/modules', $edit3, t('Install')); $this->rebuildContainer(); $this->assertTrue($this->container->get('module_handler')->moduleExists('dbee'), 'dbee module installed.'); // Search again. $this->drupalLogin($this->search_users_account); $this->drupalPostForm('search/user', array('keys' => $mail1), t('Search')); $this->assertRaw($link1, 'searching user by completed email address still succeed'); // Search the partial email address. $this->drupalPostForm('search/user', $edit2, t('Search')); $this->assertRaw($link2, 'searching user by partial email address still succeed (first user finded)'); $this->assertRaw($link3, 'searching user by partial email address still succeed (second user finded)'); $this->assertNoRaw($link4, 'searching user by partial email address still succeed (third user not finded)'); } }