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

@ -8,11 +8,11 @@ require_once("MsCommon_mid-refactor.inc");
try {
// Connect
$conn = connect();
$conn = connect();
// Create table
$tableName = 'pdo_040test';
// common function insertRow() is not used here since the test deliberately
// common function insertRow() is not used here since the test deliberately
// executes an invalid insertion statement
// thus it's not necessary to create an encrypted column for testing column encryption
$sql = "CREATE TABLE $tableName (code INT)";
@ -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;
@ -41,7 +41,7 @@ try {
if ($error[0] === "07009") {
$success = true;
}
}
}
if ($success) {
print "Done";
} else {

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++) {
@ -79,4 +79,4 @@ OK
OK
id
väriable
tésting
tésting

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
--TEST--
Test error from preparing a parameterized query with direct query or emulate prepare when Column Encryption is enabled
Test error from preparing a parameterized query with direct query or emulate prepare when Column Encryption is enabled
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--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);