2019-01-26 13:09:48 +00:00
|
|
|
import requests
|
2019-01-28 02:29:10 +00:00
|
|
|
import os
|
2019-01-26 13:09:48 +00:00
|
|
|
|
|
|
|
# TODO - Make this configurable based on config file test section.
|
|
|
|
http_proxy = "http://127.0.0.1:8124"
|
|
|
|
|
|
|
|
def test_proxy_basic():
|
2019-01-27 16:43:32 +00:00
|
|
|
resp = requests.get("http://httpbin.org", proxies={"http": http_proxy})
|
2019-01-26 18:17:00 +00:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
2019-01-28 02:29:10 +00:00
|
|
|
def test_proxy_block_page():
|
|
|
|
for i in range(2):
|
|
|
|
requests.get("http://httpbin.org", proxies={"http": http_proxy})
|
|
|
|
assert requests.get("http://httpbin.org", proxies={"http": http_proxy}).status_code == 403
|
2019-02-13 21:26:05 +00:00
|
|
|
|
2019-02-13 21:34:56 +00:00
|
|
|
# TODO - Use a sqlite driver here to check that httpbin.org is in the blocked table.
|
|
|
|
# Or mock the sqlite client.
|
|
|
|
|
2019-02-13 21:26:05 +00:00
|
|
|
def test_blocked_file():
|
2019-02-13 21:34:56 +00:00
|
|
|
"""
|
|
|
|
Tests that the host configured to be blocked is successfully blocked.
|
|
|
|
|
|
|
|
TODO - Mock the blocked file to be used by the proxy to not have to hardcode the host.
|
|
|
|
"""
|
2019-02-13 21:26:05 +00:00
|
|
|
resp = requests.get("http://wikipedia.org", proxies={"http": http_proxy})
|
|
|
|
assert resp.status_code == 403
|
2019-01-26 13:09:48 +00:00
|
|
|
|