-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated skipifs and modified tests with HGS enabled servers (#1111)
- Loading branch information
Showing
4 changed files
with
132 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,106 @@ | ||
--TEST-- | ||
Test new connection keyword ColumnEncryption | ||
--DESCRIPTION-- | ||
Some test cases return errors as expected. For testing purposes, an enclave enabled | ||
SQL Server and the HGS server are the same instance. If the server is HGS enabled, | ||
the error message of one test case is not the same. | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
$msodbcsql_maj = ""; | ||
$msodbcsqlMaj = ""; | ||
$hgsEnabled = true; | ||
|
||
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 ) | ||
{ | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server", $uid, $pwd); | ||
$msodbcsqlVer = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)['DriverVer']; | ||
$version = explode(".", $msodbcsqlVer); | ||
$msodbcsqlMaj = $version[0]; | ||
|
||
// Next, check if the server is HGS enabled | ||
$serverInfo = $conn->getAttribute(PDO::ATTR_SERVER_INFO); | ||
if (strpos($serverInfo['SQLServerName'], 'PHPHGS') === false) { | ||
$hgsEnabled = false; | ||
} | ||
} catch (PDOException $e) { | ||
echo "Failed to connect\n"; | ||
print_r( $e->getMessage() ); | ||
print_r($e->getMessage()); | ||
echo "\n"; | ||
} | ||
|
||
test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj ); | ||
testColumnEncryption($server, $uid, $pwd, $msodbcsqlMaj); | ||
echo "Done"; | ||
|
||
|
||
function verify_output( $PDOerror, $expected ) | ||
function verifyOutput($PDOerror, $expected, $caseNum) | ||
{ | ||
if( strpos( $PDOerror->getMessage(), $expected ) === false ) | ||
{ | ||
print_r( $PDOerror->getMessage() ); | ||
if (strpos($PDOerror->getMessage(), $expected) === false) { | ||
echo "Test case $caseNum failed:\n"; | ||
print_r($PDOerror->getMessage()); | ||
echo "\n"; | ||
} | ||
} | ||
|
||
function test_ColumnEncryption( $server, $uid, $pwd, $msodbcsql_maj ) | ||
function testColumnEncryption($server, $uid, $pwd, $msodbcsqlMaj) | ||
{ | ||
global $hgsEnabled; | ||
|
||
// 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) | ||
{ | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server ; $connectionInfo", $uid, $pwd); | ||
} catch (PDOException $e) { | ||
if ($msodbcsqlMaj < 17) { | ||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server."; | ||
verify_output( $e, $expected ); | ||
} | ||
else | ||
{ | ||
print_r( $e->getMessage() ); | ||
verifyOutput($e, $expected, "1"); | ||
} else { | ||
echo "Test case 1 failed:\n"; | ||
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) | ||
{ | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server ; $connectionInfo", $uid, $pwd); | ||
} catch (PDOException $e) { | ||
if ($msodbcsqlMaj < 13) { | ||
$expected = "Invalid connection string attribute"; | ||
verify_output( $e, $expected ); | ||
} | ||
else | ||
{ | ||
print_r( $e->getMessage() ); | ||
verifyOutput($e, $expected, "2"); | ||
} else { | ||
echo "Test case 2 failed:\n"; | ||
print_r($e->getMessage()); | ||
echo "\n"; | ||
} | ||
} | ||
|
||
// should fail for all ODBC drivers | ||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'"; | ||
if ($hgsEnabled) { | ||
$expected = "Requested attestation protocol is invalid."; | ||
} | ||
|
||
//////////////////////////////////////// | ||
$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 ); | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server ; $connectionInfo", $uid, $pwd); | ||
} catch (PDOException $e) { | ||
verifyOutput($e, $expected, "3"); | ||
} | ||
|
||
// should fail for all ODBC drivers | ||
//////////////////////////////////////// | ||
$connectionInfo = "ColumnEncryption = 1;"; | ||
try | ||
{ | ||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd ); | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server ; $connectionInfo", $uid, $pwd); | ||
} catch (PDOException $e) { | ||
verifyOutput($e, $expected, "4"); | ||
} | ||
catch( PDOException $e ) | ||
{ | ||
$expected = "Invalid value specified for connection string attribute 'ColumnEncryption'"; | ||
verify_output( $e, $expected ); | ||
} | ||
} | ||
} | ||
?> | ||
--EXPECT-- | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters