Updated connpool and aad tests

This commit is contained in:
David Puglielli 2017-06-20 17:05:09 -07:00
parent a3f59a3782
commit f58a75c45e
4 changed files with 123 additions and 110 deletions

View file

@ -1,5 +1,5 @@
--TEST--
PDO Connection Pooling Test on Unix
SQLSRV Connection Pooling Test on Unix
--DESCRIPTION--
This test assumes odbcinst.ini has not been modified.
This test also requires root privileges to modify odbcinst.ini file on Linux.
@ -14,12 +14,14 @@ $lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
//back up the odbcinst.ini file
shell_exec("cp $odbcinst_ini $odbcinst_ini.bak");
shell_exec("sudo cp $odbcinst_ini $odbcinst_ini.bak");
//enable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current.=$lines_to_add;
file_put_contents($odbcinst_ini, $current);
shell_exec("cp $odbcinst_ini .");
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
//Creating a new php process, because for changes in odbcinst.ini file to affect pooling, drivers must be reloaded.
print_r(shell_exec("php ./test/pdo_sqlsrv/isPooled.php"));
@ -27,7 +29,8 @@ print_r(shell_exec("php ./test/pdo_sqlsrv/isPooled.php"));
//disable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current = str_replace($lines_to_add,'',$current);
file_put_contents($odbcinst_ini, $current);
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
print_r(shell_exec("php ./test/pdo_sqlsrv/isPooled.php"));
?>
@ -35,8 +38,8 @@ print_r(shell_exec("php ./test/pdo_sqlsrv/isPooled.php"));
<?php
$lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
shell_exec("cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec("rm $odbcinst_ini.bak");
shell_exec("sudo cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec("sudo rm $odbcinst_ini.bak");
?>
--EXPECT--
Pooled

View file

@ -1,78 +1,86 @@
--TEST--
Test the Authentication keyword with options SqlPassword and ActiveDirectoryIntegrated.
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
$connectionInfo = "Database = $databaseName; Authentication = SqlPassword; TrustServerCertificate = true;";
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with Authentication=SqlPassword.
//
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"Authentication"=>'SqlPassword', "TrustServerCertificate"=>true);
try
{
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
echo "Connected successfully with Authentication=SqlPassword.\n";
}
catch( PDOException $e )
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
echo "Could not connect with Authentication=SqlPassword.\n";
print_r( $e->getMessage() );
echo "\n";
var_dump( sqlsrv_errors() );
}
else
{
echo "Connected successfully with Authentication=SqlPassword.\n";
}
$stmt = $conn->query( "SELECT count(*) FROM cd_info" );
$stmt = sqlsrv_query( $conn, "SELECT count(*) FROM cd_info" );
if ( $stmt === false )
{
echo "Query failed.\n";
}
else
{
$result = $stmt->fetch();
$result = sqlsrv_fetch_array( $stmt );
var_dump( $result );
}
$conn = null;
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with integrated authentication. This should fail because
// we don't support it.
//
$connectionInfo = array( "Authentication"=>"ActiveDirectoryIntegrated", "TrustServerCertificate"=>true );
$connectionInfo = "Authentication = ActiveDirectoryIntegrated; TrustServerCertificate = true;";
try
{
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo" );
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
$conn = null;
}
catch( PDOException $e )
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
echo "Could not connect with Authentication=ActiveDirectoryIntegrated.\n";
print_r( $e->getMessage() );
echo "\n";
$errors = sqlsrv_errors();
print_r($errors[0]);
}
else
{
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
sqlsrv_close( $conn );
}
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
// your credentials to test, or this part is skipped.
//
$azureServer = $adServer;
$azureDatabase = $adDatabase;
$azureUsername = $adUser;
$azurePassword = $adPassword;
$azureServer = 'myServer';
$azureDatabase = 'myDatabase';
$azureUsername = 'myUsername';
$azurePassword = 'myPassword';
if ($azureServer != 'myServer')
if ($azureServer != 'TARGET_AD_SERVER')
{
$connectionInfo = "Authentication = ActiveDirectoryPassword; TrustServerCertificate = false";
$connectionInfo = array( "UID"=>$azureUsername, "PWD"=>$azurePassword,
"Authentication"=>'ActiveDirectoryPassword', "TrustServerCertificate"=>true );
try
{
$conn = new PDO( "sqlsrv:server = $azureServer ; $connectionInfo", $azureUsername, $azurePassword );
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
}
catch( PDOException $e )
$conn = sqlsrv_connect( $azureServer, $connectionInfo );
if( $conn === false )
{
echo "Could not connect with ActiveDirectoryPassword.\n";
print_r( $e->getMessage() );
echo "\n";
print_r( sqlsrv_errors() );
}
else
{
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
sqlsrv_close( $conn );
}
}
else
@ -83,11 +91,19 @@ else
--EXPECTF--
Connected successfully with Authentication=SqlPassword.
array(2) {
[""]=>
string(1) "7"
[0]=>
string(1) "7"
int(7)
[""]=>
int(7)
}
Could not connect with Authentication=ActiveDirectoryIntegrated.
SQLSTATE[IMSSP]: Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -62
[code] => -62
[2] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
[message] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
)
%s with Authentication=ActiveDirectoryPassword.

