mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-06 07:54:05 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15ece7ec09 | ||
|
|
336cb7ccae |
@@ -1,11 +1,3 @@
|
|||||||
# 1.5.57 (04 June 2024)
|
|
||||||
- [#1113](https://github.com/WireMock-Net/WireMock.Net/pull/1113) - Add some Extension methods to IWireMockAdminApi [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
|
|
||||||
# 1.5.56 (03 June 2024)
|
|
||||||
- [#1111](https://github.com/WireMock-Net/WireMock.Net/pull/1111) - Fix Request.Create().WithBodyAsJson(...) [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1112](https://github.com/WireMock-Net/WireMock.Net/pull/1112) - Add "/__admin/health" endpoint [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1110](https://github.com/WireMock-Net/WireMock.Net/issues/1110) - Connection prematurely closed BEFORE response [bug]
|
|
||||||
|
|
||||||
# 1.5.55 (22 May 2024)
|
# 1.5.55 (22 May 2024)
|
||||||
- [#1107](https://github.com/WireMock-Net/WireMock.Net/pull/1107) - When only Port is provided, bind to * (Fixes #1100) [bug] contributed by [StefH](https://github.com/StefH)
|
- [#1107](https://github.com/WireMock-Net/WireMock.Net/pull/1107) - When only Port is provided, bind to * (Fixes #1100) [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.5.57</VersionPrefix>
|
<VersionPrefix>1.5.55</VersionPrefix>
|
||||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
rem https://github.com/StefH/GitHubReleaseNotes
|
rem https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
SET version=1.5.57
|
SET version=1.5.55
|
||||||
|
|
||||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN%
|
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN%
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# 1.5.57 (04 June 2024)
|
# 1.5.55 (22 May 2024)
|
||||||
- #1113 Add some Extension methods to IWireMockAdminApi [feature]
|
- #1107 When only Port is provided, bind to * (Fixes #1100) [bug]
|
||||||
|
|
||||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
@@ -229,6 +229,7 @@ message HelloReply {
|
|||||||
server.SetBasicAuthentication("a", "b");
|
server.SetBasicAuthentication("a", "b");
|
||||||
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
|
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
|
||||||
|
|
||||||
|
|
||||||
//var http = new HttpClient();
|
//var http = new HttpClient();
|
||||||
//var response = await http.GetAsync($"{_wireMockServer.Url}/pricing");
|
//var response = await http.GetAsync($"{_wireMockServer.Url}/pricing");
|
||||||
//var value = await response.Content.ReadAsStringAsync();
|
//var value = await response.Content.ReadAsStringAsync();
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Stef.Validation;
|
|
||||||
using WireMock.Client.Builders;
|
using WireMock.Client.Builders;
|
||||||
|
|
||||||
namespace WireMock.Client.Extensions;
|
namespace WireMock.Client.Extensions;
|
||||||
@@ -13,77 +7,13 @@ namespace WireMock.Client.Extensions;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WireMockAdminApiExtensions
|
public static class WireMockAdminApiExtensions
|
||||||
{
|
{
|
||||||
private const int MaxRetries = 5;
|
|
||||||
private const int InitialWaitingTimeInMilliSeconds = 500;
|
|
||||||
private const string HealthStatusHealthy = "Healthy";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
|
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
/// <param name="api">See <see cref="IWireMockAdminApi"/>.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi adminApi)
|
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi api)
|
||||||
{
|
{
|
||||||
return new AdminApiMappingBuilder(adminApi);
|
return new AdminApiMappingBuilder(api);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set basic authentication to access the <see cref="IWireMockAdminApi"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
|
||||||
/// <param name="username">The admin username.</param>
|
|
||||||
/// <param name="password">The admin password.</param>
|
|
||||||
/// <returns><see cref="IWireMockAdminApi"/></returns>
|
|
||||||
public static IWireMockAdminApi WithAuthorization(this IWireMockAdminApi adminApi, string username, string password)
|
|
||||||
{
|
|
||||||
Guard.NotNull(adminApi);
|
|
||||||
Guard.NotNullOrEmpty(username);
|
|
||||||
Guard.NotNullOrEmpty(password);
|
|
||||||
|
|
||||||
adminApi.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")));
|
|
||||||
return adminApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wait for the WireMock.Net server to be healthy. (The "/__admin/health" returns "Healthy").
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
|
||||||
/// <param name="maxRetries">The maximum number of retries. Default is <c>5</c>.</param>
|
|
||||||
/// <param name="cancellationToken">The optional <see cref="CancellationToken"/>.</param>
|
|
||||||
/// <returns>A completed Task in case the health endpoint is available, else throws a <see cref="InvalidOperationException"/>.</returns>
|
|
||||||
public static async Task WaitForHealthAsync(this IWireMockAdminApi adminApi, int maxRetries = MaxRetries, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
Guard.NotNull(adminApi);
|
|
||||||
|
|
||||||
var retries = 0;
|
|
||||||
var waitTime = InitialWaitingTimeInMilliSeconds;
|
|
||||||
var totalWaitTime = waitTime;
|
|
||||||
var isHealthy = await IsHealthyAsync(adminApi, cancellationToken);
|
|
||||||
while (!isHealthy && retries < MaxRetries && !cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
waitTime = (int)(InitialWaitingTimeInMilliSeconds * Math.Pow(2, retries));
|
|
||||||
await Task.Delay(waitTime, cancellationToken);
|
|
||||||
isHealthy = await IsHealthyAsync(adminApi, cancellationToken);
|
|
||||||
retries++;
|
|
||||||
totalWaitTime += waitTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retries >= MaxRetries)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"The /__admin/health endpoint did not return 'Healthy' after {MaxRetries} retries and {totalWaitTime / 1000.0:0.0} seconds.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task<bool> IsHealthyAsync(IWireMockAdminApi adminApi, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var status = await adminApi.GetHealthAsync(cancellationToken);
|
|
||||||
return string.Equals(status, HealthStatusHealthy, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,24 +24,12 @@ public interface IWireMockAdminApi
|
|||||||
[Header("Authorization")]
|
[Header("Authorization")]
|
||||||
AuthenticationHeaderValue Authorization { get; set; }
|
AuthenticationHeaderValue Authorization { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get health status.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// Returns HttpStatusCode <c>200</c> with a value <c>Healthy</c> to indicate that WireMock.Net is healthy.
|
|
||||||
/// Else it returns HttpStatusCode <c>404</c>.
|
|
||||||
/// </returns>
|
|
||||||
[Get("health")]
|
|
||||||
[AllowAnyStatusCode]
|
|
||||||
Task<string> GetHealthAsync(CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the settings.
|
/// Get the settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>SettingsModel</returns>
|
/// <returns>SettingsModel</returns>
|
||||||
[Get("settings")]
|
[Get("settings")]
|
||||||
Task<SettingsModel> GetSettingsAsync(CancellationToken cancellationToken = default);
|
Task<SettingsModel> GetSettingsAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the settings.
|
/// Update the settings.
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using Microsoft.Extensions.Logging;
|
|||||||
using RestEase;
|
using RestEase;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Client;
|
using WireMock.Client;
|
||||||
using WireMock.Client.Extensions;
|
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
|
|
||||||
namespace WireMock.Net.Testcontainers;
|
namespace WireMock.Net.Testcontainers;
|
||||||
@@ -48,7 +47,13 @@ public sealed class WireMockContainer : DockerContainer
|
|||||||
ValidateIfRunning();
|
ValidateIfRunning();
|
||||||
|
|
||||||
var api = RestClient.For<IWireMockAdminApi>(GetPublicUri());
|
var api = RestClient.For<IWireMockAdminApi>(GetPublicUri());
|
||||||
return _configuration.HasBasicAuthentication ? api.WithAuthorization(_configuration.Username!, _configuration.Password!) : api;
|
|
||||||
|
if (_configuration.HasBasicAuthentication)
|
||||||
|
{
|
||||||
|
api.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_configuration.Username}:{_configuration.Password}")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public partial class WireMockServer
|
|||||||
{
|
{
|
||||||
private const int EnhancedFileSystemWatcherTimeoutMs = 1000;
|
private const int EnhancedFileSystemWatcherTimeoutMs = 1000;
|
||||||
private const string AdminFiles = "/__admin/files";
|
private const string AdminFiles = "/__admin/files";
|
||||||
private const string AdminHealth = "/__admin/health";
|
|
||||||
private const string AdminMappings = "/__admin/mappings";
|
private const string AdminMappings = "/__admin/mappings";
|
||||||
private const string AdminMappingsCode = "/__admin/mappings/code";
|
private const string AdminMappingsCode = "/__admin/mappings/code";
|
||||||
private const string AdminMappingsWireMockOrg = "/__admin/mappings/wiremock.org";
|
private const string AdminMappingsWireMockOrg = "/__admin/mappings/wiremock.org";
|
||||||
@@ -55,9 +54,6 @@ public partial class WireMockServer
|
|||||||
#region InitAdmin
|
#region InitAdmin
|
||||||
private void InitAdmin()
|
private void InitAdmin()
|
||||||
{
|
{
|
||||||
// __admin/health
|
|
||||||
Given(Request.Create().WithPath(AdminHealth).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(HealthGet));
|
|
||||||
|
|
||||||
// __admin/settings
|
// __admin/settings
|
||||||
Given(Request.Create().WithPath(AdminSettings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsGet));
|
Given(Request.Create().WithPath(AdminSettings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsGet));
|
||||||
Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsUpdate));
|
Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsUpdate));
|
||||||
@@ -222,22 +218,6 @@ public partial class WireMockServer
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Health
|
|
||||||
private static IResponseMessage HealthGet(IRequestMessage requestMessage)
|
|
||||||
{
|
|
||||||
return new ResponseMessage
|
|
||||||
{
|
|
||||||
BodyData = new BodyData
|
|
||||||
{
|
|
||||||
DetectedBodyType = BodyType.String,
|
|
||||||
BodyAsString = "Healthy"
|
|
||||||
},
|
|
||||||
StatusCode = (int)HttpStatusCode.OK,
|
|
||||||
Headers = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string>(WireMockConstants.ContentTypeTextPlain) } }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Settings
|
#region Settings
|
||||||
private IResponseMessage SettingsGet(IRequestMessage requestMessage)
|
private IResponseMessage SettingsGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
@@ -850,4 +830,4 @@ public partial class WireMockServer
|
|||||||
var singleResult = ((JObject)value).ToObject<T>();
|
var singleResult = ((JObject)value).ToObject<T>();
|
||||||
return new[] { singleResult! };
|
return new[] { singleResult! };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ using VerifyXunit;
|
|||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
using WireMock.Client;
|
using WireMock.Client;
|
||||||
using WireMock.Client.Extensions;
|
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
@@ -42,47 +41,6 @@ public partial class WireMockAdminApiTests
|
|||||||
VerifyNewtonsoftJson.Enable(VerifySettings);
|
VerifyNewtonsoftJson.Enable(VerifySettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_OK()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var adminUsername = $"username_{Guid.NewGuid()}";
|
|
||||||
var adminPassword = $"password_{Guid.NewGuid()}";
|
|
||||||
var server = WireMockServer.Start(w =>
|
|
||||||
{
|
|
||||||
w.StartAdminInterface = true;
|
|
||||||
w.AdminUsername = adminUsername;
|
|
||||||
w.AdminPassword = adminPassword;
|
|
||||||
});
|
|
||||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0])
|
|
||||||
.WithAuthorization(adminUsername, adminPassword);
|
|
||||||
|
|
||||||
// Act 1
|
|
||||||
await api.WaitForHealthAsync().ConfigureAwait(false);
|
|
||||||
|
|
||||||
// Act 2
|
|
||||||
var status = await api.GetHealthAsync().ConfigureAwait(false);
|
|
||||||
status.Should().Be("Healthy");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_ThrowsException()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var server = WireMockServer.Start(w =>
|
|
||||||
{
|
|
||||||
w.StartAdminInterface = true;
|
|
||||||
w.AdminUsername = $"username_{Guid.NewGuid()}";
|
|
||||||
w.AdminPassword = $"password_{Guid.NewGuid()}";
|
|
||||||
});
|
|
||||||
|
|
||||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
Func<Task> act = () => api.WaitForHealthAsync(maxRetries: 3);
|
|
||||||
await act.Should().ThrowAsync<InvalidOperationException>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task IWireMockAdminApi_GetSettingsAsync()
|
public async Task IWireMockAdminApi_GetSettingsAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using FluentAssertions.Execution;
|
using FluentAssertions.Execution;
|
||||||
@@ -14,12 +13,9 @@ public class TestcontainersTests
|
|||||||
public async Task WireMockContainer_Build_and_StartAsync_and_StopAsync()
|
public async Task WireMockContainer_Build_and_StartAsync_and_StopAsync()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var adminUsername = $"username_{Guid.NewGuid()}";
|
|
||||||
var adminPassword = $"password_{Guid.NewGuid()}";
|
|
||||||
var wireMockContainer = new WireMockContainerBuilder()
|
var wireMockContainer = new WireMockContainerBuilder()
|
||||||
.WithAutoRemove(true)
|
.WithAutoRemove(true)
|
||||||
.WithCleanUp(true)
|
.WithCleanUp(true)
|
||||||
.WithAdminUserNameAndPassword(adminUsername, adminPassword)
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public class WireMockServerProxyTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
server.Mappings.Should().HaveCount(36);
|
server.Mappings.Should().HaveCount(35);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class WireMockServerSettingsTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
server.Mappings.Should().NotBeNull();
|
server.Mappings.Should().NotBeNull();
|
||||||
server.Mappings.Should().HaveCount(34);
|
server.Mappings.Should().HaveCount(33);
|
||||||
server.Mappings.All(m => m.Priority == WireMockConstants.AdminPriority).Should().BeTrue();
|
server.Mappings.All(m => m.Priority == WireMockConstants.AdminPriority).Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,9 +100,9 @@ public class WireMockServerSettingsTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
server.Mappings.Should().NotBeNull();
|
server.Mappings.Should().NotBeNull();
|
||||||
server.Mappings.Should().HaveCount(35);
|
server.Mappings.Should().HaveCount(34);
|
||||||
|
|
||||||
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(34);
|
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(33);
|
||||||
server.Mappings.Count(m => m.Priority == WireMockConstants.ProxyPriority).Should().Be(1);
|
server.Mappings.Count(m => m.Priority == WireMockConstants.ProxyPriority).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user