From d0fc889f4241bd1e0d9a572da33b1f56e99d412e Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 12 Dec 2017 18:18:04 +0100 Subject: [PATCH] Fix for url encoded path + params (1.0.2.10) - #72 Fix for url encoded path + params (1.0.2.10) --- .../MainApp.cs | 11 +++++++++- .../WireMock.Net.StandAlone.csproj | 2 +- .../Request/RequestMessageParamMatcher.cs | 20 ++++++------------- src/WireMock.Net/RequestMessage.cs | 17 +++++++++++----- src/WireMock.Net/WireMock.Net.csproj | 2 +- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/examples/WireMock.Net.ConsoleApplication/MainApp.cs b/examples/WireMock.Net.ConsoleApplication/MainApp.cs index b7db6ac7..14bd08a3 100644 --- a/examples/WireMock.Net.ConsoleApplication/MainApp.cs +++ b/examples/WireMock.Net.ConsoleApplication/MainApp.cs @@ -32,7 +32,7 @@ namespace WireMock.Net.ConsoleApplication server.SetBasicAuthentication("a", "b"); - // server.AllowPartialMapping(); + server.AllowPartialMapping(); // .WithHeader("Stef", "Stef") //server @@ -40,6 +40,15 @@ namespace WireMock.Net.ConsoleApplication // .RespondWith(Response.Create() // .WithProxy("http://restcountries.eu")); + server + .Given(Request + .Create() + .WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true)) + .WithParam("$filter", "(substringof(Code, 'WA')") + .UsingGet()) + .RespondWith(Response.Create() + .WithBody(@"{ ""result"": ""odata""}")); + server .Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*")) .RespondWith(Response.Create() diff --git a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj index a7544994..622970d0 100644 --- a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj +++ b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj @@ -3,7 +3,7 @@ Lightweight StandAlone Http Mocking Server for .Net. WireMock.Net.StandAlone - 1.0.2.9 + 1.0.2.10 Stef Heyenrath net452;net46;netstandard1.3;netstandard2.0 true diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs index 75967481..43d3bb05 100644 --- a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs +++ b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs @@ -30,12 +30,8 @@ namespace WireMock.Matchers.Request /// /// Initializes a new instance of the class. /// - /// - /// The key. - /// - /// - /// The values. - /// + /// The key. + /// The values. public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable values) { Check.NotNull(key, nameof(key)); @@ -51,17 +47,11 @@ namespace WireMock.Matchers.Request public RequestMessageParamMatcher([NotNull] params Func>, bool>[] funcs) { Check.NotNull(funcs, nameof(funcs)); + Funcs = funcs; } - /// - /// Determines whether the specified RequestMessage is match. - /// - /// The RequestMessage. - /// The RequestMatchResult. - /// - /// A value between 0.0 - 1.0 of the similarity. - /// + /// public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) { double score = IsMatch(requestMessage); @@ -71,7 +61,9 @@ namespace WireMock.Matchers.Request private double IsMatch(RequestMessage requestMessage) { if (Funcs != null) + { return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query))); + } List values = requestMessage.GetParameter(Key); diff --git a/src/WireMock.Net/RequestMessage.cs b/src/WireMock.Net/RequestMessage.cs index 20af990a..75177ca1 100644 --- a/src/WireMock.Net/RequestMessage.cs +++ b/src/WireMock.Net/RequestMessage.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; +using System.Net; using JetBrains.Annotations; using WireMock.Util; using WireMock.Validation; -using System.Text; namespace WireMock { @@ -53,6 +54,11 @@ namespace WireMock /// public IDictionary> Query { get; } + /// + /// Gets the raw query. + /// + public string RawQuery { get; } + /// /// Gets the bodyAsBytes. /// @@ -110,7 +116,7 @@ namespace WireMock Host = url.Host; Port = url.Port; Origin = $"{url.Scheme}://{url.Host}:{url.Port}"; - Path = url.AbsolutePath; + Path = WebUtility.UrlDecode(url.AbsolutePath); Method = method.ToLower(); ClientIP = clientIP; BodyAsBytes = bodyAsBytes; @@ -118,10 +124,11 @@ namespace WireMock BodyEncoding = bodyEncoding; Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList(header.Value)); Cookies = cookies; - Query = ParseQuery(url.Query); + RawQuery = WebUtility.UrlDecode(url.Query); + Query = ParseQuery(RawQuery); } - private IDictionary> ParseQuery(string queryString) + private static IDictionary> ParseQuery(string queryString) { if (string.IsNullOrEmpty(queryString)) { @@ -153,7 +160,7 @@ namespace WireMock } /// - /// The get a query parameter. + /// Get a query parameter. /// /// The key. /// The query parameter. diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj index 6f53ed43..8ce020b0 100644 --- a/src/WireMock.Net/WireMock.Net.csproj +++ b/src/WireMock.Net/WireMock.Net.csproj @@ -3,7 +3,7 @@ Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape. WireMock.Net - 1.0.2.9 + 1.0.2.10 Alexandre Victoor;Stef Heyenrath net452;net46;netstandard1.3;netstandard2.0 true