View file

@ -14,12 +14,14 @@ $lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
//back up the odbcinst.ini file
shell_exec("cp $odbcinst_ini $odbcinst_ini.bak");
shell_exec("sudo cp $odbcinst_ini $odbcinst_ini.bak");
//enable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current.=$lines_to_add;
file_put_contents($odbcinst_ini, $current);
shell_exec("cp $odbcinst_ini .");
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
//Creating a new php process, because for changes in odbcinst.ini file to affect pooling, drivers must be reloaded.
print_r(shell_exec("php ./test/sqlsrv/isPooled.php"));
@ -27,7 +29,8 @@ print_r(shell_exec("php ./test/sqlsrv/isPooled.php"));
//disable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current = str_replace($lines_to_add,'',$current);
file_put_contents($odbcinst_ini, $current);
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
print_r(shell_exec("php ./test/sqlsrv/isPooled.php"));
?>
@ -35,8 +38,8 @@ print_r(shell_exec("php ./test/sqlsrv/isPooled.php"));
<?php
$lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
shell_exec("cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec("rm $odbcinst_ini.bak");
shell_exec("sudo cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec("sudo rm $odbcinst_ini.bak");
?>
--EXPECT--
Pooled

View file

@ -6,79 +6,78 @@ Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryI
<?php
require_once("MsSetup.inc");
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with Authentication=SqlPassword.
//
$connectionInfo = "Database = $databaseName; Authentication = SqlPassword; TrustServerCertificate = true;";
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"Authentication"=>'SqlPassword', "TrustServerCertificate"=>true);
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
echo "Could not connect with Authentication=SqlPassword.\n";
var_dump( sqlsrv_errors() );
}
else
try
{
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
echo "Connected successfully with Authentication=SqlPassword.\n";
}
catch( PDOException $e )
{
echo "Could not connect with Authentication=SqlPassword.\n";
print_r( $e->getMessage() );
echo "\n";
}
$stmt = sqlsrv_query( $conn, "SELECT count(*) FROM cd_info" );
$stmt = $conn->query( "SELECT count(*) FROM cd_info" );
if ( $stmt === false )
{
echo "Query failed.\n";
}
else
{
$result = sqlsrv_fetch_array( $stmt );
$result = $stmt->fetch();
var_dump( $result );
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
$conn = null;
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with integrated authentication. This should fail because
// we don't support it.
//
$connectionInfo = "Authentication = ActiveDirectoryIntegrated; TrustServerCertificate = true;";
$connectionInfo = array( "Authentication"=>"ActiveDirectoryIntegrated", "TrustServerCertificate"=>true );
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
try
{
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo" );
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
$conn = null;
}
catch( PDOException $e )
{
echo "Could not connect with Authentication=ActiveDirectoryIntegrated.\n";
$errors = sqlsrv_errors();
print_r($errors[0]);
}
else
{
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
sqlsrv_close( $conn );
print_r( $e->getMessage() );
echo "\n";
}
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
// your credentials to test, or this part is skipped.
//
$azureServer = $adServer;
$azureDatabase = $adDatabase;
$azureUsername = $adUser;
$azurePassword = $adPassword;
$azureServer = 'myServer';
$azureDatabase = 'myDatabase';
$azureUsername = 'myUsername';
$azurePassword = 'myPassword';
if ($azureServer != 'myServer')
if ($azureServer != 'TARGET_AD_SERVER')
{
$connectionInfo = array( "UID"=>$azureUsername, "PWD"=>$azurePassword,
"Authentication"=>'ActiveDirectoryPassword', "TrustServerCertificate"=>true );
$connectionInfo = "Authentication = ActiveDirectoryPassword; TrustServerCertificate = false";
$conn = sqlsrv_connect( $azureServer, $connectionInfo );
if( $conn === false )
try
{
$conn = new PDO( "sqlsrv:server = $azureServer ; $connectionInfo", $azureUsername, $azurePassword );
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
}
catch( PDOException $e )
{
echo "Could not connect with ActiveDirectoryPassword.\n";
print_r( sqlsrv_errors() );
}
else
{
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
sqlsrv_close( $conn );
print_r( $e->getMessage() );
echo "\n";
}
}
else
@ -89,19 +88,11 @@ else
--EXPECTF--
Connected successfully with Authentication=SqlPassword.
array(2) {
[0]=>
int(7)
[""]=>
int(7)
string(1) "7"
[0]=>
string(1) "7"
}
Could not connect with Authentication=ActiveDirectoryIntegrated.
Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -62
[code] => -62
[2] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
[message] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
)
SQLSTATE[IMSSP]: Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
%s with Authentication=ActiveDirectoryPassword.