Skip to content

Commit

Permalink
Merge pull request #233 from Thiht/issue-232
Browse files Browse the repository at this point in the history
handle paths containing encoded entities
  • Loading branch information
Thiht authored Dec 13, 2021
2 parents 8d61d0d + f3ebd4b commit 0a15cb6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 47 deletions.
2 changes: 1 addition & 1 deletion server/types/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func HTTPRequestToRequest(req *http.Request) Request {
}
headers.Add("Host", req.Host)
return Request{
Path: req.URL.Path,
Path: req.URL.EscapedPath(),
Method: req.Method,
Origin: getOrigin(req),
Body: body,
Expand Down
13 changes: 13 additions & 0 deletions tests/data/basic_mock_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
Content-Type: application/json
body: >
{"message": "test"}
- request:
path: /encoded%2Fpath
response:
headers:
Content-Type: application/json
body: >
{"message": "encoded path"}
- request:
path: /test
method: POST
Expand All @@ -14,6 +23,7 @@
body: >
{"message": "test2"}
delay: 10ms

- request:
path: /test
method: DELETE
Expand All @@ -25,6 +35,7 @@
delay:
min: 0ms
max: 10ms

- request:
path: /test
query_params:
Expand All @@ -34,6 +45,7 @@
Content-Type: application/json
body: >
{"message": "test4"}
- request:
path: /test
headers:
Expand All @@ -43,6 +55,7 @@
Content-Type: application/json
body: >
{"message": "test5"}
- request:
path: /test
headers:
Expand Down
43 changes: 17 additions & 26 deletions tests/features/set_mocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ testcases:
steps:
- type: http
method: POST
url: http://localhost:8081/reset
- type: http
method: POST
url: http://localhost:8081/mocks
url: http://localhost:8081/mocks?reset=true
headers:
Content-Type: "application/x-yaml"
bodyFile: ../data/basic_mock.yml
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.message ShouldEqual "Mocks registered successfully"

- type: http
method: GET
url: http://localhost:8081/mocks
Expand All @@ -26,6 +24,7 @@ testcases:
vars:
mock_id:
from: result.bodyjson.bodyjson0.state.id

- type: http
method: GET
url: http://localhost:8081/mocks?id={{.AddBasicMock.mock_id}}
Expand All @@ -38,22 +37,20 @@ testcases:
steps:
- type: http
method: POST
url: http://localhost:8081/reset
- type: http
method: POST
url: http://localhost:8081/mocks
url: http://localhost:8081/mocks?reset=true
headers:
Content-Type: "application/x-yaml"
bodyFile: ../data/basic_mock_list.yml
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.message ShouldEqual "Mocks registered successfully"

- type: http
method: GET
url: http://localhost:8081/mocks
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.__len__ ShouldEqual 6
- result.bodyjson.__len__ ShouldEqual 7

# Mocks are stored as a stack
- result.bodyjson.bodyjson5.request.method.value ShouldEqual .*
Expand All @@ -67,24 +64,24 @@ testcases:
steps:
- type: http
method: POST
url: http://localhost:8081/reset
- type: http
method: POST
url: http://localhost:8081/mocks
url: http://localhost:8081/mocks?reset=true
bodyFile: ../data/basic_mock_list.yml
assertions:
- result.statuscode ShouldEqual 200

- type: http
method: GET
url: http://localhost:8081/mocks
assertions:
- result.bodyjson.__len__ ShouldEqual 6
- result.bodyjson.__len__ ShouldEqual 7

- type: http
method: POST
url: http://localhost:8081/mocks?reset=true
bodyFile: ../data/basic_mock.yml
assertions:
- result.statuscode ShouldEqual 200

- type: http
method: GET
url: http://localhost:8081/mocks
Expand All @@ -95,16 +92,14 @@ testcases:
steps:
- type: http
method: POST
url: http://localhost:8081/reset
- type: http
method: POST
url: http://localhost:8081/mocks
url: http://localhost:8081/mocks?reset=true
headers:
Content-Type: "application/x-yaml"
bodyFile: ../data/matcher_mock_list.yml
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.message ShouldEqual "Mocks registered successfully"

- type: http
method: GET
url: http://localhost:8081/mocks
Expand All @@ -128,16 +123,14 @@ testcases:
steps:
- type: http
method: POST
url: http://localhost:8081/reset
- type: http
method: POST
url: http://localhost:8081/mocks
url: http://localhost:8081/mocks?reset=true
headers:
Content-Type: "application/x-yaml"
bodyFile: ../data/dynamic_mock_list.yml
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.message ShouldEqual "Mocks registered successfully"

- type: http
method: GET
url: http://localhost:8081/mocks
Expand All @@ -155,16 +148,14 @@ testcases:
steps:
- type: http
method: POST
url: http://localhost:8081/reset
- type: http
method: POST
url: http://localhost:8081/mocks
url: http://localhost:8081/mocks?reset=true
headers:
Content-Type: "application/x-yaml"
bodyFile: ../data/proxy_mock_list.yml
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.message ShouldEqual "Mocks registered successfully"

- type: http
method: GET
url: http://localhost:8081/mocks
Expand Down
Loading

0 comments on commit 0a15cb6

Please sign in to comment.