From 8292fb7a1592882627d811359ca0acba912738e6 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Thu, 8 Feb 2018 13:25:08 -0800 Subject: [PATCH] Modified tests to check the right error messages --- .../pdo_sqlsrv/pdo_connect_driver.phpt | 38 +--- .../pdo_sqlsrv/pdo_connect_encrypted.phpt | 214 +++++++++--------- .../sqlsrv/sqlsrv_connect_driver.phpt | 39 +--- .../sqlsrv/sqlsrv_connect_encrypted.phpt | 202 ++++++++--------- 4 files changed, 218 insertions(+), 275 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt b/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt index 91b1412c..34186baf 100644 --- a/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt +++ b/test/functional/pdo_sqlsrv/pdo_connect_driver.phpt @@ -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() diff --git a/test/functional/pdo_sqlsrv/pdo_connect_encrypted.phpt b/test/functional/pdo_sqlsrv/pdo_connect_encrypted.phpt index 66f3a194..8b3b0a0e 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 db05578c..4f878bea 100644 --- a/test/functional/sqlsrv/sqlsrv_connect_driver.phpt +++ b/test/functional/sqlsrv/sqlsrv_connect_driver.phpt @@ -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) diff --git a/test/functional/sqlsrv/sqlsrv_connect_encrypted.phpt b/test/functional/sqlsrv/sqlsrv_connect_encrypted.phpt index 6f9d95ae..5a39140e 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