From bad65817e1aaae3315f46bdfe7595b727b00b8a2 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Thu, 8 Feb 2018 09:30:07 -0800 Subject: [PATCH] ColumnEncryption keyword reserved for Windows for now --- .../pdo_sqlsrv/pdo_connect_driver.phpt | 323 +++++++++--------- .../pdo_sqlsrv/pdo_connect_encrypted.phpt | 214 ++++++------ .../sqlsrv/sqlsrv_connect_driver.phpt | 321 ++++++++--------- .../sqlsrv/sqlsrv_connect_encrypted.phpt | 202 +++++------ 4 files changed, 535 insertions(+), 525 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt b/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt index 468f9ceb..b9e3f5ac 100644 --- a/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt +++ b/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt @@ -1,160 +1,165 @@ ---TEST-- -Test new connection keyword Driver with valid and invalid values ---SKIPIF-- - ---FILE-- -getAttribute(PDO::ATTR_CLIENT_VERSION)['DriverVer']; - $msodbcsqlMaj = explode(".", $msodbcsqlVer)[0]; -} catch(PDOException $e) { - echo "Failed to connect\n"; - print_r($e->getMessage()); - echo "\n"; -} - -$conn = null; - -// start test -testValidValues(); -testInvalidValues(); -testEncryptedWithODBC(); -testWrongODBC(); -echo "Done"; -// end test - -/////////////////////////// -function connectVerifyOutput($connectionOptions, $expected = '') -{ - global $server, $uid, $pwd; - - try { - $conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd); - } catch(PDOException $e) { - if (strpos($e->getMessage(), $expected) === false) { - print_r($e->getMessage()); - echo "\n"; - } - } -} - -function testValidValues() -{ - global $msodbcsqlMaj; - - $value = ""; - // The major version number of ODBC 11 can be 11 or 12 - // Test with {} - switch ($msodbcsqlMaj) { - case 17: - $value = "{ODBC Driver 17 for SQL Server}"; - break; - case 14: - case 13: - $value = "{ODBC Driver 13 for SQL Server}"; - break; - case 12: - case 11: - $value = "{ODBC Driver 11 for SQL Server}"; - break; - default: - $value = "invalid value $msodbcsqlMaj"; - } - $connectionOptions = "Driver = $value"; - connectVerifyOutput($connectionOptions); - - // Test without {} - switch ($msodbcsqlMaj) { - case 17: - $value = "ODBC Driver 17 for SQL Server"; - break; - case 14: - case 13: - $value = "ODBC Driver 13 for SQL Server"; - break; - case 12: - case 11: - $value = "ODBC Driver 11 for SQL Server"; - break; - default: - $value = "invalid value $msodbcsqlMaj"; - } - - $connectionOptions = "Driver = $value"; - connectVerifyOutput($connectionOptions); -} - -function testInvalidValues() -{ - $values = array("{SQL Server Native Client 11.0}", - "SQL Server Native Client 11.0", - "ODBC Driver 00 for SQL Server", - 123, - false); - - foreach ($values as $value) { - $connectionOptions = "Driver = $value"; - $expected = "Invalid value $value was specified for Driver option."; - connectVerifyOutput($connectionOptions, $expected); - } -} - -function testEncryptedWithODBC() -{ - 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 ($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() -{ - global $msodbcsqlMaj; - - // 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"; - } - $connectionOptions = "Driver = $value;"; - $expected = "The specified ODBC Driver is not found."; - - connectVerifyOutput($connectionOptions, $expected); -} - -?> ---EXPECT-- +--TEST-- +Test new connection keyword Driver with valid and invalid values +--SKIPIF-- + +--FILE-- +getAttribute(PDO::ATTR_CLIENT_VERSION)['DriverVer']; + $msodbcsqlMaj = explode(".", $msodbcsqlVer)[0]; +} catch(PDOException $e) { + echo "Failed to connect\n"; + print_r($e->getMessage()); + echo "\n"; +} + +$conn = null; + +// start test +testValidValues(); +testInvalidValues(); +testEncryptedWithODBC(); +testWrongODBC(); +echo "Done"; +// end test + +/////////////////////////// +function connectVerifyOutput($connectionOptions, $expected = '') +{ + global $server, $uid, $pwd; + + try { + $conn = new PDO("sqlsrv:server = $server ; $connectionOptions", $uid, $pwd); + } catch(PDOException $e) { + if (strpos($e->getMessage(), $expected) === false) { + print_r($e->getMessage()); + echo "\n"; + } + } +} + +function testValidValues() +{ + global $msodbcsqlMaj; + + $value = ""; + // The major version number of ODBC 11 can be 11 or 12 + // Test with {} + switch ($msodbcsqlMaj) { + case 17: + $value = "{ODBC Driver 17 for SQL Server}"; + break; + case 14: + case 13: + $value = "{ODBC Driver 13 for SQL Server}"; + break; + case 12: + case 11: + $value = "{ODBC Driver 11 for SQL Server}"; + break; + default: + $value = "invalid value $msodbcsqlMaj"; + } + $connectionOptions = "Driver = $value"; + connectVerifyOutput($connectionOptions); + + // Test without {} + switch ($msodbcsqlMaj) { + case 17: + $value = "ODBC Driver 17 for SQL Server"; + break; + case 14: + case 13: + $value = "ODBC Driver 13 for SQL Server"; + break; + case 12: + case 11: + $value = "ODBC Driver 11 for SQL Server"; + break; + default: + $value = "invalid value $msodbcsqlMaj"; + } + + $connectionOptions = "Driver = $value"; + connectVerifyOutput($connectionOptions); +} + +function testInvalidValues() +{ + $values = array("{SQL Server Native Client 11.0}", + "SQL Server Native Client 11.0", + "ODBC Driver 00 for SQL Server", + 123, + false); + + foreach ($values as $value) { + $connectionOptions = "Driver = $value"; + $expected = "Invalid value $value was specified for Driver option."; + connectVerifyOutput($connectionOptions, $expected); + } +} + +function testEncryptedWithODBC() +{ + // Skip this function if running outside Windows + if (!strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') { + return; + } + + 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 ($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() +{ + global $msodbcsqlMaj; + + // 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"; + } + $connectionOptions = "Driver = $value;"; + $expected = "The specified ODBC Driver is not found."; + + connectVerifyOutput($connectionOptions, $expected); +} + +?> +--EXPECT-- Done \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_connect_encrypted.phpt b/test/functional/pdo_sqlsrv/pdo_connect_encrypted.phpt index cb073668..66f3a194 100644 --- a/test/functional/pdo_sqlsrv/pdo_connect_encrypted.phpt +++ b/test/functional/pdo_sqlsrv/pdo_connect_encrypted.phpt @@ -1,108 +1,108 @@ ---TEST-- -Test new connection keyword ColumnEncryption ---SKIPIF-- - ---FILE-- -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-- + +--FILE-- +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 \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_connect_driver.phpt b/test/functional/sqlsrv/sqlsrv_connect_driver.phpt index 89377f1a..e539b4c9 100644 --- a/test/functional/sqlsrv/sqlsrv_connect_driver.phpt +++ b/test/functional/sqlsrv/sqlsrv_connect_driver.phpt @@ -1,158 +1,163 @@ ---TEST-- -Test new connection keyword Driver with valid and invalid values ---SKIPIF-- - ---FILE-- -$database, "UID"=>$userName, "PWD"=>$userPassword); -$conn = sqlsrv_connect($server, $connectionOptions); -if ($conn === false) { - print_r(sqlsrv_errors()); -} -$msodbcsqlVer = sqlsrv_client_info($conn)['DriverVer']; -$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0]; -sqlsrv_close($conn); - -// start test -testValidValues($msodbcsqlMaj, $server, $connectionOptions); -testInvalidValues($msodbcsqlMaj, $server, $connectionOptions); -testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions); -testWrongODBC($msodbcsqlMaj, $server, $connectionOptions); -echo "Done"; -// end test - -/////////////////////////// -function connectVerifyOutput($server, $connectionOptions, $expected = '') -{ - $conn = sqlsrv_connect($server, $connectionOptions); - if ($conn === false) { - if (strpos(sqlsrv_errors($conn)[0]['message'], $expected) === false) { - print_r(sqlsrv_errors()); - } - } -} - -function testValidValues($msodbcsqlMaj, $server, $connectionOptions) -{ - $value = ""; - // The major version number of ODBC 11 can be 11 or 12 - // Test with {} - switch ($msodbcsqlMaj) { - case 17: - $value = "{ODBC Driver 17 for SQL Server}"; - break; - case 14: - case 13: - $value = "{ODBC Driver 13 for SQL Server}"; - break; - case 12: - case 11: - $value = "{ODBC Driver 11 for SQL Server}"; - break; - default: - $value = "invalid value $msodbcsqlMaj"; - } - $connectionOptions['Driver']=$value; - connectVerifyOutput($server, $connectionOptions); - - // Test without {} - switch ($msodbcsqlMaj) { - case 17: - $value = "ODBC Driver 17 for SQL Server"; - break; - case 14: - case 13: - $value = "ODBC Driver 13 for SQL Server"; - break; - case 12: - case 11: - $value = "ODBC Driver 11 for SQL Server"; - break; - default: - $value = "invalid value $msodbcsqlMaj"; - } - - $connectionOptions['Driver']=$value; - connectVerifyOutput($server, $connectionOptions); -} - -function testInvalidValues($msodbcsqlMaj, $server, $connectionOptions) -{ - $values = array("{SQL Server Native Client 11.0}", - "SQL Server Native Client 11.0", - "ODBC Driver 00 for SQL Server"); - - foreach ($values as $value) { - $connectionOptions['Driver']=$value; - $expected = "Invalid value $value was specified for Driver option."; - connectVerifyOutput($server, $connectionOptions, $expected); - } - - $values = array(123, false); - - foreach ($values as $value) { - $connectionOptions['Driver']=$value; - $expected = "Invalid value type for option Driver was specified. String type was expected."; - connectVerifyOutput($server, $connectionOptions, $expected); - } -} - -function testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions) -{ - $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."; - - 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) -{ - // 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"; - } - - $connectionOptions['Driver']=$value; - $expected = "The specified ODBC Driver is not found."; - - connectVerifyOutput($server, $connectionOptions, $expected); -} - -?> ---EXPECT-- -Done +--TEST-- +Test new connection keyword Driver with valid and invalid values +--SKIPIF-- + +--FILE-- +$database, "UID"=>$userName, "PWD"=>$userPassword); +$conn = sqlsrv_connect($server, $connectionOptions); +if ($conn === false) { + print_r(sqlsrv_errors()); +} +$msodbcsqlVer = sqlsrv_client_info($conn)['DriverVer']; +$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0]; +sqlsrv_close($conn); + +// start test +testValidValues($msodbcsqlMaj, $server, $connectionOptions); +testInvalidValues($msodbcsqlMaj, $server, $connectionOptions); +testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions); +testWrongODBC($msodbcsqlMaj, $server, $connectionOptions); +echo "Done"; +// end test + +/////////////////////////// +function connectVerifyOutput($server, $connectionOptions, $expected = '') +{ + $conn = sqlsrv_connect($server, $connectionOptions); + if ($conn === false) { + if (strpos(sqlsrv_errors($conn)[0]['message'], $expected) === false) { + print_r(sqlsrv_errors()); + } + } +} + +function testValidValues($msodbcsqlMaj, $server, $connectionOptions) +{ + $value = ""; + // The major version number of ODBC 11 can be 11 or 12 + // Test with {} + switch ($msodbcsqlMaj) { + case 17: + $value = "{ODBC Driver 17 for SQL Server}"; + break; + case 14: + case 13: + $value = "{ODBC Driver 13 for SQL Server}"; + break; + case 12: + case 11: + $value = "{ODBC Driver 11 for SQL Server}"; + break; + default: + $value = "invalid value $msodbcsqlMaj"; + } + $connectionOptions['Driver']=$value; + connectVerifyOutput($server, $connectionOptions); + + // Test without {} + switch ($msodbcsqlMaj) { + case 17: + $value = "ODBC Driver 17 for SQL Server"; + break; + case 14: + case 13: + $value = "ODBC Driver 13 for SQL Server"; + break; + case 12: + case 11: + $value = "ODBC Driver 11 for SQL Server"; + break; + default: + $value = "invalid value $msodbcsqlMaj"; + } + + $connectionOptions['Driver']=$value; + connectVerifyOutput($server, $connectionOptions); +} + +function testInvalidValues($msodbcsqlMaj, $server, $connectionOptions) +{ + $values = array("{SQL Server Native Client 11.0}", + "SQL Server Native Client 11.0", + "ODBC Driver 00 for SQL Server"); + + foreach ($values as $value) { + $connectionOptions['Driver']=$value; + $expected = "Invalid value $value was specified for Driver option."; + connectVerifyOutput($server, $connectionOptions, $expected); + } + + $values = array(123, false); + + foreach ($values as $value) { + $connectionOptions['Driver']=$value; + $expected = "Invalid value type for option Driver was specified. String type was expected."; + connectVerifyOutput($server, $connectionOptions, $expected); + } +} + +function testEncryptedWithODBC($msodbcsqlMaj, $server, $connectionOptions) +{ + // Skip this function if running outside Windows + if (!strtoupper(substr(php_uname('s'), 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."; + + 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) +{ + // 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"; + } + + $connectionOptions['Driver']=$value; + $expected = "The specified ODBC Driver is not found."; + + connectVerifyOutput($server, $connectionOptions, $expected); +} + +?> +--EXPECT-- +Done diff --git a/test/functional/sqlsrv/sqlsrv_connect_encrypted.phpt b/test/functional/sqlsrv/sqlsrv_connect_encrypted.phpt index e6a5bbb6..6f9d95ae 100644 --- a/test/functional/sqlsrv/sqlsrv_connect_encrypted.phpt +++ b/test/functional/sqlsrv/sqlsrv_connect_encrypted.phpt @@ -1,102 +1,102 @@ ---TEST-- -Test new connection keyword ColumnEncryption ---SKIPIF-- - ---FILE-- -$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-- + +--FILE-- +$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 \ No newline at end of file