зеркало из https://github.com/microsoft/msphpsql.git
Modified tests to check the right error messages
This commit is contained in:
Родитель
efd9ffbf0d
Коммит
8292fb7a15
|
@ -104,46 +104,18 @@ function testInvalidValues()
|
|||
|
||||
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;
|
||||
|
||||
$value = "ODBC Driver 13 for SQL Server";
|
||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
|
||||
connectVerifyOutput($connectionOptions, $expected);
|
||||
|
||||
// TODO: the following block will change once ODBC 17 is officially released
|
||||
$value = "ODBC Driver 17 for SQL Server";
|
||||
$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 (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
} else {
|
||||
$expected = "An invalid keyword 'ColumnEncryption' was specified in the DSN string.";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
connectVerifyOutput($connectionOptions, $expected);
|
||||
}
|
||||
|
||||
function testWrongODBC()
|
||||
|
|
|
@ -1,108 +1,108 @@
|
|||
--TEST--
|
||||
Test new connection keyword ColumnEncryption
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsSetup.inc");
|
||||
$msodbcsql_maj = "";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server", $uid, $pwd );
|
||||
$msodbcsql_ver = $conn->getAttribute( PDO::ATTR_CLIENT_VERSION )['DriverVer'];
|
||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Failed to connect\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj );
|
||||
echo "Done";
|
||||
|
||||
|
||||
function verify_output( $PDOerror, $expected )
|
||||
{
|
||||
if( strpos( $PDOerror->getMessage(), $expected ) === false )
|
||||
{
|
||||
print_r( $PDOerror->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
function test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj )
|
||||
{
|
||||
// Only works for ODBC 17
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = Enabled;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
if($msodbcsql_maj < 17)
|
||||
{
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Works for ODBC 17, ODBC 13
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = Disabled;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
if($msodbcsql_maj < 13)
|
||||
{
|
||||
$expected = "Invalid connection string attribute";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = false;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = 1;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--TEST--
|
||||
Test new connection keyword ColumnEncryption
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsSetup.inc");
|
||||
$msodbcsql_maj = "";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server", $uid, $pwd );
|
||||
$msodbcsql_ver = $conn->getAttribute( PDO::ATTR_CLIENT_VERSION )['DriverVer'];
|
||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Failed to connect\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj );
|
||||
echo "Done";
|
||||
|
||||
|
||||
function verify_output( $PDOerror, $expected )
|
||||
{
|
||||
if( strpos( $PDOerror->getMessage(), $expected ) === false )
|
||||
{
|
||||
print_r( $PDOerror->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
function test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj )
|
||||
{
|
||||
// Only works for ODBC 17
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = Enabled;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
if($msodbcsql_maj < 17)
|
||||
{
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Works for ODBC 17, ODBC 13
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = Disabled;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
if($msodbcsql_maj < 13)
|
||||
{
|
||||
$expected = "Invalid connection string attribute";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = false;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
////////////////////////////////////////
|
||||
$connectionInfo = "ColumnEncryption = 1;";
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||
verify_output( $e, $expected );
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Done
|
|
@ -102,46 +102,17 @@ function testInvalidValues($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";
|
||||
$connectionOptions['Driver']=$value;
|
||||
$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);
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -1,102 +1,102 @@
|
|||
--TEST--
|
||||
Test new connection keyword ColumnEncryption
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
require( 'MsSetup.inc' );
|
||||
|
||||
$connectionOptions = array("Database"=>$database,"UID"=>$userName, "PWD"=>$userPassword);
|
||||
test_ColumnEncryption($server, $connectionOptions);
|
||||
echo "Done";
|
||||
|
||||
function test_ColumnEncryption($server ,$connectionOptions){
|
||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||
if ($conn === false)
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
|
||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||
|
||||
// Only works for ODBC 17
|
||||
$connectionOptions['ColumnEncryption']='Enabled';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
if($msodbcsql_maj < 17){
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
if( strcasecmp(sqlsrv_errors($conn)[0]['message'], $expected ) != 0 )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// Works for ODBC 17, ODBC 13
|
||||
$connectionOptions['ColumnEncryption']='Disabled';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
if($msodbcsql_maj < 13)
|
||||
{
|
||||
$expected_substr = "Invalid connection string attribute";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']='false';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
$expected_substr = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']=true;
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']=false;
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--TEST--
|
||||
Test new connection keyword ColumnEncryption
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
require( 'MsSetup.inc' );
|
||||
|
||||
$connectionOptions = array("Database"=>$database,"UID"=>$userName, "PWD"=>$userPassword);
|
||||
test_ColumnEncryption($server, $connectionOptions);
|
||||
echo "Done";
|
||||
|
||||
function test_ColumnEncryption($server ,$connectionOptions){
|
||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||
if ($conn === false)
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
|
||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||
|
||||
// Only works for ODBC 17
|
||||
$connectionOptions['ColumnEncryption']='Enabled';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
if($msodbcsql_maj < 17){
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
if( strcasecmp(sqlsrv_errors($conn)[0]['message'], $expected ) != 0 )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// Works for ODBC 17, ODBC 13
|
||||
$connectionOptions['ColumnEncryption']='Disabled';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
if($msodbcsql_maj < 13)
|
||||
{
|
||||
$expected_substr = "Invalid connection string attribute";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']='false';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
$expected_substr = "Invalid value specified for connection string attribute 'ColumnEncryption'";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']=true;
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']=false;
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
$expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
|
||||
if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false )
|
||||
{
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Done
|
Загрузка…
Ссылка в новой задаче