add refactored ae related tests

This commit is contained in:
v-kaywon 2017-11-06 17:30:11 -08:00
parent e09dd9163d
commit 1e69c86d69
13 changed files with 411 additions and 562 deletions

View file

@ -3,44 +3,40 @@ Test for inserting and retrieving encrypted data of datetime types
--DESCRIPTION--
No PDO::PARAM_ type specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
try
{
$conn = ae_connect();
try {
$conn = connect();
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);
// insert a row
$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 );
$stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ($r === false) {
is_incompatible_types_error( $stmt, $dataType, "default type" );
}
else {
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,77 +3,60 @@ Test for inserting and retrieving encrypted data of money types
--DESCRIPTION--
No PDO::PARAM_ tpe specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("smallmoney", "money");
try
{
$conn = ae_connect();
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
try {
$conn = connect('', array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$tbname = getTableName();
$colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized"));
create_table( $conn, $tbname, $colMetaArr );
createTable($conn, $tbname, $colMetaArr);
// insert a row
$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 );
$stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ( !is_col_enc() )
{
if ( $r === false )
{
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] )
{
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of numeric types
--DESCRIPTION--
No PDO::PARAM_ tpe specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real");
try
{
$conn = ae_connect();
try {
$conn = connect();
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);
// insert a row
$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 );
$stmt = insertRow($conn, $tbname, array( "c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ($r === false) {
is_incompatible_types_error( $stmt, $dataType, "default type" );
}
else {
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,49 +3,42 @@ Test for inserting and retrieving encrypted data of datetime types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
try
{
$conn = ae_connect();
try {
$conn = connect();
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) {
// insert a row
$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");
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset($stmt);
unset($conn);
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,84 +3,67 @@ Test for inserting and retrieving encrypted data of money types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "smallmoney", "money" );
try
{
$conn = ae_connect();
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
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) {
// insert a row
$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 )));
$stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ( !is_col_enc() )
{
if ( $r === false )
{
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" )
{
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);
$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");
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
}
DropTable($conn, $tbname);
}
unset($stmt);
unset($conn);
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,49 +3,41 @@ Test for inserting and retrieving encrypted data of numeric types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "bit", "tinyint", "smallint", "int", "decimal(18,5)", "numeric(10,5)", "float", "real" );
try
{
$conn = ae_connect();
try {
$conn = connect();
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);
// test each PDO::PARAM_ type
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$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");
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset($stmt);
unset($conn);
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,50 +3,41 @@ Test for inserting and retrieving encrypted data of string types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)");
try
{
$conn = ae_connect();
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
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) {
// insert a row
$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");
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset($stmt);
unset($conn);
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,15 +3,12 @@ Test for inserting encrypted data and retrieving both encrypted and decrypted da
--DESCRIPTION--
Retrieving SQL query contains encrypted filter
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
try
{
$conn = ae_connect();
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect();
// Create the table
$tbname = 'Patients';
$colMetaArr = array( new columnMeta("int", "PatientId", "IDENTITY(1,1)"),
@ -19,12 +16,12 @@ try
new columnMeta("nvarchar(50)", "FirstName", "NULL"),
new columnMeta("nvarchar(50)", "LastName", "NULL"),
new columnMeta("date", "BirthDate", null, "randomized"));
create_table( $conn, $tbname, $colMetaArr );
createTable($conn, $tbname, $colMetaArr);
// insert a row
$SSN = "795-73-9838";
$inputs = array( "SSN" => $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 = ?";
@ -32,44 +29,34 @@ try
$stmt->bindParam(1, $SSN);
$stmt->execute();
$decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC);
foreach ( $decrypted_row as $key => $value )
{
foreach ($decrypted_row as $key => $value) {
print "$key: $value\n";
}
unset($stmt);
}
catch( PDOException $e )
{
} 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 ))
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
unset($conn);
echo "Done\n";
?>
--EXPECT--

View file

@ -1,26 +1,23 @@
--TEST--
Test for inserting encrypted fixed size types data and retrieve both encrypted and decrypted data
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
try
{
$conn = ae_connect();
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect();
// Create the table
$tbname = 'FixedSizeAnalysis';
$colMetaArr = array( new columnMeta( "tinyint", "TinyIntData" ),
new columnMeta( "smallint", "SmallIntData" ),
new columnMeta( "int", "IntData" ),
new columnMeta( "bigint", "BigIntData" ),
new columnMeta( "decimal(38,0)", "DecimalData" ),
new columnMeta( "bit", "BitData" ),
new columnMeta( "datetime", "DateTimeData" ),
new columnMeta( "datetime2", "DateTime2Data" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array("TinyIntData" => "tinyint",
"SmallIntData" => "smallint",
"IntData" => "int",
"BigIntData" => "bigint",
"DecimalData" => "decimal(18,0)",
"BitData" => "bit",
"DateTimeData" => "datetime",
"DateTime2Data" => "datetime2");
createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputs = array( "TinyIntData" => 255,
@ -31,50 +28,37 @@ try
"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" ) );
//$paramOptions = array( new bindParamOption(4, "PDO::PARAM_INT") );
$r;
$stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions );
$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r);
print "Decrypted values:\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
unset($stmt);
}
catch( PDOException $e )
{
} 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 ))
{
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
unset($conn);
echo "Done\n";
?>
--EXPECT--

View file

@ -1,79 +1,60 @@
--TEST--
Test for inserting encrypted nvarchar data of variable lengths and retrieving encrypted and decrypted data
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
$testPass = true;
try
{
$conn = ae_connect();
try {
$conn = connect();
// Create the table
$tbname = 'NVarcharAnalysis';
$colMetaArr = array( new columnMeta( "int", "CharCount", "IDENTITY(0,1)" ), new columnMeta( "nvarchar(1000)" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new columnMeta("nvarchar(1000)"));
createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
for ( $i = 0; $i < 1000; $i++ )
{
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = insert_row( $conn, $tbname, array( get_default_colname( "nvarchar(1000)" ) => $data ) );
$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)" ) ] ))
{
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 )
{
} 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);
$stmt = $conn1->query($selectSql);
while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] ))
{
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
unset($conn);
if ($testPass) {
echo "Test successfully done.\n";
}
?>
--EXPECT--
Test successfully done.

View file

@ -1,75 +1,57 @@
--TEST--
Test for inserting encrypted varchar data of variable lengths and retrieving encrypted and decrypted data
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
$testPass = true;
try
{
$conn = ae_connect();
try {
$conn = connect();
// Create the table
$tbname = 'VarcharAnalysis';
$colMetaArr = array( new columnMeta( "int", "CharCount", "IDENTITY(0,1)" ), new columnMeta( "varchar(1000)" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new ColumnMeta("varchar(1000)"));
createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
for( $i = 0; $i < 1000; $i++ )
{
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = insert_row( $conn, $tbname, array( get_default_colname( "varchar(1000)" ) => $data ) );
$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)" ) ] ))
{
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 )
{
} 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);
$stmt = $conn1->query($selectSql);
while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] ))
{
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
unset($conn);
if ($testPass) {
echo "Test successfully done.\n";
}

View file

@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of string types
--DESCRIPTION--
No PDO::PARAM_ type specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)");
try
{
$conn = ae_connect();
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$tbname = getTableName();
$colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized"));
create_table( $conn, $tbname, $colMetaArr );
createTable($conn, $tbname, $colMetaArr);
// insert a row
$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 );
$stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ($r === false) {
is_incompatible_types_error( $stmt, $dataType, "default type" );
}
else {
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 )
{
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -1,35 +1,32 @@
--TEST--
Test for binding output params for encrypted data for all types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
$conn = ae_connect();
require_once("MsCommon_mid-refactor.inc");
$conn = connect();
// Create the table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( "int", "c1_int" ),
new columnMeta( "smallint", "c2_smallint" ),
new columnMeta( "tinyint", "c3_tinyint" ),
new columnMeta( "bit", "c4_bit" ),
new columnMeta( "bigint", "c5_bigint" ),
new columnMeta( "decimal(18,5)", "c6_decimal" ),
new columnMeta( "numeric(10,5)", "c7_numeric" ),
new columnMeta( "float", "c8_float" ),
new columnMeta( "real", "c9_real" ),
new columnMeta( "date", "c10_date" ),
new columnMeta( "datetime", "c11_datetime" ),
new columnMeta( "datetime2", "c12_datetime2" ),
new columnMeta( "datetimeoffset", "c13_datetimeoffset" ),
new columnMeta( "time", "c14_time" ),
new columnMeta( "char(5)", "c15_char" ),
new columnMeta( "varchar(max)", "c16_varchar" ),
new columnMeta( "nchar(5)", "c17_nchar" ),
new columnMeta( "nvarchar(max)", "c18_nvarchar" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array("c1_int" => "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 (
@ -53,7 +50,6 @@ $spSql = "CREATE PROCEDURE $spname (
@c17_nchar = c17_nchar, @c18_nvarchar = c18_nvarchar
FROM $tbname";
$conn->query($spSql);
// Insert data
$inputs = array( "c1_int" => 2147483647,
"c2_smallint" => 32767,
@ -73,12 +69,10 @@ $inputs = array( "c1_int" => 2147483647,
"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;
@ -117,7 +111,6 @@ $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");
@ -136,12 +129,10 @@ 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" );
dropProc($conn, $spname);
dropTable($conn, $tbname);
unset($stmt);
unset($conn);
?>
--EXPECTREGEX--
intOut: 2147483647