fixed mars connection, added test for col enrytion

This commit is contained in:
Hadis-Fard 2017-09-12 19:21:55 -07:00
parent 2737b9cc0d
commit 6f3f578219
2 changed files with 73 additions and 67 deletions

View file

@ -52,7 +52,7 @@ const char* PROCESSOR_ARCH[] = { "x86", "x64", "ia64" };
std::vector<std::string> CONNECTION_STRING_DRIVER_NAME{ "Driver={ODBC Driver 17 for SQL Server};","Driver={ODBC Driver 13 for SQL Server};", "Driver={ODBC Driver 11 for SQL Server};" }; std::vector<std::string> CONNECTION_STRING_DRIVER_NAME{ "Driver={ODBC Driver 17 for SQL Server};","Driver={ODBC Driver 13 for SQL Server};", "Driver={ODBC Driver 11 for SQL Server};" };
// default options if only the server is specified // default options if only the server is specified
const char CONNECTION_STRING_DEFAULT_OPTIONS[] = "Mars_Connection={Yes}"; const char CONNECTION_STRING_DEFAULT_OPTIONS[] = "Mars_Connection={Yes};";
// connection option appended when no user name or password is given // connection option appended when no user name or password is given
const char CONNECTION_OPTION_NO_CREDENTIALS[] = "Trusted_Connection={Yes};"; const char CONNECTION_OPTION_NO_CREDENTIALS[] = "Trusted_Connection={Yes};";

View file

@ -4,84 +4,90 @@ Test new connection keyword ColumnEncryption
<?php require('skipif.inc'); ?> <?php require('skipif.inc'); ?>
--FILE-- --FILE--
<?php <?php
sqlsrv_configure( 'WarningsReturnAsErrors', 1 ); sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL ); require( 'MsSetup.inc' );
require( 'MsSetup.inc' );
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd, $connectionOptions = array("Database"=>$database,"UID"=>$userName, "PWD"=>$userPassword);
"ColumnEncryption"=>'Enabled'); test_ColumnEncryption($server, $connectionOptions);
$conn = sqlsrv_connect( $server, $connectionInfo ); 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( $conn === false )
{ {
echo "Failed to connect.\n"; if($msodbcsql_maj < 17){
print_r( sqlsrv_errors() ); $expected = "This extension requires Microsoft ODBC Driver 17 for SQL Server when ColumnEncryption attribute is enabled.";
if( strcasecmp(sqlsrv_errors($conn)[0]['message'], $expected ) != 0 ){
print_r(sqlsrv_errors());
}
}
else{
print_r(sqlsrv_errors());
}
} }
else
{ // Works for ODBC 17, ODBC 13
echo "Connected successfully with ColumnEncryption enabled.\n"; $connectionOptions['ColumnEncryption']='Disabled';
sqlsrv_close( $conn ); $conn = sqlsrv_connect( $server, $connectionOptions );
}
////////////////////////////////////////
$connectionInfo['ColumnEncryption']='false';
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false ) if( $conn === false )
{ {
echo "Failed to connect.\n"; if($msodbcsql_maj < 13){
print_r( sqlsrv_errors() ); $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{
$connectionInfo['ColumnEncryption']=true; sqlsrv_close($conn);
$conn = sqlsrv_connect( $server, $connectionInfo ); }
// should fail for all ODBC drivers
$connectionOptions['ColumnEncryption']='false';
$conn = sqlsrv_connect( $server, $connectionOptions );
if( $conn === false ) if( $conn === false )
{ {
echo "Failed to connect.\n"; $expected_substr = "Invalid value specified for connection string attribute 'ColumnEncryption'";
print_r( sqlsrv_errors() ); if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false ){
} print_r(sqlsrv_errors());
//////////////////////////////////////// }
$connectionInfo['ColumnEncryption']='Disabled'; }
$conn = sqlsrv_connect( $server, $connectionInfo );
// should fail for all ODBC drivers
$connectionOptions['ColumnEncryption']=true;
$conn = sqlsrv_connect( $server, $connectionOptions );
if( $conn === false ) if( $conn === false )
{ {
echo "Failed to connect.\n"; $expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
print_r( sqlsrv_errors() ); if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false ){
print_r(sqlsrv_errors());
}
} }
else
// should fail for all ODBC drivers
$connectionOptions['ColumnEncryption']=false;
$conn = sqlsrv_connect( $server, $connectionOptions );
if( $conn === false )
{ {
echo "Connected successfully with ColumnEncryption disabled.\n"; $expected_substr = "Invalid value type for option ColumnEncryption was specified. String type was expected.";
sqlsrv_close( $conn ); if( strpos(sqlsrv_errors($conn)[0]['message'], $expected_substr ) === false ){
print_r(sqlsrv_errors());
}
} }
}
echo "Done\n";
?> ?>
--EXPECTREGEX-- --EXPECTF--
Connected successfully with ColumnEncryption enabled.
Failed to connect.
Array
\(
\[0\] => Array
\(
\[0\] => 08001
\[SQLSTATE\] => 08001
\[1\] => 0
\[code\] => 0
\[2\] => .*\[Microsoft\]\[ODBC Driver 13 for SQL Server\]Invalid value specified for connection string attribute 'ColumnEncryption'
\[message\] => .*\[Microsoft\]\[ODBC Driver 13 for SQL Server\]Invalid value specified for connection string attribute 'ColumnEncryption'
\)
\)
Failed to connect.
Array
\(
\[0\] => Array
\(
\[0\] => IMSSP
\[SQLSTATE\] => IMSSP
\[1\] => -33
\[code\] => -33
\[2\] => Invalid value type for option ColumnEncryption was specified. String type was expected.
\[message\] => Invalid value type for option ColumnEncryption was specified. String type was expected.
\)
\)
Connected successfully with ColumnEncryption disabled.
Done Done