checkpoint
This commit is contained in:
Родитель
420126a03d
Коммит
b6054dcd1e
26
build.ps1
26
build.ps1
|
@ -7,6 +7,9 @@ param(
|
|||
[switch]
|
||||
$install,
|
||||
|
||||
[switch]
|
||||
$startService,
|
||||
|
||||
[switch]
|
||||
$test,
|
||||
|
||||
|
@ -83,12 +86,14 @@ function CleanUp() {
|
|||
}
|
||||
}
|
||||
|
||||
function StartTest() {
|
||||
function StartTestService($hold) {
|
||||
$group = GetGlobalVariable IIS_ADMIN_API_OWNERS
|
||||
$member = & ([System.IO.Path]::Combine($scriptDir, "setup", "security.ps1")) CurrentAdUser
|
||||
if (!(Get-LocalGroupMember -Group $group -Member $member -ErrorAction SilentlyContinue)) {
|
||||
Add-LocalGroupMember -Group $group -Member $member
|
||||
}
|
||||
|
||||
Write-Host "[Build] Sanity tests..."
|
||||
$pingEndpoint = "https://localhost:$testPort"
|
||||
try {
|
||||
Invoke-WebRequest -UseDefaultCredentials -UseBasicParsing $pingEndpoint | Out-Null
|
||||
|
@ -96,6 +101,15 @@ function StartTest() {
|
|||
Write-Error "Failed to ping test server $pingEndpoint, did you forget to start it manually?"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
if ($hold) {
|
||||
Read-Host "Press enter to continue..."
|
||||
}
|
||||
}
|
||||
|
||||
function StartTest() {
|
||||
Write-Host "[Build] Functional tests..."
|
||||
dotnet test ([System.IO.Path]::Combine($projectRoot, "test", "Microsoft.IIS.Administration.Tests", "Microsoft.IIS.Administration.Tests.csproj"))
|
||||
}
|
||||
|
||||
function VerifyPath($path) {
|
||||
|
@ -146,10 +160,18 @@ try {
|
|||
Publish
|
||||
|
||||
if ($install) {
|
||||
Write-Host "[Build] Installing test service..."
|
||||
Write-Host "[Build] Installing service..."
|
||||
InstallTestService
|
||||
}
|
||||
|
||||
if ($test -or $startService) {
|
||||
Write-Host "[Build] Starting service..."
|
||||
if ($test -and $startService) {
|
||||
Write-Warning "[Build] -test flag is provided, unit tests will continue right after service is started. To hold to service in running stage for manual testing, omit the -test flag"
|
||||
}
|
||||
StartTestService (!$test)
|
||||
}
|
||||
|
||||
if ($test) {
|
||||
Write-Host "[Build] Starting test..."
|
||||
StartTest
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
namespace Microsoft.IIS.Administration.Tests
|
||||
{
|
||||
using Core.Http;
|
||||
using System.Net.Http;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
public class ApiHttpClient : HttpClient
|
||||
{
|
||||
private string _keyId;
|
||||
private string _serverUri;
|
||||
private HttpClient _keyClient;
|
||||
|
||||
public static HttpClient Create()
|
||||
{
|
||||
|
@ -20,23 +23,23 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
public static HttpClient Create(string serverUri)
|
||||
{
|
||||
HttpClientHandler handler = new HttpClientHandler();
|
||||
handler.ServerCertificateCustomValidationCallback = (request, cert, chain, errors) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
handler.ServerCertificateCustomValidationCallback = ServerCertificateCustomValidationCallback;
|
||||
return new ApiHttpClient(serverUri, handler, true);
|
||||
}
|
||||
|
||||
private ApiHttpClient(string serverUri, HttpMessageHandler handler, bool disposeHandler) : base(handler, disposeHandler)
|
||||
{
|
||||
_keyClient = new HttpClient(new HttpClientHandler()
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = ServerCertificateCustomValidationCallback,
|
||||
UseDefaultCredentials = true
|
||||
}, true);
|
||||
Init(serverUri);
|
||||
}
|
||||
|
||||
private void Init(string serverUri)
|
||||
{
|
||||
|
||||
var key = Utils.GetApiKey(serverUri, this);
|
||||
|
||||
{
|
||||
var key = Utils.GetApiKey(serverUri, _keyClient);
|
||||
_keyId = key.Value<string>("id");
|
||||
_serverUri = serverUri;
|
||||
|
||||
|
@ -44,15 +47,24 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
this.DefaultRequestHeaders.Add("Accept", "application/hal+json");
|
||||
}
|
||||
|
||||
private static bool ServerCertificateCustomValidationCallback(HttpRequestMessage msg, X509Certificate2 cert, X509Chain x509, SslPolicyErrors errors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.DefaultRequestHeaders.Clear();
|
||||
Utils.DeleteApiKey(_serverUri, _keyId, this);
|
||||
Utils.DeleteApiKey(_serverUri, _keyId, _keyClient);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_keyClient != null)
|
||||
{
|
||||
_keyClient.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче