From b695cc1655973cc03700588e12a560257e55c120 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 11:45:13 -0800 Subject: [PATCH] test column encryption unsupported types --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 23 +++++++++++++++---- .../pdo_sqlsrv/pdo_ae_insert_money.phpt | 3 ++- .../pdo_ae_insert_pdoparam_money.phpt | 3 ++- .../pdostatement_getColumnMeta.phpt | 9 ++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 5e0f0a76..efaad345 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -127,10 +127,11 @@ class ColumnMeta { public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5)) public $colName; //column name - public $encType; //randomized or deterministic; default is deterministic public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) ) + public $encType; //randomized or deterministic; default is deterministic + public $forceEncrypt; //force encryption on a datatype no supported by Column Encrypton - public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic") + public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic", $forceEncrypt = false) { if (is_null($colName)) { $this->colName = getDefaultColName($dataType); @@ -138,8 +139,9 @@ class ColumnMeta $this->colName = $colName; } $this->dataType = $dataType; - $this->encType = $encType; $this->options = $options; + $this->encType = $encType; + $this->forceEncrypt = $forceEncrypt; } /** * @return string column definition for creating a table @@ -150,7 +152,7 @@ class ColumnMeta $append = " "; // an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time - if (isColEncrypted() && stripos($this->options, "identity") === false) { + if (isColEncrypted() && $this->isEncryptableType() && stripos($this->options, "identity") === false) { $cekName = getCekName(); if (stripos($this->dataType, "char") !== false) { $append .= "COLLATE Latin1_General_BIN2 "; @@ -161,6 +163,19 @@ class ColumnMeta $colDef = "[" . $this->colName . "] " . $this->dataType . $append; return $colDef; } + + /** + * @return bool if the datatype for this column is encryptable + */ + public function isEncryptableType() + { + $unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant"); + if (in_array(strtolower($this->dataType), $unsupportedTypes) && !$this->forceEncrypt) { + return false; + } else { + return true; + } + } } diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt index 1cc76fd3..d11cf6b6 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt @@ -17,7 +17,8 @@ try { // create table $tbname = getTableName(); - $colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized")); + $colMetaArr = array(new columnMeta($dataType, "c_det", null, "deterministic", true), + new columnMeta($dataType, "c_rand", null, "randomized", true)); createTable($conn, $tbname, $colMetaArr); // insert a row diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt index abdf5159..563b0b90 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt @@ -17,7 +17,8 @@ try { // create table $tbname = getTableName(); - $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); + $colMetaArr = array(new ColumnMeta($dataType, "c_det", null, "deterministic", true), + new ColumnMeta($dataType, "c_rand", null, "randomized", true)); createTable($conn, $tbname, $colMetaArr); // test each PDO::PARAM_ type diff --git a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt index 419f5a98..f42d1d3d 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt @@ -43,13 +43,8 @@ function fetchBoth($conn, $tbname) // 8 $meta = $stmt->getColumnMeta(7); - if (isColEncrypted()) { - $xmlType = "nvarchar"; - } else { - $xmlType = "xml"; - } - if ($meta["sqlsrv:decl_type"] != $xmlType) { - echo "Wrong column metadata was retrieved for a $xmlType column.\n"; + if ($meta["sqlsrv:decl_type"] != "xml") { + echo "Wrong column metadata was retrieved for a xml column.\n"; } unset($meta["sqlsrv:decl_type"]); var_dump($meta);