Modified files as per review comments

This commit is contained in:
Jenny Tam 2017-11-09 09:29:13 -08:00
parent 41eec918c9
commit 1daa4f0623
8 changed files with 115 additions and 134 deletions

View file

@ -31,7 +31,7 @@ this test is very similar to test_scrollable.phpt... might consider removing thi
$options = array('Scrollable' => 'static');
}
$stmt = AE\executeQueryEx($conn, $query, $options);
$stmt = sqlsrv_query($conn, $query, array(), $options);
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");
@ -46,7 +46,7 @@ this test is very similar to test_scrollable.phpt... might consider removing thi
print_r(sqlsrv_errors(), true);
}
$stmt = AE\selectFromTable($conn, $tableName);
$stmt = sqlsrv_query($conn, $query);
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");

View file

@ -224,12 +224,14 @@ function getKSPpath()
$ksp = $dir_name . DIRECTORY_SEPARATOR . $name;
if (strtoupper(substr(php_uname('s'), 0, 3)) == 'WIN') {
$arch = 'x64';
if ( PHP_INT_SIZE == 4 ) // running 32 bit
if (PHP_INT_SIZE == 4) {
// running 32 bit
$arch = '';
$ksp .= $arch . '.dll';
}
else
$ksp .= $arch . '.dll';
} else {
$ksp .= '.so';
}
return $ksp;
}
@ -507,10 +509,11 @@ function executeQuery($conn, $sql, $conds = null, $values = null, $options = nul
} else {
// with AE enabled, use sqlsrv_prepare() in case there are
// fields with unlimited size
if (empty($conds) || empty($values)) {
if (empty($conds)) {
$stmt = sqlsrv_prepare($conn, $sql, null, $options);
} else {
$sql = $sql . " WHERE $conds ";
// pass $values to sqlsrv_prepare whether the array is null, empty or filled
$stmt = sqlsrv_prepare($conn, $sql, $values, $options);
}
if ($stmt) {

View file

@ -31,20 +31,20 @@ Connect using a custom keystore provider with some required inputs missing
$ksp_name = AE\KSP_NAME;
$encrypt_key = AE\ENCRYPT_KEY;
echo("Connecting... with column encryption\n");
echo "Connecting... with column encryption\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled");
connect($server, $connectionInfo);
echo("Connecting... with an invalid input to CEKeystoreProvider\n");
echo "Connecting... with an invalid input to CEKeystoreProvider\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled",
"CEKeystoreProvider"=>1);
connect($server, $connectionInfo);
echo("Connecting... with an empty path\n");
echo "Connecting... with an empty path\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled",
"CEKeystoreProvider"=>"",
@ -53,7 +53,7 @@ Connect using a custom keystore provider with some required inputs missing
connect($server, $connectionInfo);
echo("Connecting... without a name\n");
echo "Connecting... without a name\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled",
"CEKeystoreProvider"=>$ksp_path,
@ -61,7 +61,7 @@ Connect using a custom keystore provider with some required inputs missing
connect($server, $connectionInfo);
echo("Connecting... with an empty name\n");
echo "Connecting... with an empty name\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled",
"CEKeystoreProvider"=>$ksp_path,
@ -70,7 +70,7 @@ Connect using a custom keystore provider with some required inputs missing
connect($server, $connectionInfo);
echo("Connecting... without a key\n");
echo "Connecting... without a key\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled",
"CEKeystoreProvider"=>$ksp_path,
@ -78,7 +78,7 @@ Connect using a custom keystore provider with some required inputs missing
connect($server, $connectionInfo);
echo("Connecting... with all required inputs\n");
echo "Connecting... with all required inputs\n";
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ColumnEncryption"=>"enabled",
"CEKeystoreProvider"=>$ksp_path,

View file

@ -4,7 +4,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
<?php require('skipif_not_ksp.inc'); ?>
--FILE--
<?php
function CreatePatientsTable()
function createPatientsTable()
{
global $conn;
$tableName = 'Patients';
@ -88,7 +88,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
echo "Connected successfully with ColumnEncryption enabled.\n";
}
$tableName = CreatePatientsTable();
$tableName = createPatientsTable();
insertData('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
insertData('795-73-9838', 'John', 'Doe', '2001-05-29');
@ -103,7 +103,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
array('Chang', null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
array('456-12-5486', null, null, SQLSRV_SQLTYPE_CHAR(11)));
$tsql = "UPDATE Patients SET BirthDate = ?, LastName = ? WHERE SSN = ?";
$tsql = "UPDATE $tableName SET BirthDate = ?, LastName = ? WHERE SSN = ?";
$stmt = sqlsrv_query($conn, $tsql, $params);
if (!$stmt) {
@ -112,7 +112,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
echo "Update his birthdate too...\n";
$params = array(array('456-12-5486', null, null, SQLSRV_SQLTYPE_CHAR(11)));
$tsql = "SELECT SSN, FirstName, LastName, BirthDate FROM Patients WHERE SSN = ?";
$tsql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tableName WHERE SSN = ?";
$stmt = sqlsrv_query($conn, $tsql, $params);
if (!$stmt) {
fatalError("Failed to select with a WHERE clause\n");
@ -128,7 +128,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
///////////////////////////////////////////
$procName = '#phpAEProc1';
$spArgs = "@p1 INT, @p2 DATE OUTPUT";
$spCode = "SET @p2 = (SELECT [BirthDate] FROM Patients WHERE [PatientId] = @p1)";
$spCode = "SET @p2 = (SELECT [BirthDate] FROM $tableName WHERE [PatientId] = @p1)";
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
sqlsrv_free_stmt($stmt);
@ -147,7 +147,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
///////////////////////////////////////////
$procName = '#phpAEProc2';
$spArgs = "@p1 INT, @p2 CHAR(11) OUTPUT";
$spCode = "SET @p2 = (SELECT [SSN] FROM Patients WHERE [PatientId] = @p1)";
$spCode = "SET @p2 = (SELECT [SSN] FROM $tableName WHERE [PatientId] = @p1)";
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
sqlsrv_free_stmt($stmt);

View file

@ -1,42 +1,33 @@
--TEST--
Test using sqlserv_query for binding parameters with ColumnEncryption enabled and a custome keystore provider
Test using sqlsrv_query for binding parameters with column encryption and a custom keystore provider
--SKIPIF--
<?php require('skipif_not_ksp.inc'); ?>
--FILE--
<?php
function CreatePatientsTable()
function createPatientsTable()
{
global $conn;
$tablename = 'Patients';
$tableName = 'Patients';
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('$tablename', 'U') IS NOT NULL DROP TABLE $tablename" );
sqlsrv_free_stmt( $stmt );
$tsql = "CREATE TABLE $tablename (
[PatientId] [int] IDENTITY(1,1) NOT NULL,
[SSN] [char](11) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL,
[FirstName] [nvarchar](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL,
[LastName] [nvarchar](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL,
[BirthDate] [date] ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Randomized, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL)";
$stmt = sqlsrv_query( $conn, $tsql );
if (! $stmt )
{
echo "Failed to create test table!\n";
die( print_r( sqlsrv_errors(), true ));
$columns = array(new AE\ColumnMeta('int', 'PatientId', 'IDENTITY(1,1) NOT NULL'),
new AE\ColumnMeta('char(11)', 'SSN'),
new AE\ColumnMeta('nvarchar(50)', 'FirstName'),
new AE\ColumnMeta('nvarchar(50)', 'LastName'),
new AE\ColumnMeta('date', 'BirthDate'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create test table!\n");
}
return $tableName;
}
return $tablename;
}
function SelectData()
function selectData()
{
global $conn, $tablename;
global $conn, $tableName;
$stmt = sqlsrv_query($conn, "SELECT * FROM $tablename");
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
while ($obj = sqlsrv_fetch_object( $stmt ))
{
while ($obj = sqlsrv_fetch_object($stmt)) {
echo $obj->PatientId . "\n";
echo $obj->SSN . "\n";
echo $obj->FirstName . "\n";
@ -45,11 +36,10 @@ Test using sqlserv_query for binding parameters with ColumnEncryption enabled an
}
}
function PrintError()
function printError()
{
$errors = sqlsrv_errors();
foreach ( $errors as $error )
{
foreach ($errors as $error) {
echo " SQLSTATE: " . $error['SQLSTATE'] . "\n";
echo " code: " . $error['code'] . "\n";
echo " message: " . $error['message'] . "\n\n";
@ -59,38 +49,27 @@ Test using sqlserv_query for binding parameters with ColumnEncryption enabled an
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once( 'MsSetup.inc' );
require_once( 'AE_Ksp.inc' );
require_once('MsHelper.inc');
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
$ksp_path = getKSPpath();
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"ReturnDatesAsStrings"=>true, "ColumnEncryption"=>'Enabled',
"CEKeystoreProvider"=>$ksp_path,
"CEKeystoreName"=>$ksp_name,
"CEKeystoreEncryptKey"=>$encrypt_key);
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
if ($conn === false) {
echo "Failed to connect.\n";
PrintError();
}
else
{
printError();
} else {
echo "Connected successfully with ColumnEncryption enabled.\n\n";
}
$tablename = CreatePatientsTable();
$tableName = createPatientsTable();
$tsql = "INSERT INTO $tablename (SSN, FirstName, LastName, BirthDate) VALUES (?, ?, ?, ?)";
$tsql = "INSERT INTO $tableName (SSN, FirstName, LastName, BirthDate) VALUES (?, ?, ?, ?)";
$inputs = array('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
// expects an error in Column Encryption enabled connection
print_r("Using sqlsrv_query and binding parameters with literal values:\n");
$stmt = sqlsrv_query($conn, $tsql, $inputs);
if ( !$stmt)
PrintError();
if (!$stmt) {
printError();
}
// expects an error in Column Encryption enabled connection
print_r("Using sqlsrv_query and binding parameters with parameter arrays and no sqltypes provided:\n");
@ -98,20 +77,19 @@ Test using sqlserv_query for binding parameters with ColumnEncryption enabled an
array($inputs[1], SQLSRV_PARAM_IN),
array($inputs[2], SQLSRV_PARAM_IN),
array($inputs[3], SQLSRV_PARAM_IN)));
if ( !$stmt)
PrintError();
if (!$stmt) {
printError();
}
// no error is expected
print_r("Using sqlsrv_query and binding parameters with parameter arrays and sqltypes provided:\n");
$stmt = sqlsrv_query($conn, $tsql, array(array($inputs[0], null, null, SQLSRV_SQLTYPE_CHAR(11)),
array($inputs[1], null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
array($inputs[2], null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
array($inputs[3], null, null, SQLSRV_SQLTYPE_DATE)));
if ( !$stmt)
PrintError();
SelectData();
if (!$stmt) {
printError();
}
selectData();
echo "Done\n";
?>