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

Add tests for relative and absolute redirect with a proxy #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ otp_release:
before_script:
- "./support/bootstrap_travis.sh"
- "gunicorn httpbin:app&"
- "mitmdump -p 8001&"
before_install:
- sudo pip install -q httpbin
- sudo pip install -q gunicorn
- sudo pip install -q mitmproxy
script: './rebar3 eunit --dir="test"'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,22 +494,23 @@ $ rebar3 compile
```

For successfully running the hackney test suite locally it is necessary to
install [httpbin](https://pypi.python.org/pypi/httpbin/0.2.0).
install [httpbin](https://pypi.python.org/pypi/httpbin/0.2.0) and [mitmproxy](https://pypi.python.org/pypi/mitmproxy).

An example installation using virtualenv::

```sh

$ mkvirtualenv hackney
$ pip install gunicorn httpbin
$ pip install gunicorn httpbin mitmproxy

```

Running the tests:

```
$ mitmdump -p 8001
$ gunicorn --daemon --pid httpbin.pid httpbin:app
$ make test
$ rebar3 eunit --dir="test"
$ kill `cat httpbin.pid`
```

Expand Down
18 changes: 18 additions & 0 deletions test/hackney_integration_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ http_requests_test_() ->
send_cookies_request(),
absolute_redirect_request_no_follow(),
absolute_redirect_request_follow(),
absolute_redirect_request_follow_with_proxy(),
relative_redirect_request_no_follow(),
relative_redirect_request_follow(),
relative_redirect_request_follow_with_proxy(),
async_request(),
async_head_request(),
async_no_content_request()]}
Expand Down Expand Up @@ -100,6 +102,14 @@ absolute_redirect_request_follow() ->
[?_assertEqual(200, StatusCode),
?_assertEqual(<<"http://localhost:8000/get">>, Location)].

absolute_redirect_request_follow_with_proxy() ->
URL = <<"http://localhost:8000/redirect-to?url=http://localhost:8000/get">>,
Options = [{follow_redirect, true}, {proxy, "http://localhost:8001"}],
{ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
Location = hackney:location(Client),
[?_assertEqual(200, StatusCode),
?_assertEqual(<<"http://localhost:8000/get">>, Location)].

relative_redirect_request_no_follow() ->
URL = <<"http://localhost:8000/relative-redirect/1">>,
Options = [{follow_redirect, false}],
Expand All @@ -116,6 +126,14 @@ relative_redirect_request_follow() ->
[?_assertEqual(200, StatusCode),
?_assertEqual(<<"/get">>, Location)].

relative_redirect_request_follow_with_proxy() ->
URL = <<"http://localhost:8000/relative-redirect/1">>,
Options = [{follow_redirect, true}, {proxy, "http://localhost:8001"}],
{ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
Location = hackney:location(Client),
[?_assertEqual(200, StatusCode),
?_assertEqual(<<"/get">>, Location)].

async_request() ->
URL = <<"http://localhost:8000/get">>,
Options = [async],
Expand Down