-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtest_errors.py
More file actions
71 lines (58 loc) · 2.24 KB
/
test_errors.py
File metadata and controls
71 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Test `securedrop-proxy`'s handling of errors from generic HTTP endpoints, not tied to the SecureDrop SDK."""
import os
import subprocess
def test_missing_config(proxy_bin):
env = os.environ.copy()
if "SD_PROXY_ORIGIN" in env:
del env["SD_PROXY_ORIGIN"]
result = subprocess.run([proxy_bin], env=env, capture_output=True)
assert result.returncode == 1
assert result.stderr.decode().strip() == '{"error":"environment variable not found"}'
def test_empty_input(proxy_request):
result = proxy_request(input=b"")
assert result.returncode == 1
assert (
result.stderr.decode().strip() == '{"error":"EOF while parsing a value at line 1 column 0"}'
)
def test_input_invalid(proxy_request):
test_input = b'"foo": "bar", "baz": "bliff"}'
result = proxy_request(input=test_input)
assert result.returncode == 1
assert (
result.stderr.decode().strip()
== '{"error":"invalid type: string \\"foo\\", '
+ 'expected struct IncomingRequest at line 1 column 5"}'
)
def test_input_missing_keys(proxy_request):
test_input = b'{"foo": "bar", "baz": "bliff"}'
result = proxy_request(input=test_input)
assert result.returncode == 1
assert (
result.stderr.decode().strip()
== '{"error":"unknown field `foo`, expected one of `method`, '
+ '`path_query`, `stream`, `headers`, `body`, `timeout` at line 1 column 6"}'
)
def test_invalid_origin(proxy_request):
test_input = {
"method": "GET",
"path_query": "/status/200",
"stream": False,
}
# invalid port
result = proxy_request(input=test_input, origin="http://127.0.0.1:-1/foo")
assert result.returncode == 1
assert result.stderr.decode().strip() == '{"error":"invalid port number"}'
def test_cannot_connect(proxy_request):
test_input = {
"method": "GET",
"path_query": "/",
"stream": False,
}
# .test is a reserved TLD, so it should never resolve
result = proxy_request(input=test_input, origin="http://missing.test/foo")
assert result.returncode == 1
assert (
result.stderr.decode().strip()
== '{"error":"error sending request for url (http://missing.test/): '
+ 'client error (Connect)"}'
)