You are here

public function SelectQueryTest::testBadKeysInArrayArguments in Drupal driver for SQL Server and SQL Azure 8

Test for weird key names in array arguments.

File

src/Tests/SelectQueryTest.php, line 154
Definition of Drupal\sqlsrv\Tests\SelectQueryTest.

Class

SelectQueryTest
General tests for SQL Server database driver.

Namespace

Drupal\sqlsrv\Tests

Code

public function testBadKeysInArrayArguments() {
  $params[':nids'] = array(
    'uid1' => -9,
    'What a bad placeholder name, why should we care?' => -6,
  );
  $result = NULL;
  try {

    // The regular expandArguments implementation will fail to
    // properly expand the associative array with weird keys, OH, and actually
    // you can perform some SQL Injection through the array keys.
    $result = db_query('SELECT COUNT(*) FROM USERS WHERE USERS.UID IN (:nids)', $params)
      ->execute()
      ->fetchField();
  } catch (\Exception $err) {

    // Regular drupal will fail with
    // SQLSTATE[IMSSP]: An error occurred substituting the named parameters.
    // https://www.drupal.org/node/2146839
  }

  // User ID's are negative, so this should return 0 matches.
  $this
    ->assertEqual($result, 0, 'Returned the correct number of total rows.');
}