[+] add project
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Internal worker for tests/s3_failure.py; reads auth data only from stdin."""
|
||||
import json
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
|
||||
def main():
|
||||
payload = json.load(sys.stdin)
|
||||
alice = payload["alice"]
|
||||
chat = payload["chat"]
|
||||
content = bytes.fromhex(payload["fixture"])
|
||||
request = urllib.request.Request(
|
||||
"http://127.0.0.1:8080/api/v1/chats/"
|
||||
+ chat["id"]
|
||||
+ "/attachments?filename=s3-down.png",
|
||||
data=content,
|
||||
headers={
|
||||
"Authorization": "Bearer " + alice["token"],
|
||||
"Content-Type": "image/png",
|
||||
},
|
||||
method="POST",
|
||||
)
|
||||
try:
|
||||
urllib.request.urlopen(request, timeout=15)
|
||||
except urllib.error.HTTPError as response:
|
||||
if response.code != 503:
|
||||
raise AssertionError("expected HTTP 503, received " + str(response.code))
|
||||
body = json.loads(response.read())
|
||||
request_id = response.headers.get("X-Request-Id")
|
||||
if body.get("error", {}).get("code") != "unavailable":
|
||||
raise AssertionError("expected unavailable error response")
|
||||
if not request_id or body["error"].get("request_id") != request_id:
|
||||
raise AssertionError("error request ID does not match response header")
|
||||
if not response.headers.get("X-Instance-Id"):
|
||||
raise AssertionError("missing API instance ID")
|
||||
else:
|
||||
raise AssertionError("expected HTTP 503 during the S3 outage")
|
||||
print("PASS")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user