From 1e69c86d69ec5e265ef9d4288fd17244f9c467ce Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Mon, 6 Nov 2017 17:30:11 -0800 Subject: [PATCH] add refactored ae related tests --- .../pdo_sqlsrv/pdo_ae_insert_datetime.phpt | 46 +++-- .../pdo_sqlsrv/pdo_ae_insert_money.phpt | 79 ++++----- .../pdo_sqlsrv/pdo_ae_insert_numeric.phpt | 51 +++--- .../pdo_ae_insert_pdoparam_datetime.phpt | 53 +++--- .../pdo_ae_insert_pdoparam_money.phpt | 87 ++++------ .../pdo_ae_insert_pdoparam_numeric.phpt | 54 +++--- .../pdo_ae_insert_pdoparam_string.phpt | 57 +++---- .../pdo_sqlsrv/pdo_ae_insert_retrieve.phpt | 77 ++++----- .../pdo_ae_insert_retrieve_fixed_size.phpt | 104 +++++------- .../pdo_ae_insert_retrieve_nvarchar.phpt | 79 ++++----- .../pdo_ae_insert_retrieve_varchar.phpt | 78 ++++----- .../pdo_sqlsrv/pdo_ae_insert_string.phpt | 51 +++--- .../pdo_sqlsrv/pdo_ae_output_param_all.phpt | 157 +++++++++--------- 13 files changed, 411 insertions(+), 562 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt index f81cf8a8..dbff0f59 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt @@ -3,44 +3,40 @@ Test for inserting and retrieving encrypted data of datetime types --DESCRIPTION-- No PDO::PARAM_ type specified when binding parameters --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - if ( $r === false ) { - is_incompatible_types_error( $stmt, $dataType, "default type" ); - } - else { + $stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, "default type"); + } else { echo "****Encrypted default type is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt index e778290c..1cc76fd3 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt @@ -3,77 +3,60 @@ Test for inserting and retrieving encrypted data of money types --DESCRIPTION-- No PDO::PARAM_ tpe specified when binding parameters --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); - - foreach ( $dataTypes as $dataType ) { +require_once("MsCommon_mid-refactor.inc"); +require_once("AEData.inc"); +$dataTypes = array("smallmoney", "money"); +try { + $conn = connect('', array(), PDO::ERRMODE_SILENT); + foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; $success = true; - + // create table - $tbname = GetTempTableName( "", false ); - $colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" )); - create_table( $conn, $tbname, $colMetaArr ); - + $tbname = getTableName(); + $colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized")); + createTable($conn, $tbname, $colMetaArr); + // insert a row - $inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 ); + $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - - if ( !is_col_enc() ) - { - if ( $r === false ) - { + $stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + + if (!isColEncrypted()) { + if ($r === false) { echo "Default type should be compatible with $dataType.\n"; $success = false; - } - else - { + } else { $sql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $sql ); - $row = $stmt->fetch( PDO::FETCH_ASSOC ); - if ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] ) - { + $stmt = $conn->query($sql); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + if ($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) { echo "Incorrect output retrieved for datatype $dataType.\n"; $success = false; } } - } - else - { - if ( $r === false ) - { - if ( $stmt->errorInfo()[0] != "22018" ) - { + } else { + if ($r === false) { + if ($stmt->errorInfo()[0] != "22018") { echo "Incorrect error returned.\n"; $success = false; } - } - else - { + } else { echo "$dataType is not compatible with any type.\n"; $success = false; } } - if ( $success ) + if ($success) { echo "Test successfully done.\n"; - DropTable( $conn, $tbname ); + } + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt index 753d59b0..7d5627a2 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt @@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of numeric types --DESCRIPTION-- No PDO::PARAM_ tpe specified when binding parameters --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - if ( $r === false ) { - is_incompatible_types_error( $stmt, $dataType, "default type" ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, "default type"); + } else { echo "****Encrypted default type is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt index c6b3523c..df3fbfc5 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt @@ -3,49 +3,42 @@ Test for inserting and retrieving encrypted data of datetime types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - if ( $r === false ) - { - is_incompatible_types_error( $stmt, $dataType, $pdoParamType ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, $pdoParamType); + } else { echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> 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 9a8b2412..abdf5159 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt @@ -3,84 +3,67 @@ Test for inserting and retrieving encrypted data of money types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); - - foreach ( $dataTypes as $dataType ) { +try { + $conn = connect('', array(), PDO::ERRMODE_SILENT); + foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; $success = true; - + // create table - $tbname = GetTempTableName( "", false ); - $colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" )); - create_table( $conn, $tbname, $colMetaArr ); - + $tbname = getTableName(); + $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); + createTable($conn, $tbname, $colMetaArr); + // test each PDO::PARAM_ type - foreach ( $pdoParamTypes as $pdoParamType ) { + foreach ($pdoParamTypes as $pdoParamType) { // insert a row - $inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 ); + $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - - - if ( !is_col_enc() ) - { - if ( $r === false ) - { + $stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + + + if (!isColEncrypted()) { + if ($r === false) { echo "$pdoParamType should be compatible with $dataType.\n"; $success = false; - } - else - { + } else { $sql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $sql ); - $row = $stmt->fetch( PDO::FETCH_ASSOC ); - if ( ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] ) && $pdoParamType != "PDO::PARAM_NULL" ) - { + $stmt = $conn->query($sql); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + if (($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) && $pdoParamType != "PDO::PARAM_NULL") { echo "Incorrect output retrieved for datatype $dataType.\n"; - var_dump( $inputValues ); - var_dump( $row ); + var_dump($inputValues); + var_dump($row); $success = false; } } - } - else - { - if ( $r === false ) - { - if ( $stmt->errorInfo()[0] != "22018" ) - { + } else { + if ($r === false) { + if ($stmt->errorInfo()[0] != "22018") { echo "Incorrect error returned.\n"; $success = false; } - } - else - { + } else { echo "$dataType is not compatible with any type.\n"; $success = false; } } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - if ( $success ) + if ($success) { echo "Test successfully done.\n"; - DropTable( $conn, $tbname ); + } + DropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt index c40e2aeb..6cfd7f81 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt @@ -3,49 +3,41 @@ Test for inserting and retrieving encrypted data of numeric types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - if ( $r === false ) - { - is_incompatible_types_error( $stmt, $dataType, $pdoParamType ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, $pdoParamType); + } else { echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt index 4b2b9c59..44ec7d0a 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt @@ -3,50 +3,41 @@ Test for inserting and retrieving encrypted data of string types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); - - foreach ( $dataTypes as $dataType ) { +require_once("MsCommon_mid-refactor.inc"); +require_once("AEData.inc"); +$dataTypes = array("char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)"); +try { + $conn = connect('', array(), PDO::ERRMODE_SILENT); + foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; - + // create table - $tbname = GetTempTableName( "", false ); - $colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" )); - create_table( $conn, $tbname, $colMetaArr ); - + $tbname = getTableName(); + $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); + createTable($conn, $tbname, $colMetaArr); + // prepare statement for inserting into table - foreach ( $pdoParamTypes as $pdoParamType ) { + foreach ($pdoParamTypes as $pdoParamType) { // insert a row - $inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 ); + $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - if ( $r === false ) - { - is_incompatible_types_error( $stmt, $dataType, $pdoParamType ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType),"c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, $pdoParamType); + } else { echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt index 7bba2212..4f464c9d 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt @@ -3,73 +3,60 @@ Test for inserting encrypted data and retrieving both encrypted and decrypted da --DESCRIPTION-- Retrieving SQL query contains encrypted filter --SKIPIF-- - + --FILE-- $SSN, "FirstName" => "Catherine", "LastName" => "Abel", "BirthDate" => "1996-10-19" ); - $stmt = insert_row( $conn, $tbname, $inputs ); - + $stmt = insertRow($conn, $tbname, $inputs); + echo "Retrieving plaintext data:\n"; $selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname WHERE SSN = ?"; - $stmt = $conn->prepare( $selectSql ); - $stmt->bindParam( 1, $SSN ); + $stmt = $conn->prepare($selectSql); + $stmt->bindParam(1, $SSN); $stmt->execute(); - $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ); - foreach ( $decrypted_row as $key => $value ) - { + $decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC); + foreach ($decrypted_row as $key => $value) { print "$key: $value\n"; } - unset( $stmt ); -} -catch( PDOException $e ) -{ + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only echo "\nChecking ciphertext data:\n"; -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); $selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname"; - $stmt = $conn1->query( $selectSql ); - $encrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ); - foreach ( $encrypted_row as $key => $value ) - { - if ( ctype_print( $value )) + $stmt = $conn1->query($selectSql); + $encrypted_row = $stmt->fetch(PDO::FETCH_ASSOC); + foreach ($encrypted_row as $key => $value) { + if (ctype_print($value)) { print "Error: expected a binary array for $key\n"; + } } - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - +dropTable($conn, $tbname); +unset($conn); echo "Done\n"; ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt index ca76ba2f..6990e3dd 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt @@ -1,80 +1,64 @@ --TEST-- Test for inserting encrypted fixed size types data and retrieve both encrypted and decrypted data --SKIPIF-- - + --FILE-- 255, - "SmallIntData" => 32767, - "IntData" => 2147483647, - "BigIntData" => 92233720368547, - "DecimalData" => 79228162514264, - "BitData" => true, - "DateTimeData" => '9999-12-31 23:59:59.997', - "DateTime2Data" => '9999-12-31 23:59:59.9999999'); - $paramOptions = array( new bindParamOption( 4, "PDO::PARAM_INT" ) ); - $r; - $stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions ); - - print "Decrypted values:\n"; - fetch_all( $conn, $tbname ); + $colMetaArr = array("TinyIntData" => "tinyint", + "SmallIntData" => "smallint", + "IntData" => "int", + "BigIntData" => "bigint", + "DecimalData" => "decimal(18,0)", + "BitData" => "bit", + "DateTimeData" => "datetime", + "DateTime2Data" => "datetime2"); + createTable($conn, $tbname, $colMetaArr); - unset( $stmt ); -} -catch( PDOException $e ) -{ + // insert a row + $inputs = array( "TinyIntData" => 255, + "SmallIntData" => 32767, + "IntData" => 2147483647, + "BigIntData" => 92233720368547, + "DecimalData" => 79228162514264, + "BitData" => true, + "DateTimeData" => '9999-12-31 23:59:59.997', + "DateTime2Data" => '9999-12-31 23:59:59.9999999'); + //$paramOptions = array( new bindParamOption(4, "PDO::PARAM_INT") ); + $r; + $stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r); + + print "Decrypted values:\n"; + fetchAll($conn, $tbname); + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); - +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); + $selectSql = "SELECT * FROM $tbname"; - $stmt = $conn1->query( $selectSql ); - $encrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ); - foreach ( $encrypted_row as $key => $value ) - { - if ( ctype_print( $value )) - { + $stmt = $conn1->query($selectSql); + $encrypted_row = $stmt->fetch(PDO::FETCH_ASSOC); + foreach ($encrypted_row as $key => $value) { + if (ctype_print($value)) { print "Error: expected a binary array for $key\n"; } } - - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - +dropTable($conn, $tbname); +unset($conn); echo "Done\n"; ?> --EXPECT-- @@ -87,4 +71,4 @@ DecimalData: 79228162514264 BitData: 1 DateTimeData: 9999-12-31 23:59:59.997 DateTime2Data: 9999-12-31 23:59:59.9999999 -Done \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt index bd2dab8f..92f03f88 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt @@ -1,79 +1,60 @@ --TEST-- Test for inserting encrypted nvarchar data of variable lengths and retrieving encrypted and decrypted data --SKIPIF-- - + --FILE-- $data ) ); + for ($i = 0; $i < 1000; $i++) { + $data = str_repeat("*", $i); + $stmt = insertRow($conn, $tbname, array(getDefaultColName("nvarchar(1000)") => $data)); } - + $selectSql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] )) - { - $rowInd = $decrypted_row[ 'CharCount' ] + 1; + $stmt = $conn->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) { + $rowInd = $decrypted_row['CharCount'] + 1; echo "Failed to decrypted at row $rowInd\n"; $testPass = false; } } - unset( $stmt ); -} -catch( PDOException $e ) -{ + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); - $stmt = $conn1->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] )) - { +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); + $stmt = $conn1->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row[ 'CharCount' ] == strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) { $rowInd = $decrypted_row[ 'CharCount' ] + 1; echo "Failed to encrypted at row $rowInd\n"; $testPass = false; } } - - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - -if ( $testPass ) { +dropTable($conn, $tbname); +unset($conn); +if ($testPass) { echo "Test successfully done.\n"; } - ?> --EXPECT-- -Test successfully done. \ No newline at end of file +Test successfully done. diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt index 3b5218c1..f30de5cf 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt @@ -1,78 +1,60 @@ --TEST-- Test for inserting encrypted varchar data of variable lengths and retrieving encrypted and decrypted data --SKIPIF-- - + --FILE-- $data ) ); + for ($i = 0; $i < 1000; $i++) { + $data = str_repeat("*", $i); + $stmt = insertRow($conn, $tbname, array(getDefaultColname("varchar(1000)") => $data)); } - + $selectSql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] )) - { - $rowInd = $decrypted_row[ 'CharCount' ] + 1; + $stmt = $conn->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColname("varchar(1000)")])) { + $rowInd = $decrypted_row['CharCount'] + 1; echo "Failed to decrypted at row $rowInd\n"; $testPass = false; } } - unset( $stmt ); -} -catch( PDOException $e ) -{ + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); - $stmt = $conn1->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] )) - { +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); + $stmt = $conn1->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row['CharCount'] == strlen($decrypted_row[getDefaultColname("varchar(1000)")])) { $rowInd = $decrypted_row[ 'CharCount' ] + 1; echo "Failed to encrypted at row $rowInd\n"; $testPass = false; } } - - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - -if ( $testPass ) { +dropTable($conn, $tbname); +unset($conn); +if ($testPass) { echo "Test successfully done.\n"; } ?> --EXPECT-- -Test successfully done. \ No newline at end of file +Test successfully done. diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt index 4ef6b026..e9f295bc 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt @@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of string types --DESCRIPTION-- No PDO::PARAM_ type specified when binding parameters --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - if ( $r === false ) { - is_incompatible_types_error( $stmt, $dataType, "default type" ); - } - else { + $stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, "default type"); + } else { echo "****Encrypted default type is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt b/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt index b870d957..6becaf4d 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt @@ -1,84 +1,78 @@ --TEST-- Test for binding output params for encrypted data for all types --SKIPIF-- - + --FILE-- "int", + "c2_smallint" => "smallint", + "c3_tinyint" => "tinyint", + "c4_bit" => "bit", + "c5_bigint" => "bigint", + "c6_decimal" => "decimal(18,5)", + "c7_numeric" => "numeric(10,5)", + "c8_float" => "float", + "c9_real" => "real", + "c10_date" => "date", + "c11_datetime" => "datetime", + "c12_datetime2" => "datetime2", + "c13_datetimeoffset" => "datetimeoffset", + "c14_time" => "time", + "c15_char" => "char(5)", + "c16_varchar" => "varchar(max)", + "c17_nchar" => "nchar(5)", + "c18_nvarchar" => "nvarchar(max)"); +createTable($conn, $tbname, $colMetaArr); // Create a Store Procedure $spname = 'selectAllColumns'; $spSql = "CREATE PROCEDURE $spname ( - @c1_int int OUTPUT, @c2_smallint smallint OUTPUT, - @c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT, + @c1_int int OUTPUT, @c2_smallint smallint OUTPUT, + @c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT, @c5_bigint bigint OUTPUT, @c6_decimal decimal(18,5) OUTPUT, - @c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT, + @c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT, @c9_real real OUTPUT, @c10_date date OUTPUT, @c11_datetime datetime OUTPUT, @c12_datetime2 datetime2 OUTPUT, @c13_datetimeoffset datetimeoffset OUTPUT, @c14_time time OUTPUT, @c15_char char(5) OUTPUT, @c16_varchar varchar(max) OUTPUT, @c17_nchar nchar(5) OUTPUT, @c18_nvarchar nvarchar(max) OUTPUT) AS - SELECT @c1_int = c1_int, @c2_smallint = c2_smallint, - @c3_tinyint = c3_tinyint, @c4_bit = c4_bit, - @c5_bigint = c5_bigint, @c6_decimal = c6_decimal, - @c7_numeric = c7_numeric, @c8_float = c8_float, - @c9_real = c9_real, @c10_date = c10_date, + SELECT @c1_int = c1_int, @c2_smallint = c2_smallint, + @c3_tinyint = c3_tinyint, @c4_bit = c4_bit, + @c5_bigint = c5_bigint, @c6_decimal = c6_decimal, + @c7_numeric = c7_numeric, @c8_float = c8_float, + @c9_real = c9_real, @c10_date = c10_date, @c11_datetime = c11_datetime, @c12_datetime2 = c12_datetime2, @c13_datetimeoffset = c13_datetimeoffset, @c14_time = c14_time, @c15_char = c15_char, @c16_varchar = c16_varchar, @c17_nchar = c17_nchar, @c18_nvarchar = c18_nvarchar FROM $tbname"; -$conn->query( $spSql ); - +$conn->query($spSql); // Insert data -$inputs = array( "c1_int" => 2147483647, - "c2_smallint" => 32767, - "c3_tinyint" => 255, - "c4_bit" => 1, - "c5_bigint" => 922337203685479936, - "c6_decimal" => 9223372036854.80000, - "c7_numeric" => 21474.83647, +$inputs = array( "c1_int" => 2147483647, + "c2_smallint" => 32767, + "c3_tinyint" => 255, + "c4_bit" => 1, + "c5_bigint" => 922337203685479936, + "c6_decimal" => 9223372036854.80000, + "c7_numeric" => 21474.83647, "c8_float" => 9223372036.8548, - "c9_real" => 2147.483, - "c10_date" => '9999-12-31', - "c11_datetime" => '9999-12-31 23:59:59.997', - "c12_datetime2" => '9999-12-31 23:59:59.9999999', - "c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00', - "c14_time" => '23:59:59.9999999', - "c15_char" => 'th, n', - "c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.', - "c17_nchar" => 'th Un', + "c9_real" => 2147.483, + "c10_date" => '9999-12-31', + "c11_datetime" => '9999-12-31 23:59:59.997', + "c12_datetime2" => '9999-12-31 23:59:59.9999999', + "c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00', + "c14_time" => '23:59:59.9999999', + "c15_char" => 'th, n', + "c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.', + "c17_nchar" => 'th Un', "c18_nvarchar" => 'When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).' ); -$paramOptions = array( new bindParamOption( 5, "PDO::PARAM_INT" ) ); $r; -$stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions ); - +$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r); // Call store procedure -$outSql = get_callProcSql_placeholders( $spname, count( $inputs )); +$outSql = getCallProcSqlPlaceholders($spname, count($inputs)); $intOut = 0; $smallintOut = 0; $tinyintOut = 0; @@ -97,7 +91,7 @@ $charOut = ''; $varcharOut = ''; $ncharOut = ''; $nvarcharOut = ''; -$stmt = $conn->prepare( $outSql ); +$stmt = $conn->prepare($outSql); $stmt->bindParam(1, $intOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); $stmt->bindParam(2, $smallintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); $stmt->bindParam(3, $tinyintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); @@ -117,31 +111,28 @@ $stmt->bindParam(16, $varcharOut, PDO::PARAM_STR, 2048); $stmt->bindParam(17, $ncharOut, PDO::PARAM_STR, 2048); $stmt->bindParam(18, $nvarcharOut, PDO::PARAM_STR, 2048); $stmt->execute(); - -print ( "intOut: " . $intOut . "\n" ); -print ( "smallintOut: " . $smallintOut . "\n" ); -print ( "tinyintOut: " . $tinyintOut . "\n" ); -print ( "bitOut: " . $bitOut . "\n" ); -print ( "bigintOut: " . $bigintOut . "\n" ); -print ( "decimalOut: " . $decimalOut . "\n" ); -print ( "numericOut: " . $numericOut . "\n" ); -print ( "floatOut: " . $floatOut . "\n" ); -print ( "realOut: " . $realOut . "\n" ); -print ( "dateOut: " . $dateOut . "\n" ); -print ( "datetimeOut: " . $datetimeOut . "\n" ); -print ( "datetime2Out: " . $datetime2Out . "\n" ); -print ( "datetimeoffsetOut: " . $datetimeoffsetOut . "\n" ); -print ( "timeOut: " . $timeOut . "\n" ); -print ( "charOut: " . $charOut . "\n" ); -print ( "varcharOut: " . $varcharOut . "\n" ); -print ( "ncharOut: " . $ncharOut . "\n" ); -print ( "nvarcharOut: " . $nvarcharOut . "\n" ); - -$conn->query( "DROP PROCEDURE $spname" ); -$conn->query( "DROP TABLE $tbname" ); -unset( $stmt ); -unset( $conn ); - +print("intOut: " . $intOut . "\n"); +print("smallintOut: " . $smallintOut . "\n"); +print("tinyintOut: " . $tinyintOut . "\n"); +print("bitOut: " . $bitOut . "\n"); +print("bigintOut: " . $bigintOut . "\n"); +print("decimalOut: " . $decimalOut . "\n"); +print("numericOut: " . $numericOut . "\n"); +print("floatOut: " . $floatOut . "\n"); +print("realOut: " . $realOut . "\n"); +print("dateOut: " . $dateOut . "\n"); +print("datetimeOut: " . $datetimeOut . "\n"); +print("datetime2Out: " . $datetime2Out . "\n"); +print("datetimeoffsetOut: " . $datetimeoffsetOut . "\n"); +print("timeOut: " . $timeOut . "\n"); +print("charOut: " . $charOut . "\n"); +print("varcharOut: " . $varcharOut . "\n"); +print("ncharOut: " . $ncharOut . "\n"); +print("nvarcharOut: " . $nvarcharOut . "\n"); +dropProc($conn, $spname); +dropTable($conn, $tbname); +unset($stmt); +unset($conn); ?> --EXPECTREGEX-- intOut: 2147483647 @@ -161,4 +152,4 @@ timeOut: 23:59:59\.9999999 charOut: th\, n varcharOut: This large row size can cause errors \(such as error 512\) during some normal operations\, such as a clustered index key update\, or sorts of the full column set\, which users cannot anticipate until performing an operation\. ncharOut: th Un -nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\). \ No newline at end of file +nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\).