--TEST-- Test some basics of Azure AD Service Principal support --SKIPIF-- $userName, "PWD"=>$userPassword, "Driver" => $driver); $conn = sqlsrv_connect($server, $connectionInfo); if ($conn === false) { die("skip: Failed to connect in skipif."); } $msodbcsqlVer = sqlsrv_client_info($conn)['DriverVer']; $version = explode(".", $msodbcsqlVer); if ($version[0] < 17 || $version[1] < 7) { die("skip: Requires ODBC driver 17.7 or above"); } ?> --FILE-- $adDatabase, "Authentication"=>"ActiveDirectoryServicePrincipal", "UID"=>$adSPClientId, "PWD"=>$adSPClientSecret); $conn = sqlsrv_connect($adServer, $connectionInfo); if ($conn === false) { if ($showException) { fatalError("Could not connect with Azure AD Service Principal after $maxAttempts retries.\n"); } } else { simpleTest($conn); sqlsrv_close($conn); } return $conn; } // Try connecting to an invalid server. Expect this to fail. $connectionInfo = array("Authentication"=>"ActiveDirectoryServicePrincipal"); $conn = sqlsrv_connect('invalidServer', $connectionInfo); if ($conn) { fatalError("AzureAD Service Principal test: expected to fail with invalidServer\n"); } // Next, test connecting with Service Principal $maxAttempts = 3; if ($adServer != 'TARGET_AD_SERVER' && $adSPClientId != 'TARGET_ADSP_CLIENT_ID') { $conn = false; $numAttempts = 0; do { $conn = connectAzureDB($numAttempts == ($maxAttempts - 1)); if ($conn === false) { $numAttempts++; sleep(10); } } while ($conn === false && $numAttempts < $maxAttempts); } echo "Done\n"; ?> --EXPECT-- Done