Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin API: PUT Mapping, FormatException because of wrong parsing of the Query #325

Closed
andi0b opened this issue Aug 20, 2019 · 2 comments
Closed
Assignees
Labels

Comments

@andi0b
Copy link
Contributor

andi0b commented Aug 20, 2019

It sounds a bit crazy, but if you PUT a new Mapping through the Admin API you get an Exception if the GUID starts with a or d. This happens because of this line of code:

Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));

It trims away characters from the beginning, including a and d. We had flaky unit tests because of that and could't believe it in the beginning when we found that issue ;)

How to reproduce:

Start Wiremock.NET 1.0.27 with Admin API and send Request

PUT http://localhost:9981/__admin/mappings/a0000000-0000-0000-0000-000000000000 HTTP/1.1
Host: localhost:9981
User-Agent: insomnia/6.6.2
Connection: Keep-Alive
Content-Type: application/json
Accept: */*
Content-Length: 35

{
	"Request": {},
	"Response": {}
}

Then you will receive this error:

System.FormatException Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
   at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException)
   at System.Guid.TryParseGuidWithDashes(ReadOnlySpan`1 guidString, GuidResult& result)
   at System.Guid.TryParseGuid(ReadOnlySpan`1 guidString, GuidStyles flags, GuidResult& result)
   at System.Guid.Parse(ReadOnlySpan`1 input)
   at System.Guid.Parse(String input)
   at WireMock.Server.FluentMockServer.MappingPut(RequestMessage requestMessage)
   at WireMock.ResponseProviders.DynamicResponseProvider.ProvideResponseAsync(RequestMessage requestMessage, IFluentMockServerSettings settings)
   at WireMock.Mapping.ResponseToAsync(RequestMessage requestMessage)
   at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx)

because this get's excuted:

string guidString = "/__admin/mappings/a0000000-0000-0000-0000-000000000000".TrimStart("/__admin/mappings".ToCharArray());
//  guidString = "0000000-0000-0000-0000-000000000000" (the a get's trimmed away)

Guid guid = Guid.TryParse(guidString); 
// Exception

What I expect:

Put another GUID there, and it suddenly works:

PUT http://localhost:9981/__admin/mappings/b0000000-0000-0000-0000-000000000000 HTTP/1.1
Host: localhost:9981
User-Agent: insomnia/6.6.2
Connection: Keep-Alive
Content-Type: application/json
Accept: */*
Content-Length: 35

{
	"Request": {},
	"Response": {}
}

HTTP/1.1 200 OK
Date: Tue, 20 Aug 2019 11:40:49 GMT
Content-Type: application/json
Server: Kestrel
Content-Length: 37

{"Status":"Mapping added or updated"}
@StefH StefH self-assigned this Aug 20, 2019
@StefH StefH added the bug label Aug 20, 2019
@StefH
Copy link
Collaborator

StefH commented Aug 20, 2019

Good catch !
#326

@StefH
Copy link
Collaborator

StefH commented Aug 20, 2019

solved

@StefH StefH closed this as completed Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants