-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
ProxyAndRecord does not save query-parameters, headers and body #57
Comments
Which version do you use? And can you post the client c# code or json? |
I am using the latest version. I just created a console app and trying to record the requests. I am able to record the requests for get calls. But not able to do it for post/put/delete calls. C# code is just a console application with above code in the main method. |
Ok. The latest code from yesterday should fix some issues with headers. However I am not sure I ever tested something else then GET... Will have to check. |
I update the binaries. Looks like the issue for me is fixed. Thank you for the prompt response. |
Please double check and close this issue if possible. |
This has regressed with some other issues. Now the mappings which are made from code are not getting recognized at all. Example
With the above code, if I run http://localhost:1111/with/get is returning HttpStatusCode 410 with the response of proxy url. This was working fine. This works fine when we put the same settings in the mapping json file. Also when the recording of the above happens and we update the response body, a new mapping file will gets created with the older result rather than picking it from the updated once. Even this was working well before this latest code changes. @StefH . |
I used latest code, and used you code example above. The json file generated looks like: {
"Guid": "791a3f31-6946-4ce7-8e6f-0237c7443275",
"Title": "",
"Priority": 0,
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/proxy-google-test-post"
}
]
},
"Methods": [
"post"
],
"Body": {}
},
"Response": {
"StatusCode": 404,
"Body": "<!DOCTYPE html>\n<html lang=en>\n <meta charset=utf-8>\n <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n <title>Error 404 (Not Found)!!1</title>\n <style>\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n </style>\n <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n <p><b>404.</b> <ins>That’s an error.</ins>\n <p>The requested URL <code>/proxy-google-test-post</code> was not found on this server. <ins>That’s all we know.</ins>\n",
"BodyAsBytes": "PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ZW4+CiAgPG1ldGEgY2hhcnNldD11dGYtOD4KICA8bWV0YSBuYW1lPXZpZXdwb3J0IGNvbnRlbnQ9ImluaXRpYWwtc2NhbGU9MSwgbWluaW11bS1zY2FsZT0xLCB3aWR0aD1kZXZpY2Utd2lkdGgiPgogIDx0aXRsZT5FcnJvciA0MDQgKE5vdCBGb3VuZCkhITE8L3RpdGxlPgogIDxzdHlsZT4KICAgICp7bWFyZ2luOjA7cGFkZGluZzowfWh0bWwsY29kZXtmb250OjE1cHgvMjJweCBhcmlhbCxzYW5zLXNlcmlmfWh0bWx7YmFja2dyb3VuZDojZmZmO2NvbG9yOiMyMjI7cGFkZGluZzoxNXB4fWJvZHl7bWFyZ2luOjclIGF1dG8gMDttYXgtd2lkdGg6MzkwcHg7bWluLWhlaWdodDoxODBweDtwYWRkaW5nOjMwcHggMCAxNXB4fSogPiBib2R5e2JhY2tncm91bmQ6dXJsKC8vd3d3Lmdvb2dsZS5jb20vaW1hZ2VzL2Vycm9ycy9yb2JvdC5wbmcpIDEwMCUgNXB4IG5vLXJlcGVhdDtwYWRkaW5nLXJp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JSAxMDAlfX0jbG9nb3tkaXNwbGF5OmlubGluZS1ibG9jaztoZWlnaHQ6NTRweDt3aWR0aDoxNTBweH0KICA8L3N0eWxlPgogIDxhIGhyZWY9Ly93d3cuZ29vZ2xlLmNvbS8+PHNwYW4gaWQ9bG9nbyBhcmlhLWxhYmVsPUdvb2dsZT48L3NwYW4+PC9hPgogIDxwPjxiPjQwNC48L2I+IDxpbnM+VGhhdOKAmXMgYW4gZXJyb3IuPC9pbnM+CiAgPHA+VGhlIHJlcXVlc3RlZCBVUkwgPGNvZGU+L3Byb3h5LWdvb2dsZS10ZXN0LXBvc3Q8L2NvZGU+IHdhcyBub3QgZm91bmQgb24gdGhpcyBzZXJ2ZXIuICA8aW5zPlRoYXTigJlzIGFsbCB3ZSBrbm93LjwvaW5zPgo=",
"BodyEncoding": {
"CodePage": 65001,
"EncodingName": "Unicode (UTF-8)",
"WebName": "utf-8"
},
"UseTransformer": false,
"Headers": {
"Date": "Wed, 25 Oct 2017 18:57:40 GMT",
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"39,38,37,35\"",
"Referrer-Policy": "no-referrer",
"Connection": "close"
}
}
} And this file can be use fine as a static mapping. So can you please help me by providing the steps you take? |
So now you have the above json, just update the response status code and response body to something else. Then make the same call again, ideally, you should get this request matching and the updated response should be returned. Did you give a try for the coded part of mapping??. If you run the same request again, it is creating a new mapping. It should not be creating a new mapping right if the request matches the mappings which is saved in the json @StefH |
Ah. Maybe I understand you problem: When WireMock is in Proxy-mode (ProxyAndRecordSettings defined), it can only be used for that purpose. The idea is that when you are done proying & recording, you must start and use WireMock in a normal way. |
Got it. But in the post call, when we pass some post data either as plain text/form data, this is not getting recorded. Is there anything I am missing? You can try this with the above code by calling it as an API with some post body in postman. |
When WireMock is in proxy-mode, only the response from the real service (which is proxied) is recorded in a .json file. What you want is that in case of a body (POST,PUT,PATCH), the Request matcher is defined so that when you send exactly the same request, WireMock will only then return the recorded response. This is not yet build. I will take a look. |
@Dreamescaper maybe you also have a clever idea here? |
@StefH did you get to see why the post body is not getting recorded in the request? |
I have an idea why this fails. However I dont have the solution at this moment. |
@StefH even the query string parameters are not getting recorded. Not sure this has been noticed. |
ProxyAndRecord does not save query-parameters, headers and body (#57)
Code is fixed. You can take a look here : e25c873 If this is correct, I can create a new NuGet. |
I will build the solution in my local and let you know if this working fine. |
I was able to build the solution and see that body and params are getting saved in the mapping file. But this fix has created few other issues. Every time it checks for an exact match in the headers list. Using C# code we cannot do a check if request header list contains required headers, then match the pattern. The same is applicable for the static mappings too.
In the above code, when we invoke the API with post method in postman, it always checks for all the possible headers and also in exact match pattern. Postman generated a token by itself this will keep recording a new mapping. If we remove few headers from the list, it makes an exact match to the list also. Cannot we skip this to make headers contains? @StefH |
1] 2] |
1] Code has been changed into |
@StefH as the header/params/cookie are array of entries, do you think it will make easy if we just have exact match or pattern match for these attributes? Should we not have contains in the array kind of search, where the pattern can be considered as a match when we have that one entry of the header/params/cookies among the list. I guess this will make this tool more flexible. |
The generated mapping is like: "Headers": [
{
"Name": "Cache-Control",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "no-cache"
}
]
},
{
"Name": "User-Agent",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "PostmanRuntime/6.4.1"
}
]
},
{
"Name": "StefTest",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "true"
}
]
}
] So by default If you don't want to match on User-Agent, just delete that block. "Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "*"
}
] |
Clear for you @raghavendrabankapur ? |
Looks good I guess. Let me check if it's working as the way I was expecting. |
@raghavendrabankapur : closing this one. If you still have issues, just open a new issue. |
When we try to record a request with HttpMethod as post, then we are getting error as below. Can someone please help me if I am missing anything.
I am starting server as below
Error is as below. But when I create a static mapping for the above serevr with Post as method then it works fine. Seeing the below issue only when we try to record it.
The text was updated successfully, but these errors were encountered: