php-sqlsrv/test/functional/sqlsrv/sqlsrv_azure_ad_authentication.phpt

92 lines
3.3 KiB
PHP

--TEST--
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
--SKIPIF--
<?php require('skipif.inc');
require('skipif_version_less_than_2k16.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);
$conn = sqlsrv_connect($server, $connectionInfo);
if ($conn === false) {
echo "Could not connect with Authentication=SqlPassword.\n";
var_dump(sqlsrv_errors());
} else {
echo "Connected successfully with Authentication=SqlPassword.\n";
}
// For details, https://docs.microsoft.com/sql/t-sql/functions/serverproperty-transact-sql
$stmt = sqlsrv_query($conn, "SELECT SERVERPROPERTY('EngineEdition')");
if (sqlsrv_fetch($stmt)) {
$edition = sqlsrv_get_field($stmt, 0);
var_dump($edition);
} else {
echo "Query failed.\n";
}
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);
if ($conn === false) {
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);
}
///////////////////////////////////////////////////////////////////////////////////////////
// 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"=>false );
$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";
}
?>
--EXPECTF--
Connected successfully with Authentication=SqlPassword.
string(1) "%d"
Could not connect with Authentication=ActiveDirectoryIntegrated.
Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -62
[code] => -62
[2] => Invalid option for the Authentication keyword. Only SqlPassword, ActiveDirectoryPassword, or ActiveDirectoryMsi is supported.
[message] => Invalid option for the Authentication keyword. Only SqlPassword, ActiveDirectoryPassword, or ActiveDirectoryMsi is supported.
)
%s with Authentication=ActiveDirectoryPassword.