Skip to content

Commit 0a15cb6

Browse files
authored
Merge pull request #233 from Thiht/issue-232
handle paths containing encoded entities
2 parents 8d61d0d + f3ebd4b commit 0a15cb6

File tree

4 files changed

+73
-47
lines changed

4 files changed

+73
-47
lines changed

server/types/history.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func HTTPRequestToRequest(req *http.Request) Request {
7878
}
7979
headers.Add("Host", req.Host)
8080
return Request{
81-
Path: req.URL.Path,
81+
Path: req.URL.EscapedPath(),
8282
Method: req.Method,
8383
Origin: getOrigin(req),
8484
Body: body,

tests/data/basic_mock_list.yml

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
Content-Type: application/json
66
body: >
77
{"message": "test"}
8+
9+
- request:
10+
path: /encoded%2Fpath
11+
response:
12+
headers:
13+
Content-Type: application/json
14+
body: >
15+
{"message": "encoded path"}
16+
817
- request:
918
path: /test
1019
method: POST
@@ -14,6 +23,7 @@
1423
body: >
1524
{"message": "test2"}
1625
delay: 10ms
26+
1727
- request:
1828
path: /test
1929
method: DELETE
@@ -25,6 +35,7 @@
2535
delay:
2636
min: 0ms
2737
max: 10ms
38+
2839
- request:
2940
path: /test
3041
query_params:
@@ -34,6 +45,7 @@
3445
Content-Type: application/json
3546
body: >
3647
{"message": "test4"}
48+
3749
- request:
3850
path: /test
3951
headers:
@@ -43,6 +55,7 @@
4355
Content-Type: application/json
4456
body: >
4557
{"message": "test5"}
58+
4659
- request:
4760
path: /test
4861
headers:

tests/features/set_mocks.yml

+17-26
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ testcases:
55
steps:
66
- type: http
77
method: POST
8-
url: http://localhost:8081/reset
9-
- type: http
10-
method: POST
11-
url: http://localhost:8081/mocks
8+
url: http://localhost:8081/mocks?reset=true
129
headers:
1310
Content-Type: "application/x-yaml"
1411
bodyFile: ../data/basic_mock.yml
1512
assertions:
1613
- result.statuscode ShouldEqual 200
1714
- result.bodyjson.message ShouldEqual "Mocks registered successfully"
15+
1816
- type: http
1917
method: GET
2018
url: http://localhost:8081/mocks
@@ -26,6 +24,7 @@ testcases:
2624
vars:
2725
mock_id:
2826
from: result.bodyjson.bodyjson0.state.id
27+
2928
- type: http
3029
method: GET
3130
url: http://localhost:8081/mocks?id={{.AddBasicMock.mock_id}}
@@ -38,22 +37,20 @@ testcases:
3837
steps:
3938
- type: http
4039
method: POST
41-
url: http://localhost:8081/reset
42-
- type: http
43-
method: POST
44-
url: http://localhost:8081/mocks
40+
url: http://localhost:8081/mocks?reset=true
4541
headers:
4642
Content-Type: "application/x-yaml"
4743
bodyFile: ../data/basic_mock_list.yml
4844
assertions:
4945
- result.statuscode ShouldEqual 200
5046
- result.bodyjson.message ShouldEqual "Mocks registered successfully"
47+
5148
- type: http
5249
method: GET
5350
url: http://localhost:8081/mocks
5451
assertions:
5552
- result.statuscode ShouldEqual 200
56-
- result.bodyjson.__len__ ShouldEqual 6
53+
- result.bodyjson.__len__ ShouldEqual 7
5754

5855
# Mocks are stored as a stack
5956
- result.bodyjson.bodyjson5.request.method.value ShouldEqual .*
@@ -67,24 +64,24 @@ testcases:
6764
steps:
6865
- type: http
6966
method: POST
70-
url: http://localhost:8081/reset
71-
- type: http
72-
method: POST
73-
url: http://localhost:8081/mocks
67+
url: http://localhost:8081/mocks?reset=true
7468
bodyFile: ../data/basic_mock_list.yml
7569
assertions:
7670
- result.statuscode ShouldEqual 200
71+
7772
- type: http
7873
method: GET
7974
url: http://localhost:8081/mocks
8075
assertions:
81-
- result.bodyjson.__len__ ShouldEqual 6
76+
- result.bodyjson.__len__ ShouldEqual 7
77+
8278
- type: http
8379
method: POST
8480
url: http://localhost:8081/mocks?reset=true
8581
bodyFile: ../data/basic_mock.yml
8682
assertions:
8783
- result.statuscode ShouldEqual 200
84+
8885
- type: http
8986
method: GET
9087
url: http://localhost:8081/mocks
@@ -95,16 +92,14 @@ testcases:
9592
steps:
9693
- type: http
9794
method: POST
98-
url: http://localhost:8081/reset
99-
- type: http
100-
method: POST
101-
url: http://localhost:8081/mocks
95+
url: http://localhost:8081/mocks?reset=true
10296
headers:
10397
Content-Type: "application/x-yaml"
10498
bodyFile: ../data/matcher_mock_list.yml
10599
assertions:
106100
- result.statuscode ShouldEqual 200
107101
- result.bodyjson.message ShouldEqual "Mocks registered successfully"
102+
108103
- type: http
109104
method: GET
110105
url: http://localhost:8081/mocks
@@ -128,16 +123,14 @@ testcases:
128123
steps:
129124
- type: http
130125
method: POST
131-
url: http://localhost:8081/reset
132-
- type: http
133-
method: POST
134-
url: http://localhost:8081/mocks
126+
url: http://localhost:8081/mocks?reset=true
135127
headers:
136128
Content-Type: "application/x-yaml"
137129
bodyFile: ../data/dynamic_mock_list.yml
138130
assertions:
139131
- result.statuscode ShouldEqual 200
140132
- result.bodyjson.message ShouldEqual "Mocks registered successfully"
133+
141134
- type: http
142135
method: GET
143136
url: http://localhost:8081/mocks
@@ -155,16 +148,14 @@ testcases:
155148
steps:
156149
- type: http
157150
method: POST
158-
url: http://localhost:8081/reset
159-
- type: http
160-
method: POST
161-
url: http://localhost:8081/mocks
151+
url: http://localhost:8081/mocks?reset=true
162152
headers:
163153
Content-Type: "application/x-yaml"
164154
bodyFile: ../data/proxy_mock_list.yml
165155
assertions:
166156
- result.statuscode ShouldEqual 200
167157
- result.bodyjson.message ShouldEqual "Mocks registered successfully"
158+
168159
- type: http
169160
method: GET
170161
url: http://localhost:8081/mocks

0 commit comments

Comments
 (0)