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

handle paths containing encoded entities #233

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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