fixed mars connection, added test for col enrytion
This commit is contained in:
parent
2737b9cc0d
commit
6f3f578219
|
@ -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};" };
|
||||
|
||||
// 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
|
||||
const char CONNECTION_OPTION_NO_CREDENTIALS[] = "Trusted_Connection={Yes};";
|
||||
|
|
|
@ -4,84 +4,90 @@ Test new connection keyword ColumnEncryption
|
|||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 1 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
require( 'MsSetup.inc' );
|
||||
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ColumnEncryption"=>'Enabled');
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
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 )
|
||||
{
|
||||
echo "Failed to connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
if($msodbcsql_maj < 17){
|
||||
$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
|
||||
{
|
||||
echo "Connected successfully with ColumnEncryption enabled.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
$connectionInfo['ColumnEncryption']='false';
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
|
||||
// Works for ODBC 17, ODBC 13
|
||||
$connectionOptions['ColumnEncryption']='Disabled';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Failed to connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
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());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
$connectionInfo['ColumnEncryption']=true;
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
else{
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
// should fail for all ODBC drivers
|
||||
$connectionOptions['ColumnEncryption']='false';
|
||||
$conn = sqlsrv_connect( $server, $connectionOptions );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Failed to connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
////////////////////////////////////////
|
||||
$connectionInfo['ColumnEncryption']='Disabled';
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
$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 )
|
||||
{
|
||||
echo "Failed to connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
$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());
|
||||
}
|
||||
}
|
||||
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";
|
||||
sqlsrv_close( $conn );
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
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.
|
||||
--EXPECTF--
|
||||
Done
|
Loading…
Reference in a new issue