-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added ignore_urls support * Fix ignore_localhost and strict_mode
- Loading branch information
1 parent
de7f631
commit 68b4ae1
Showing
10 changed files
with
212 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,8 @@ erl_crash.dump | |
*.ez | ||
/tmp | ||
/_build | ||
/doc | ||
/doc | ||
.dockerignore | ||
.devcontainer | ||
Dockerfile | ||
docker-compose.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": [], | ||
"method": "get", | ||
"options": [], | ||
"request_body": "", | ||
"url": "http://localhost:34006/server" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "test_response_before", | ||
"headers": { | ||
"server": "Cowboy", | ||
"date": "Sun, 08 Apr 2018 12:50:46 GMT", | ||
"content-length": "20" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": [], | ||
"method": "get", | ||
"options": [], | ||
"request_body": "", | ||
"url": "http://127.0.0.1:34006/server" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "test_response_before", | ||
"headers": { | ||
"server": "Cowboy", | ||
"date": "Sun, 08 Apr 2018 12:50:46 GMT", | ||
"content-length": "20" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": { | ||
"User-Agent": "ExVCR" | ||
}, | ||
"method": "get", | ||
"options": [], | ||
"request_body": "", | ||
"url": "http://127.0.0.1:34006/server" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "test_response_before", | ||
"headers": { | ||
"server": "Cowboy", | ||
"date": "Tue, 20 Apr 2021 13:54:51 GMT", | ||
"content-length": "20" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
defmodule ExVCR.IgnoreUrlsTest do | ||
use ExVCR.Mock | ||
use ExUnit.Case, async: false | ||
|
||
@port 34006 | ||
@url "http://localhost:#{@port}/server" | ||
@ignore_urls [ | ||
~r/http:\/\/localhost.*/, | ||
~r/http:\/\/127\.0\.0\.1.*/ | ||
] | ||
|
||
setup_all do | ||
HTTPotion.start | ||
:ok | ||
end | ||
|
||
test "it does not record url requests when the config has been set" do | ||
use_cassette "ignore_urls_on", ignore_urls: @ignore_urls do | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_before") | ||
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/ | ||
HttpServer.stop(@port) | ||
# this method call should NOT be mocked | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_after") | ||
assert HTTPotion.get(@url, []).body =~ ~r/test_response_after/ | ||
HttpServer.stop(@port) | ||
# this method call should NOT be mocked | ||
non_localhost_url = "http://127.0.0.1:#{@port}/server" | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_after") | ||
assert HTTPotion.get(non_localhost_url, []).body =~ ~r/test_response_after/ | ||
HttpServer.stop(@port) | ||
end | ||
end | ||
|
||
test "it records urls requests when the config has not been set" do | ||
use_cassette "ignore_urls_unset" do | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_before") | ||
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/ | ||
HttpServer.stop(@port) | ||
# this method call should be mocked | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_after") | ||
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/ | ||
HttpServer.stop(@port) | ||
# this method call should NOT be mocked | ||
non_localhost_url = "http://127.0.0.1:#{@port}/server" | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_after") | ||
assert HTTPotion.get(non_localhost_url, []).body =~ ~r/test_response_before/ | ||
HttpServer.stop(@port) | ||
end | ||
end | ||
|
||
test "ignore_urls option works with request headers" do | ||
use_cassette "ignore_urls_with_headers", ignore_urls: @ignore_urls do | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_after") | ||
assert HTTPotion.get(@url, headers: ["User-Agent": "ExVCR"]).body =~ ~r/test_response_after/ | ||
HttpServer.stop(@port) | ||
# this method call should be mocked | ||
non_localhost_url = "http://127.0.0.1:#{@port}/server" | ||
HttpServer.start(path: "/server", port: @port, response: "test_response_before") | ||
assert HTTPotion.get(non_localhost_url, headers: ["User-Agent": "ExVCR"]).body =~ ~r/test_response_before/ | ||
HttpServer.stop(@port) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters