Azure AD tests using ActiveDirectoryPassword

This commit is contained in:
yitam 2017-06-12 10:51:23 -07:00
parent 31fb19405b
commit f38d57b7f7
4 changed files with 95 additions and 12 deletions

View file

@ -21,6 +21,11 @@ if (isset($_ENV['MSSQL_SERVER']) || isset($_ENV['MSSQL_USER']) || isset($_ENV['M
$DriverName = "ODBC Driver 11 for SQL Server";
}
$adServer = 'TARGET_AD_SERVER';
$adDatabase = 'TARGET_AD_DATABASE';
$adUser = 'TARGET_AD_USERNAME';
$adPassword = 'TARGET_AD_PASSWORD';
$driverType = true;
$PhpDriver = "ODBC Driver 11 for SQL Server";

View file

@ -1,11 +1,14 @@
--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");
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with Authentication=SqlPassword.
//
$connectionInfo = "Database = $databaseName; Authentication = SqlPassword; TrustServerCertificate = true;";
try
@ -33,8 +36,10 @@ else
$conn = null;
////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with integrated authentication. This should fail because
// we don't support it.
//
$connectionInfo = "Authentication = ActiveDirectoryIntegrated; TrustServerCertificate = true;";
try
@ -50,8 +55,37 @@ catch( PDOException $e )
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;
if ($azureServer != 'TARGET_AD_SERVER')
{
$connectionInfo = "Authentication = ActiveDirectoryPassword; TrustServerCertificate = 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( $e->getMessage() );
echo "\n";
}
}
else
{
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
}
?>
--EXPECT--
--EXPECTF--
Connected successfully with Authentication=SqlPassword.
array(2) {
[""]=>
@ -60,4 +94,6 @@ array(2) {
string(1) "7"
}
Could not connect with Authentication=ActiveDirectoryIntegrated.
SQLSTATE[IMSSP]: 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.

View file

@ -25,6 +25,11 @@ $marsMode = true;
$traceEnabled = false;
$adServer = 'TARGET_AD_SERVER';
$adDatabase = 'TARGET_AD_DATABASE';
$adUser = 'TARGET_AD_USERNAME';
$adPassword = 'TARGET_AD_PASSWORD';
if (isset($_ENV['MSSQL_SERVER']) || isset($_ENV['MSSQL_USER']) || isset($_ENV['MSSQL_PASSWORD'])) {
$server = $_ENV['MSSQL_SERVER'];
$uid = $_ENV['MSSQL_USER'];

View file

@ -1,11 +1,14 @@
--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");
///////////////////////////////////////////////////////////////////////////////////////////
// Test Azure AD with Authentication=SqlPassword.
//
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
"Authentication"=>'SqlPassword', "TrustServerCertificate"=>true);
@ -35,8 +38,10 @@ else
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 );
$conn = sqlsrv_connect( $server, $connectionInfo );
@ -52,8 +57,38 @@ else
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;
if ($azureServer != 'TARGET_AD_SERVER')
{
$connectionInfo = array( "UID"=>$azureUsername, "PWD"=>$azurePassword,
"Authentication"=>'ActiveDirectoryPassword', "TrustServerCertificate"=>true );
$conn = sqlsrv_connect( $azureServer, $connectionInfo );
if( $conn === false )
{
echo "Could not connect with ActiveDirectoryPassword.\n";
print_r( sqlsrv_errors() );
}
else
{
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
sqlsrv_close( $conn );
}
}
else
{
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
}
?>
--EXPECT--
--EXPECTF--
Connected successfully with Authentication=SqlPassword.
array(2) {
[0]=>
@ -70,4 +105,6 @@ Array
[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.