ColumnEncryption keyword reserved for Windows for now
This commit is contained in:
parent
db56c0344e
commit
bad65817e1
|
@ -1,160 +1,165 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test new connection keyword Driver with valid and invalid values
|
Test new connection keyword Driver with valid and invalid values
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require_once('MsSetup.inc');
|
require_once('MsSetup.inc');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$conn = new PDO("sqlsrv:server = $server", $uid, $pwd);
|
$conn = new PDO("sqlsrv:server = $server", $uid, $pwd);
|
||||||
$msodbcsqlVer = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)['DriverVer'];
|
$msodbcsqlVer = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)['DriverVer'];
|
||||||
$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0];
|
$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0];
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
echo "Failed to connect\n";
|
echo "Failed to connect\n";
|
||||||
print_r($e->getMessage());
|
print_r($e->getMessage());
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = null;
|
$conn = null;
|
||||||
|
|
||||||
// start test
|
// start test
|
||||||
testValidValues();
|
testValidValues();
|
||||||
testInvalidValues();
|
testInvalidValues();
|
||||||
testEncryptedWithODBC();
|
testEncryptedWithODBC();
|
||||||
testWrongODBC();
|
testWrongODBC();
|
||||||
echo "Done";
|
echo "Done";
|
||||||
// end test
|
// end test
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
function connectVerifyOutput($connectionOptions, $expected = '')
|
function connectVerifyOutput($connectionOptions, $expected = '')
|
||||||
{
|
{
|
||||||
global $server, $uid, $pwd;
|
global $server, $uid, $pwd;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd);
|
$conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd);
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
if (strpos($e->getMessage(), $expected) === false) {
|
if (strpos($e->getMessage(), $expected) === false) {
|
||||||
print_r($e->getMessage());
|
print_r($e->getMessage());
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testValidValues()
|
function testValidValues()
|
||||||
{
|
{
|
||||||
global $msodbcsqlMaj;
|
global $msodbcsqlMaj;
|
||||||
|
|
||||||
$value = "";
|
$value = "";
|
||||||
// The major version number of ODBC 11 can be 11 or 12
|
// The major version number of ODBC 11 can be 11 or 12
|
||||||
// Test with {}
|
// Test with {}
|
||||||
switch ($msodbcsqlMaj) {
|
switch ($msodbcsqlMaj) {
|
||||||
case 17:
|
case 17:
|
||||||
$value = "{ODBC Driver 17 for SQL Server}";
|
$value = "{ODBC Driver 17 for SQL Server}";
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
case 13:
|
case 13:
|
||||||
$value = "{ODBC Driver 13 for SQL Server}";
|
$value = "{ODBC Driver 13 for SQL Server}";
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
case 11:
|
case 11:
|
||||||
$value = "{ODBC Driver 11 for SQL Server}";
|
$value = "{ODBC Driver 11 for SQL Server}";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$value = "invalid value $msodbcsqlMaj";
|
$value = "invalid value $msodbcsqlMaj";
|
||||||
}
|
}
|
||||||
$connectionOptions = "Driver = $value";
|
$connectionOptions = "Driver = $value";
|
||||||
connectVerifyOutput($connectionOptions);
|
connectVerifyOutput($connectionOptions);
|
||||||
|
|
||||||
// Test without {}
|
// Test without {}
|
||||||
switch ($msodbcsqlMaj) {
|
switch ($msodbcsqlMaj) {
|
||||||
case 17:
|
case 17:
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
$value = "ODBC Driver 17 for SQL Server";
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
case 13:
|
case 13:
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
case 11:
|
case 11:
|
||||||
$value = "ODBC Driver 11 for SQL Server";
|
$value = "ODBC Driver 11 for SQL Server";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$value = "invalid value $msodbcsqlMaj";
|
$value = "invalid value $msodbcsqlMaj";
|
||||||
}
|
}
|
||||||
|
|
||||||
$connectionOptions = "Driver = $value";
|
$connectionOptions = "Driver = $value";
|
||||||
connectVerifyOutput($connectionOptions);
|
connectVerifyOutput($connectionOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInvalidValues()
|
function testInvalidValues()
|
||||||
{
|
{
|
||||||
$values = array("{SQL Server Native Client 11.0}",
|
$values = array("{SQL Server Native Client 11.0}",
|
||||||
"SQL Server Native Client 11.0",
|
"SQL Server Native Client 11.0",
|
||||||
"ODBC Driver 00 for SQL Server",
|
"ODBC Driver 00 for SQL Server",
|
||||||
123,
|
123,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
$connectionOptions = "Driver = $value";
|
$connectionOptions = "Driver = $value";
|
||||||
$expected = "Invalid value $value was specified for Driver option.";
|
$expected = "Invalid value $value was specified for Driver option.";
|
||||||
connectVerifyOutput($connectionOptions, $expected);
|
connectVerifyOutput($connectionOptions, $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testEncryptedWithODBC()
|
function testEncryptedWithODBC()
|
||||||
{
|
{
|
||||||
global $msodbcsqlMaj, $server, $uid, $pwd;
|
// Skip this function if running outside Windows
|
||||||
|
if (!strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') {
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
return;
|
||||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
}
|
||||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
|
||||||
|
global $msodbcsqlMaj, $server, $uid, $pwd;
|
||||||
connectVerifyOutput($connectionOptions, $expected);
|
|
||||||
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
// TODO: the following block will change once ODBC 17 is officially released
|
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
|
||||||
|
connectVerifyOutput($connectionOptions, $expected);
|
||||||
$success = "Successfully connected with column encryption.";
|
|
||||||
$expected = "The specified ODBC Driver is not found.";
|
// TODO: the following block will change once ODBC 17 is officially released
|
||||||
$message = $success;
|
$value = "ODBC Driver 17 for SQL Server";
|
||||||
try {
|
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
||||||
$conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd);
|
|
||||||
} catch(PDOException $e) {
|
$success = "Successfully connected with column encryption.";
|
||||||
$message = $e->getMessage();
|
$expected = "The specified ODBC Driver is not found.";
|
||||||
}
|
$message = $success;
|
||||||
|
try {
|
||||||
if ($msodbcsqlMaj == 17) {
|
$conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd);
|
||||||
// this indicates that OCBC 17 is the only available driver
|
} catch(PDOException $e) {
|
||||||
if (strcmp($message, $success)) {
|
$message = $e->getMessage();
|
||||||
print_r($message);
|
}
|
||||||
}
|
|
||||||
} else {
|
if ($msodbcsqlMaj == 17) {
|
||||||
// OCBC 17 might or might not exist
|
// this indicates that OCBC 17 is the only available driver
|
||||||
if (strcmp($message, $success)) {
|
if (strcmp($message, $success)) {
|
||||||
if (strpos($message, $expected) === false) {
|
print_r($message);
|
||||||
print_r($message);
|
}
|
||||||
}
|
} else {
|
||||||
}
|
// OCBC 17 might or might not exist
|
||||||
}
|
if (strcmp($message, $success)) {
|
||||||
}
|
if (strpos($message, $expected) === false) {
|
||||||
|
print_r($message);
|
||||||
function testWrongODBC()
|
}
|
||||||
{
|
}
|
||||||
global $msodbcsqlMaj;
|
}
|
||||||
|
}
|
||||||
// TODO: this will change once ODBC 17 is officially released
|
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
function testWrongODBC()
|
||||||
if ($msodbcsqlMaj == 17 || $msodbcsqlMaj < 13) {
|
{
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
global $msodbcsqlMaj;
|
||||||
}
|
|
||||||
$connectionOptions = "Driver = $value;";
|
// TODO: this will change once ODBC 17 is officially released
|
||||||
$expected = "The specified ODBC Driver is not found.";
|
$value = "ODBC Driver 17 for SQL Server";
|
||||||
|
if ($msodbcsqlMaj == 17 || $msodbcsqlMaj < 13) {
|
||||||
connectVerifyOutput($connectionOptions, $expected);
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
}
|
}
|
||||||
|
$connectionOptions = "Driver = $value;";
|
||||||
?>
|
$expected = "The specified ODBC Driver is not found.";
|
||||||
--EXPECT--
|
|
||||||
|
connectVerifyOutput($connectionOptions, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
Done
|
Done
|
|
@ -1,108 +1,108 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test new connection keyword ColumnEncryption
|
Test new connection keyword ColumnEncryption
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif_unix.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require_once("MsSetup.inc");
|
require_once("MsSetup.inc");
|
||||||
$msodbcsql_maj = "";
|
$msodbcsql_maj = "";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$conn = new PDO( "sqlsrv:server = $server", $uid, $pwd );
|
$conn = new PDO( "sqlsrv:server = $server", $uid, $pwd );
|
||||||
$msodbcsql_ver = $conn->getAttribute( PDO::ATTR_CLIENT_VERSION )['DriverVer'];
|
$msodbcsql_ver = $conn->getAttribute( PDO::ATTR_CLIENT_VERSION )['DriverVer'];
|
||||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||||
}
|
}
|
||||||
catch( PDOException $e )
|
catch( PDOException $e )
|
||||||
{
|
{
|
||||||
echo "Failed to connect\n";
|
echo "Failed to connect\n";
|
||||||
print_r( $e->getMessage() );
|
print_r( $e->getMessage() );
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj );
|
test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj );
|
||||||
echo "Done";
|
echo "Done";
|
||||||
|
|
||||||
|
|
||||||
function verify_output( $PDOerror, $expected )
|
function verify_output( $PDOerror, $expected )
|
||||||
{
|
{
|
||||||
if( strpos( $PDOerror->getMessage(), $expected ) === false )
|
if( strpos( $PDOerror->getMessage(), $expected ) === false )
|
||||||
{
|
{
|
||||||
print_r( $PDOerror->getMessage() );
|
print_r( $PDOerror->getMessage() );
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj )
|
function test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj )
|
||||||
{
|
{
|
||||||
// Only works for ODBC 17
|
// Only works for ODBC 17
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
$connectionInfo = "ColumnEncryption = Enabled;";
|
$connectionInfo = "ColumnEncryption = Enabled;";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||||
}
|
}
|
||||||
catch( PDOException $e )
|
catch( PDOException $e )
|
||||||
{
|
{
|
||||||
if($msodbcsql_maj < 17)
|
if($msodbcsql_maj < 17)
|
||||||
{
|
{
|
||||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||||
verify_output( $e, $expected );
|
verify_output( $e, $expected );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print_r( $e->getMessage() );
|
print_r( $e->getMessage() );
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Works for ODBC 17, ODBC 13
|
// Works for ODBC 17, ODBC 13
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
$connectionInfo = "ColumnEncryption = Disabled;";
|
$connectionInfo = "ColumnEncryption = Disabled;";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||||
}
|
}
|
||||||
catch( PDOException $e )
|
catch( PDOException $e )
|
||||||
{
|
{
|
||||||
if($msodbcsql_maj < 13)
|
if($msodbcsql_maj < 13)
|
||||||
{
|
{
|
||||||
$expected = "Invalid connection string attribute";
|
$expected = "Invalid connection string attribute";
|
||||||
verify_output( $e, $expected );
|
verify_output( $e, $expected );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print_r( $e->getMessage() );
|
print_r( $e->getMessage() );
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should fail for all ODBC drivers
|
// should fail for all ODBC drivers
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
$connectionInfo = "ColumnEncryption = false;";
|
$connectionInfo = "ColumnEncryption = false;";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||||
}
|
}
|
||||||
catch( PDOException $e )
|
catch( PDOException $e )
|
||||||
{
|
{
|
||||||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||||
verify_output( $e, $expected );
|
verify_output( $e, $expected );
|
||||||
}
|
}
|
||||||
|
|
||||||
// should fail for all ODBC drivers
|
// should fail for all ODBC drivers
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
$connectionInfo = "ColumnEncryption = 1;";
|
$connectionInfo = "ColumnEncryption = 1;";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||||
}
|
}
|
||||||
catch( PDOException $e )
|
catch( PDOException $e )
|
||||||
{
|
{
|
||||||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||||
verify_output( $e, $expected );
|
verify_output( $e, $expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Done
|
Done
|
|
@ -1,158 +1,163 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test new connection keyword Driver with valid and invalid values
|
Test new connection keyword Driver with valid and invalid values
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
||||||
require_once('MsSetup.inc');
|
require_once('MsSetup.inc');
|
||||||
|
|
||||||
$connectionOptions = array("Database"=>$database, "UID"=>$userName, "PWD"=>$userPassword);
|
$connectionOptions = array("Database"=>$database, "UID"=>$userName, "PWD"=>$userPassword);
|
||||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||||
if ($conn === false) {
|
if ($conn === false) {
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
$msodbcsqlVer = sqlsrv_client_info($conn)['DriverVer'];
|
$msodbcsqlVer = sqlsrv_client_info($conn)['DriverVer'];
|
||||||
$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0];
|
$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0];
|
||||||
sqlsrv_close($conn);
|
sqlsrv_close($conn);
|
||||||
|
|
||||||
// start test
|
// start test
|
||||||
testValidValues($msodbcsqlMaj, $server, $connectionOptions);
|
testValidValues($msodbcsqlMaj, $server, $connectionOptions);
|
||||||
testInvalidValues($msodbcsqlMaj, $server, $connectionOptions);
|
testInvalidValues($msodbcsqlMaj, $server, $connectionOptions);
|
||||||
testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions);
|
testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions);
|
||||||
testWrongODBC($msodbcsqlMaj, $server, $connectionOptions);
|
testWrongODBC($msodbcsqlMaj, $server, $connectionOptions);
|
||||||
echo "Done";
|
echo "Done";
|
||||||
// end test
|
// end test
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
function connectVerifyOutput($server, $connectionOptions, $expected = '')
|
function connectVerifyOutput($server, $connectionOptions, $expected = '')
|
||||||
{
|
{
|
||||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||||
if ($conn === false) {
|
if ($conn === false) {
|
||||||
if (strpos(sqlsrv_errors($conn)[0]['message'], $expected) === false) {
|
if (strpos(sqlsrv_errors($conn)[0]['message'], $expected) === false) {
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testValidValues($msodbcsqlMaj, $server, $connectionOptions)
|
function testValidValues($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
{
|
{
|
||||||
$value = "";
|
$value = "";
|
||||||
// The major version number of ODBC 11 can be 11 or 12
|
// The major version number of ODBC 11 can be 11 or 12
|
||||||
// Test with {}
|
// Test with {}
|
||||||
switch ($msodbcsqlMaj) {
|
switch ($msodbcsqlMaj) {
|
||||||
case 17:
|
case 17:
|
||||||
$value = "{ODBC Driver 17 for SQL Server}";
|
$value = "{ODBC Driver 17 for SQL Server}";
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
case 13:
|
case 13:
|
||||||
$value = "{ODBC Driver 13 for SQL Server}";
|
$value = "{ODBC Driver 13 for SQL Server}";
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
case 11:
|
case 11:
|
||||||
$value = "{ODBC Driver 11 for SQL Server}";
|
$value = "{ODBC Driver 11 for SQL Server}";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$value = "invalid value $msodbcsqlMaj";
|
$value = "invalid value $msodbcsqlMaj";
|
||||||
}
|
}
|
||||||
$connectionOptions['Driver']=$value;
|
$connectionOptions['Driver']=$value;
|
||||||
connectVerifyOutput($server, $connectionOptions);
|
connectVerifyOutput($server, $connectionOptions);
|
||||||
|
|
||||||
// Test without {}
|
// Test without {}
|
||||||
switch ($msodbcsqlMaj) {
|
switch ($msodbcsqlMaj) {
|
||||||
case 17:
|
case 17:
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
$value = "ODBC Driver 17 for SQL Server";
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
case 13:
|
case 13:
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
case 11:
|
case 11:
|
||||||
$value = "ODBC Driver 11 for SQL Server";
|
$value = "ODBC Driver 11 for SQL Server";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$value = "invalid value $msodbcsqlMaj";
|
$value = "invalid value $msodbcsqlMaj";
|
||||||
}
|
}
|
||||||
|
|
||||||
$connectionOptions['Driver']=$value;
|
$connectionOptions['Driver']=$value;
|
||||||
connectVerifyOutput($server, $connectionOptions);
|
connectVerifyOutput($server, $connectionOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInvalidValues($msodbcsqlMaj, $server, $connectionOptions)
|
function testInvalidValues($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
{
|
{
|
||||||
$values = array("{SQL Server Native Client 11.0}",
|
$values = array("{SQL Server Native Client 11.0}",
|
||||||
"SQL Server Native Client 11.0",
|
"SQL Server Native Client 11.0",
|
||||||
"ODBC Driver 00 for SQL Server");
|
"ODBC Driver 00 for SQL Server");
|
||||||
|
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
$connectionOptions['Driver']=$value;
|
$connectionOptions['Driver']=$value;
|
||||||
$expected = "Invalid value $value was specified for Driver option.";
|
$expected = "Invalid value $value was specified for Driver option.";
|
||||||
connectVerifyOutput($server, $connectionOptions, $expected);
|
connectVerifyOutput($server, $connectionOptions, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = array(123, false);
|
$values = array(123, false);
|
||||||
|
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
$connectionOptions['Driver']=$value;
|
$connectionOptions['Driver']=$value;
|
||||||
$expected = "Invalid value type for option Driver was specified. String type was expected.";
|
$expected = "Invalid value type for option Driver was specified. String type was expected.";
|
||||||
connectVerifyOutput($server, $connectionOptions, $expected);
|
connectVerifyOutput($server, $connectionOptions, $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions)
|
function testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
{
|
{
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
// Skip this function if running outside Windows
|
||||||
$connectionOptions['Driver']=$value;
|
if (!strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') {
|
||||||
$connectionOptions['ColumnEncryption']='Enabled';
|
return;
|
||||||
|
}
|
||||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
|
||||||
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
connectVerifyOutput($server, $connectionOptions, $expected);
|
$connectionOptions['Driver']=$value;
|
||||||
|
$connectionOptions['ColumnEncryption']='Enabled';
|
||||||
// TODO: the following block will change once ODBC 17 is officially released
|
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||||
$connectionOptions['Driver']=$value;
|
|
||||||
$connectionOptions['ColumnEncryption']='Enabled';
|
connectVerifyOutput($server, $connectionOptions, $expected);
|
||||||
|
|
||||||
$success = "Successfully connected with column encryption.";
|
// TODO: the following block will change once ODBC 17 is officially released
|
||||||
$expected = "The specified ODBC Driver is not found.";
|
$value = "ODBC Driver 17 for SQL Server";
|
||||||
$message = $success;
|
$connectionOptions['Driver']=$value;
|
||||||
|
$connectionOptions['ColumnEncryption']='Enabled';
|
||||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
|
||||||
if ($conn === false) {
|
$success = "Successfully connected with column encryption.";
|
||||||
$message = sqlsrv_errors($conn)[0]['message'];
|
$expected = "The specified ODBC Driver is not found.";
|
||||||
}
|
$message = $success;
|
||||||
|
|
||||||
if ($msodbcsqlMaj == 17) {
|
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||||
// this indicates that OCBC 17 is the only available driver
|
if ($conn === false) {
|
||||||
if (strcmp($message, $success)) {
|
$message = sqlsrv_errors($conn)[0]['message'];
|
||||||
print_r($message);
|
}
|
||||||
}
|
|
||||||
} else {
|
if ($msodbcsqlMaj == 17) {
|
||||||
// OCBC 17 might or might not exist
|
// this indicates that OCBC 17 is the only available driver
|
||||||
if (strcmp($message, $success)) {
|
if (strcmp($message, $success)) {
|
||||||
if (strpos($message, $expected) === false) {
|
print_r($message);
|
||||||
print_r($message);
|
}
|
||||||
}
|
} else {
|
||||||
}
|
// OCBC 17 might or might not exist
|
||||||
}
|
if (strcmp($message, $success)) {
|
||||||
}
|
if (strpos($message, $expected) === false) {
|
||||||
|
print_r($message);
|
||||||
function testWrongODBC($msodbcsqlMaj, $server, $connectionOptions)
|
}
|
||||||
{
|
}
|
||||||
// TODO: this will change once ODBC 17 is officially released
|
}
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
}
|
||||||
if ($msodbcsqlMaj == 17 || $msodbcsqlMaj < 13) {
|
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
function testWrongODBC($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
}
|
{
|
||||||
|
// TODO: this will change once ODBC 17 is officially released
|
||||||
$connectionOptions['Driver']=$value;
|
$value = "ODBC Driver 17 for SQL Server";
|
||||||
$expected = "The specified ODBC Driver is not found.";
|
if ($msodbcsqlMaj == 17 || $msodbcsqlMaj < 13) {
|
||||||
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
connectVerifyOutput($server, $connectionOptions, $expected);
|
}
|
||||||
}
|
|
||||||
|
$connectionOptions['Driver']=$value;
|
||||||
?>
|
$expected = "The specified ODBC Driver is not found.";
|
||||||
--EXPECT--
|
|
||||||
Done
|
connectVerifyOutput($server, $connectionOptions, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Done
|
||||||
|
|
|
@ -1,102 +1,102 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test new connection keyword ColumnEncryption
|
Test new connection keyword ColumnEncryption
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif_unix.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||||
require( 'MsSetup.inc' );
|
require( 'MsSetup.inc' );
|
||||||
|
|
||||||
$connectionOptions = array("Database"=>$database,"UID"=>$userName, "PWD"=>$userPassword);
|
$connectionOptions = array("Database"=>$database,"UID"=>$userName, "PWD"=>$userPassword);
|
||||||
test_ColumnEncryption($server, $connectionOptions);
|
test_ColumnEncryption($server, $connectionOptions);
|
||||||
echo "Done";
|
echo "Done";
|
||||||
|
|
||||||
function test_ColumnEncryption($server ,$connectionOptions){
|
function test_ColumnEncryption($server ,$connectionOptions){
|
||||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||||
if ($conn === false)
|
if ($conn === false)
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
|
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
|
||||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||||
|
|
||||||
// Only works for ODBC 17
|
// Only works for ODBC 17
|
||||||
$connectionOptions['ColumnEncryption']='Enabled';
|
$connectionOptions['ColumnEncryption']='Enabled';
|
||||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||||
if( $conn === false )
|
if( $conn === false )
|
||||||
{
|
{
|
||||||
if($msodbcsql_maj < 17){
|
if($msodbcsql_maj < 17){
|
||||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||||
if( strcasecmp(sqlsrv_errors($conn)[0]['message'], $expected ) != 0 )
|
if( strcasecmp(sqlsrv_errors($conn)[0]['message'], $expected ) != 0 )
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Works for ODBC 17, ODBC 13
|
// Works for ODBC 17, ODBC 13
|
||||||
$connectionOptions['ColumnEncryption']='Disabled';
|
$connectionOptions['ColumnEncryption']='Disabled';
|
||||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||||
if( $conn === false )
|
if( $conn === false )
|
||||||
{
|
{
|
||||||
if($msodbcsql_maj < 13)
|
if($msodbcsql_maj < 13)
|
||||||
{
|
{
|
||||||
$expected_substr = "Invalid connection string attribute";
|
$expected_substr = "Invalid connection string attribute";
|
||||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sqlsrv_close($conn);
|
sqlsrv_close($conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// should fail for all ODBC drivers
|
// should fail for all ODBC drivers
|
||||||
$connectionOptions['ColumnEncryption']='false';
|
$connectionOptions['ColumnEncryption']='false';
|
||||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||||
if( $conn === false )
|
if( $conn === false )
|
||||||
{
|
{
|
||||||
$expected_substr = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
$expected_substr = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should fail for all ODBC drivers
|
// should fail for all ODBC drivers
|
||||||
$connectionOptions['ColumnEncryption']=true;
|
$connectionOptions['ColumnEncryption']=true;
|
||||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||||
if( $conn === false )
|
if( $conn === false )
|
||||||
{
|
{
|
||||||
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
||||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should fail for all ODBC drivers
|
// should fail for all ODBC drivers
|
||||||
$connectionOptions['ColumnEncryption']=false;
|
$connectionOptions['ColumnEncryption']=false;
|
||||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||||
if( $conn === false )
|
if( $conn === false )
|
||||||
{
|
{
|
||||||
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
||||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||||
{
|
{
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Done
|
Done
|
Loading…
Reference in a new issue