-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_s3.py
204 lines (195 loc) · 6.48 KB
/
test_s3.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from uuid import uuid4
from collections import namedtuple
from tabulate import tabulate
from typing import Iterable
from proxy_testing.constants import (
LONG_TEXT,
)
from proxy_testing.datamodel import RuntimeConfig, TestResult
from proxy_testing.test_cases import (
standard_upload,
aws_chunked_upload,
http_chunked_upload,
aws_chunked_upload_with_chunked_transfer_encoding,
)
from proxy_testing.request_helpers import sha256
CONFIG = RuntimeConfig("https://localhost:8443", "testidentity", "testsecret")
TestRunner = namedtuple("TestRunner", ("callable", "args"))
STANDARD_UPLOAD_TESTS = tuple(
TestRunner(standard_upload, args)
for args in (
{"data": "some small string", "hash_data": True},
{"data": "some small string", "hash_data": False},
)
)
AWS_CHUNKED_UPLOAD_TESTS = tuple(
TestRunner(aws_chunked_upload, args)
for args in (
# Cases with the STREAMING sha256 header
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": "aws-chunked",
"add_decoded_content_length": True,
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": "aws-chunked",
"add_decoded_content_length": False,
},
)
)
HTTP_CHUNKED_TEST_CASES = tuple(
TestRunner(http_chunked_upload, args)
for args in (
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "UNSIGNED-PAYLOAD",
"add_decoded_content_length": True,
"trailer_header": None,
"trailer_header_value": None,
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "UNSIGNED-PAYLOAD",
"add_decoded_content_length": True,
"trailer_header": "x-amz-checksum-sha256",
"trailer_header_value": sha256(LONG_TEXT),
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "UNSIGNED-PAYLOAD",
"add_decoded_content_length": False,
"trailer_header": None,
"trailer_header_value": None,
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "UNSIGNED-PAYLOAD",
"add_decoded_content_length": False,
"trailer_header": "x-amz-checksum-sha256",
"trailer_header_value": sha256(LONG_TEXT),
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
"add_decoded_content_length": True,
"trailer_header": None,
"trailer_header_value": None,
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
"add_decoded_content_length": True,
"trailer_header": "x-amz-checksum-sha256",
"trailer_header_value": sha256(LONG_TEXT),
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
"add_decoded_content_length": False,
"trailer_header": None,
"trailer_header_value": None,
},
{
"data": LONG_TEXT,
"chunk_count": 3,
"content_encoding": None,
"sha256_header": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
"add_decoded_content_length": False,
"trailer_header": "x-amz-checksum-sha256",
"trailer_header_value": sha256(LONG_TEXT),
},
)
)
AWS_CHUNKED_HTTP_CHUNKED_UPLOADS = tuple(
TestRunner(aws_chunked_upload_with_chunked_transfer_encoding, args)
for args in (
{
"data": LONG_TEXT,
"aws_chunk_count": 3,
"http_chunk_count": 3,
"content_encoding": "aws-chunked",
"sha256_header": "STREAMING-AWS4-HMAC-SHA256-PAYLOAD",
"add_decoded_content_length": True,
"trailer_header": None,
"trailer_header_value": None,
},
{
"data": LONG_TEXT,
"aws_chunk_count": 3,
"http_chunk_count": 3,
"content_encoding": "aws-chunked",
"sha256_header": "STREAMING-AWS4-HMAC-SHA256-PAYLOAD",
"add_decoded_content_length": True,
"trailer_header": "x-amz-checksum-sha256",
"trailer_header_value": sha256(LONG_TEXT),
},
{
"data": LONG_TEXT,
"aws_chunk_count": 3,
"http_chunk_count": 3,
"content_encoding": "aws-chunked",
"sha256_header": "STREAMING-AWS4-HMAC-SHA256-PAYLOAD",
"add_decoded_content_length": False,
"trailer_header": None,
"trailer_header_value": None,
},
{
"data": LONG_TEXT,
"aws_chunk_count": 3,
"http_chunk_count": 3,
"content_encoding": "aws-chunked",
"sha256_header": "STREAMING-AWS4-HMAC-SHA256-PAYLOAD",
"add_decoded_content_length": False,
"trailer_header": "x-amz-checksum-sha256",
"trailer_header_value": sha256(LONG_TEXT),
},
)
)
def run_tests(
config: RuntimeConfig,
tests_and_buckets: list[tuple[str, Iterable[TestRunner]]],
):
header_text = (
"Request Content",
"Content-Length header",
"X-Amz-Decoded-Content-Length header",
"X-Amz-Content-SHA256 header",
"Transfer-Encoding header",
"Content-Encoding header",
"Result",
)
results: list[TestResult] = []
for bucket_name, test_cases in tests_and_buckets:
results.extend(
[
test_callable(config, bucket_name, uuid4().hex, **args)
for test_callable, args in test_cases
]
)
print(tabulate(results, headers=header_text))
run_tests(
CONFIG,
[
("standard-upload-proxy-tests", STANDARD_UPLOAD_TESTS),
("aws-chunked-proxy-tests", AWS_CHUNKED_UPLOAD_TESTS),
("aws-chunked-http-chunked-proxy-tests", AWS_CHUNKED_HTTP_CHUNKED_UPLOADS),
("raw-http-chunked-proxy-tests", HTTP_CHUNKED_TEST_CASES),
],
)