Skip to content

Commit

Permalink
Merge branch 'basic_auth' of https://github.com/WireMock-Net/WireMock…
Browse files Browse the repository at this point in the history
….Net into basic_auth
  • Loading branch information
StefH committed Dec 16, 2020
2 parents 5ff217b + d286275 commit 7612520
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
32 changes: 7 additions & 25 deletions examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using WireMock.Logging;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
Expand All @@ -14,9 +15,6 @@ class Program
{
static void Main(string[] args)
{
RunTestDifferentPort().Wait(20000); // prints "1"
RunTestDifferentPort().Wait(20000); // prints "1"

var server = WireMockServer.Start(new WireMockServerSettings
{
Urls = new[] { "http://localhost:9091", "https://localhost:9443" },
Expand All @@ -29,34 +27,18 @@ static void Main(string[] args)
SaveMapping = true,
SaveMappingToFile = false,
ExcludedHeaders = new[] { "dnt", "Content-Length" }
}
},
Logger= new WireMockConsoleLogger()
});

server.LogEntriesChanged += (sender, eventRecordArgs) =>
{
System.Console.WriteLine(JsonConvert.SerializeObject(eventRecordArgs.NewItems, Formatting.Indented));
};
//server.LogEntriesChanged += (sender, eventRecordArgs) =>
//{
// System.Console.WriteLine(JsonConvert.SerializeObject(eventRecordArgs.NewItems, Formatting.Indented));
//};

System.Console.WriteLine("Press any key to stop the server");
System.Console.ReadKey();
server.Stop();
}

private static async Task RunTestDifferentPort()
{
var server = WireMockServer.Start();

server.Given(Request.Create().WithPath("/").UsingGet())
.RespondWith(Response.Create().WithStatusCode(200).WithBody("Hello"));

Thread.Sleep(1000);

var response = await new HttpClient().GetAsync(server.Urls[0]);
response.EnsureSuccessStatusCode();

System.Console.WriteLine("RunTestDifferentPort - server.LogEntries.Count() = " + server.LogEntries.Count());

server.Stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
</PropertyGroup>

Expand Down
6 changes: 1 addition & 5 deletions test/WireMock.Net.Tests/WireMockServer.Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ public async Task WireMockServer_Proxy_Should_preserve_content_header_in_proxied

// check that new proxied mapping is added
Check.That(server.Mappings).HasSize(2);

//var newMapping = _server.Mappings.First(m => m.Guid != guid);
//var matcher = ((Request)newMapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().FirstOrDefault(m => m.Name == "bbb");
//Check.That(matcher).IsNotNull();
}

[Fact]
Expand Down Expand Up @@ -200,7 +196,7 @@ public async Task WireMockServer_Proxy_Should_preserve_Authorization_header_in_p
var authorizationHeader = receivedRequest.Headers["Authorization"].ToString().Should().Be("BASIC test-A");

server.Mappings.Should().HaveCount(2);
var authorizationRequestMessageHeaderMatcher = ((Request)server.Mappings.Last().RequestMatcher)
var authorizationRequestMessageHeaderMatcher = ((Request)server.Mappings.Single(m => !m.IsAdminInterface).RequestMatcher)
.GetRequestMessageMatcher<RequestMessageHeaderMatcher>(x => x.Matchers.Any(m => m.GetPatterns().Contains("BASIC test-A")));
authorizationRequestMessageHeaderMatcher.Should().NotBeNull();
}
Expand Down

0 comments on commit 7612520

Please sign in to comment.