Merge pull request #613 from v-kaywon/fixPDOTests

fix double reclaring KSP function; fixed tests with emulate prepare
This commit is contained in:
Yuki Wong 2017-12-04 11:07:14 -08:00 committed by GitHub
commit ee4161aac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 95 additions and 87 deletions

View file

@ -81,7 +81,7 @@ function getDSN($sqlsrvserver, $database, $keywords = '', $disableCE = false)
$dsn .= "ColumnEncryption=Enabled;";
}
if ($keystore == "ksp" && !$disableCE) {
require('AE_Ksp.inc');
require_once('AE_Ksp.inc');
$ksp_path = getKSPPath();
$dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=$ksp_name;CEKeystoreEncryptKey=$encrypt_key;";
}
@ -523,6 +523,13 @@ function isColEncrypted()
}
}
function isAEConnected()
{
require('MsSetup.inc');
return $keystore != "none";
}
function teardown()
{
// TBD

View file

@ -31,7 +31,7 @@ try {
} catch (PDOException $e) {
$error = $e->errorInfo;
$success = false;
if (!isColEncrypted()) {
if (!isAEConnected()) {
// 21S01 is the expected ODBC Column name or number of supplied values does not match table definition error
if ($error[0] === "21S01") {
$success = true;

View file

@ -15,7 +15,7 @@ try {
// Always Encrypted does not support using DIRECT_QUERY for binding parameters
// see https://github.com/Microsoft/msphpsql/wiki/Features#aebindparam
$pdo_options = [];
if (!isColEncrypted()) {
if (!isAEConnected()) {
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = true;
}
$pdo_options[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL;
@ -35,13 +35,13 @@ try {
$st->execute(['p0' => $name]);
// Always Encrypted does not support emulate prepare
if (!isColEncrypted()) {
if (!isAEConnected()) {
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = true;
}
$st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", $pdo_options);
$st->execute(['p0' => $name2]);
if (!isColEncrypted()) {
if (!isAEConnected()) {
$statement1 = $connection->prepare("SELECT * FROM $tbname WHERE NAME LIKE :p0", $pdo_options);
$statement1->execute(['p0' => "$prefix%"]);
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = false;

View file

@ -11,13 +11,13 @@ Github 138. Test for Unicode Column Metadata.
* @param mixed $query
* @return PDOStatement
*/
function prepare($connection, $query) {
function prepare($connection, $query)
{
$pdo_options = array();
// emulate and binding parameter with direct query are not support in Always Encrypted
if ( !isColEncrypted() )
{
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE;
// emulate and binding parameter with direct query are not supported in Always Encrypted
if (!isAEConnected()) {
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = true;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = true;
}
$pdo_options[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL;
$pdo_options[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED;
@ -35,7 +35,7 @@ try {
// Create Table
$tbname = "mytáble";
createTable( $connection, $tbname, array( new ColumnMeta( "nchar(10)", "id" ), new ColumnMeta( "nchar(10)", "väriable" ), new ColumnMeta( "nchar(10)", "tésting" )));
createTable($connection, $tbname, array(new ColumnMeta("nchar(10)", "id"), new ColumnMeta("nchar(10)", "väriable"), new ColumnMeta("nchar(10)", "tésting")));
$query = "INSERT INTO $tbname (id, tésting, väriable) VALUES (:db_insert0, :db_insert1, :db_insert2)";
@ -55,9 +55,9 @@ try {
while ($row = $st->fetchAll()) {
$row = reset($row);
echo (isset($row['id']) ? "OK" : "FAIL") , "\n";
echo (isset($row['tésting']) ? "OK" : "FAIL") , "\n";
echo (isset($row['väriable']) ? "OK" : "FAIL") , "\n";
echo(isset($row['id']) ? "OK" : "FAIL") , "\n";
echo(isset($row['tésting']) ? "OK" : "FAIL") , "\n";
echo(isset($row['väriable']) ? "OK" : "FAIL") , "\n";
}
for ($i = 0; $i < $st->columnCount(); $i++) {

View file

@ -4,20 +4,21 @@ Test emulate prepare with mix bound param encodings including binary data
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
class MyStatement extends PDOStatement {
public function BindValues(array &$values, $placeholder_prefix, $columnInformation) {
$max_placeholder = 0;
foreach ($values as $field_name => &$field_value) {
$placeholder = $placeholder_prefix . $max_placeholder++;
if (isset($columnInformation['blobs'][$field_name])) {
$this->bindParam($placeholder, $field_value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
}
else {
// Even though not a blob, make sure we retain a copy of these values.
$this->bindParam($placeholder, $field_value, PDO::PARAM_STR);
}
class MyStatement extends PDOStatement
{
public function bindValues(array &$values, $placeholder_prefix, $columnInformation)
{
$max_placeholder = 0;
foreach ($values as $field_name => &$field_value) {
$placeholder = $placeholder_prefix . $max_placeholder++;
if (isset($columnInformation['blobs'][$field_name])) {
$this->bindParam($placeholder, $field_value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
} else {
// Even though not a blob, make sure we retain a copy of these values.
$this->bindParam($placeholder, $field_value, PDO::PARAM_STR);
}
}
}
}
}
//*******************************************************
@ -34,9 +35,9 @@ try {
dropTable($cnn, $tbname);
$pdo_options = array();
if (!isColEncrypted()) {
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE;
if (!isAEConnected()) {
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = true;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = true;
$cm_arr = array(new ColumnMeta("int", "wid", "IDENTITY(1,1) NOT NULL"),
new ColumnMeta("int", "uid", "NOT NULL CONSTRAINT [watchdog_uid_df] DEFAULT ((0))"),
@ -51,8 +52,8 @@ try {
new ColumnMeta("int", "timestamp", "NOT NULL CONSTRAINT [watchdog_timestamp_df] DEFAULT ((0))"));
} else {
// Emulate prepare and using direct query for binding parameters are not supported in Always encrypted
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = FALSE;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = FALSE;
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = false;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = false;
// Default constraints are unsupported on encrypted columns
$cm_arr = array(new ColumnMeta("int", "wid", "IDENTITY(1,1) NOT NULL"),
@ -73,7 +74,7 @@ try {
$cd_arr = array();
foreach ($cm_arr as $cm) {
array_push( $cd_arr, $cm->getColDef());
array_push($cd_arr, $cm->getColDef());
}
$tablescript = "CREATE TABLE [dbo].[$tbname](
@ -100,7 +101,7 @@ try {
/** @var MyStatement */
$st = $cnn->prepare($query, $pdo_options);
$st->BindValues($values, ':db_insert', $columnInformation);
$st->bindValues($values, ':db_insert', $columnInformation);
$st->execute();
$st = $cnn->query("SELECT * FROM [$tbname]");

View file

@ -21,7 +21,7 @@ try {
} catch (PDOException $e) {
$error = $e->errorInfo;
// expects an exception if Column Encryption is enabled
if (isColEncrypted()) {
if (isAEConnected()) {
if ($error[0] != "IMSSP" ||
$error[1] != -81 ||
$error[2] != "Parameterized statement with attribute PDO::SQLSRV_ATTR_DIRECT_QUERY is not supported in a Column Encryption enabled Connection.") {
@ -40,7 +40,7 @@ try {
} catch (PDOException $e) {
$error = $e->errorInfo;
// expects an exception if Column Encryption is enabled
if (isColEncrypted()) {
if (isAEConnected()) {
if ($error[0] != "IMSSP" ||
$error[1] != -82 ||
$error[2] != "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.") {

View file

@ -35,7 +35,7 @@ try {
$cnn->exec("TRUNCATE TABLE $tbname");
//EMULATE PREPARE with SQLSRV_ENCODING_BINARY
if (!isColEncrypted()) {
if (!isAEConnected()) {
// Emulate prepare does not work fro encrypted columns
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = true;
}
@ -59,10 +59,10 @@ try {
$st->bindParam(':p0', $p, PDO::PARAM_LOB);
$st->execute();
$error = $st->errorInfo();
if (!isColEncrypted() && $error[0] !== "42000") {
if (!isAEConnected() && $error[0] !== "42000") {
echo "Error 42000 is expected: Implicit conversion from data type varchar to varbinary(max) is not allowed.\n";
var_dump($error);
} elseif (isColEncrypted() && $error[0] != "22018") {
} elseif (isAEConnected() && $error[0] != "22018") {
echo "Error 22018 is expected: Invalid character value for cast specification.\n";
var_dump($error);
} else {

View file

@ -30,7 +30,7 @@ try {
//prepare with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bindParam options:\n");
if (!isColEncrypted()) {
if (!isAEConnected()) {
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}
$stmt = $conn->prepare($query, $options);

View file

@ -29,7 +29,7 @@ try {
print_r($row);
//with emulate prepare and no bind param options
if (!isColEncrypted()) {
if (!isAEConnected()) {
// emulate prepare is not supported in encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}

View file

@ -10,7 +10,7 @@ try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
$tableName = "number_types";
if (!isColEncrypted()) {
if (!isAEConnected()) {
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float"));
} else {
// money is not supported for column encryption, use decimal(19,4) instead
@ -35,7 +35,7 @@ try {
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
if (!isColEncrypted()) {
if (!isAEConnected()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}

View file

@ -10,7 +10,7 @@ try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
$tableName = "number_types";
if (!isColEncrypted()) {
if (!isAEConnected()) {
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float"));
} else {
// money is not supported for column encryption, use decimal(19,4) instead
@ -35,7 +35,7 @@ try {
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
if (!isColEncrypted()) {
if (!isAEConnected()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}

View file

@ -29,7 +29,7 @@ try {
// prepare with emulate prepare
print_r("Prepare with emulate prepare and no bindParam options:\n");
if (!isColEncrypted()) {
if (!isAEConnected()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}
@ -39,7 +39,7 @@ try {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if (!isColEncrypted()) {
if (!isAEConnected()) {
// without emulate prepare, binding PARAM_INT with SQLSRV_ENCODING_SYSTEM is not allowed
// thus the following will not be tested when Column Encryption is enabled

View file

@ -10,7 +10,7 @@ try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
$tableName = "number_types";
if (!isColEncrypted()) {
if (!isAEConnected()) {
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float"));
} else {
// money is not supported for column encryption, use decimal(19,4) instead
@ -35,7 +35,7 @@ try {
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
if (!isColEncrypted()) {
if (!isAEConnected()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}

View file

@ -48,7 +48,7 @@ try {
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bindParam options:\n");
if (!isColEncrypted()) {
if (!isAEConnected()) {
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
} else {
$options = array(PDO::ATTR_EMULATE_PREPARES => false);