Modified tests to check the right error messages
This commit is contained in:
parent
efd9ffbf0d
commit
8292fb7a15
|
@ -104,46 +104,18 @@ function testInvalidValues()
|
||||||
|
|
||||||
function testEncryptedWithODBC()
|
function testEncryptedWithODBC()
|
||||||
{
|
{
|
||||||
// Skip this function if running outside Windows
|
|
||||||
if (!(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
|
||||||
|
|
||||||
global $msodbcsqlMaj, $server, $uid, $pwd;
|
global $msodbcsqlMaj, $server, $uid, $pwd;
|
||||||
|
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
||||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
|
||||||
|
|
||||||
connectVerifyOutput($connectionOptions, $expected);
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||||
|
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||||
// TODO: the following block will change once ODBC 17 is officially released
|
} else {
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
$expected = "An invalid keyword 'ColumnEncryption' was specified in the DSN string.";
|
||||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
|
||||||
|
|
||||||
$success = "Successfully connected with column encryption.";
|
|
||||||
$expected = "The specified ODBC Driver is not found.";
|
|
||||||
$message = $success;
|
|
||||||
try {
|
|
||||||
$conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd);
|
|
||||||
} catch(PDOException $e) {
|
|
||||||
$message = $e->getMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($msodbcsqlMaj == 17) {
|
connectVerifyOutput($connectionOptions, $expected);
|
||||||
// this indicates that OCBC 17 is the only available driver
|
|
||||||
if (strcmp($message, $success)) {
|
|
||||||
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()
|
function testWrongODBC()
|
||||||
|
|
|
@ -1,108 +1,108 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test new connection keyword ColumnEncryption
|
Test new connection keyword ColumnEncryption
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif_unix.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
|
|
@ -102,46 +102,17 @@ function testInvalidValues($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
|
|
||||||
function testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions)
|
function testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
{
|
{
|
||||||
// Skip this function if running outside Windows
|
|
||||||
if (!(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = "ODBC Driver 13 for SQL Server";
|
$value = "ODBC Driver 13 for SQL Server";
|
||||||
$connectionOptions['Driver']=$value;
|
$connectionOptions['Driver']=$value;
|
||||||
$connectionOptions['ColumnEncryption']='Enabled';
|
$connectionOptions['ColumnEncryption']='Enabled';
|
||||||
|
|
||||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||||
|
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||||
|
} else {
|
||||||
|
$expected = "Invalid option ColumnEncryption was passed to sqlsrv_connect.";
|
||||||
|
}
|
||||||
|
|
||||||
connectVerifyOutput($server, $connectionOptions, $expected);
|
connectVerifyOutput($server, $connectionOptions, $expected);
|
||||||
|
|
||||||
// TODO: the following block will change once ODBC 17 is officially released
|
|
||||||
$value = "ODBC Driver 17 for SQL Server";
|
|
||||||
$connectionOptions['Driver']=$value;
|
|
||||||
$connectionOptions['ColumnEncryption']='Enabled';
|
|
||||||
|
|
||||||
$success = "Successfully connected with column encryption.";
|
|
||||||
$expected = "The specified ODBC Driver is not found.";
|
|
||||||
$message = $success;
|
|
||||||
|
|
||||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
|
||||||
if ($conn === false) {
|
|
||||||
$message = sqlsrv_errors($conn)[0]['message'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($msodbcsqlMaj == 17) {
|
|
||||||
// this indicates that OCBC 17 is the only available driver
|
|
||||||
if (strcmp($message, $success)) {
|
|
||||||
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)
|
function testWrongODBC($msodbcsqlMaj, $server, $connectionOptions)
|
||||||
|
|
|
@ -1,102 +1,102 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test new connection keyword ColumnEncryption
|
Test new connection keyword ColumnEncryption
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif_unix.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