| 1 | # Mock S3 server |
| 2 | |
| 3 | A **NON-TLS** mock S3 server based on [python-hyper/h11](https://github.com/python-hyper/h11) and [trio](http://trio.readthedocs.io/en/latest/index.html). The server code implementation is based on the trio-server example from python-hyper/h11 [here](https://github.com/python-hyper/h11/blob/master/examples/trio-server.py). Only supports very basic mock response for request received. |
| 4 | |
| 5 | ## How to run the server |
| 6 | |
| 7 | Python 3.7+ required. |
| 8 | |
| 9 | - Install hyper/h11 and trio python module. `python3 -m pip install h11 trio` |
| 10 | - Run python. `python3 ./mock_s3_server.py`. |
| 11 | |
| 12 | ### Supported Operations |
| 13 | |
| 14 | - CreateMultipartUpload |
| 15 | - CompleteMultipartUpload |
| 16 | - UploadPart |
| 17 | - AbortMultipartUpload |
| 18 | - GetObject |
| 19 | |
| 20 | ### Defined response |
| 21 | |
| 22 | The server will read from ./{OperationName}/{Key}.json. The json file is formatted as following: |
| 23 | |
| 24 | ```json |
| 25 | { |
| 26 | "status": 200, |
| 27 | "headers": {"Connection": "close"}, |
| 28 | "request_headers:" {"HeaderA": "ValueA"} |
| 29 | "body": [ |
| 30 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", |
| 31 | "", |
| 32 | "<Error>", |
| 33 | "<Code>InternalError</Code>", |
| 34 | "<Message>We encountered an internal error. Please try again.</Message>", |
| 35 | "<RequestId>656c76696e6727732072657175657374</RequestId>", |
| 36 | "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>", |
| 37 | "</Error>" |
| 38 | ] |
| 39 | } |
| 40 | ``` |
| 41 | |
| 42 | Where you can define the expected response status, header and response body. If the {Key}.json is not found from file system, it will load the `default.json`. |
| 43 | |
| 44 | The server validates that all specified headers in the "request_headers" field are present in the incoming request. If any required header is missing, the request will fail. These headers will not be part of the Response headers. |
| 45 | If the "delay" field is present, the response will be delayed by X seconds. |
| 46 | |
| 47 | ### GetObject Response |
| 48 | |
| 49 | By default, the GetObject response will read from ./{OperationName}/{Key}.json for the status and headers. But the body will be generated to match the range in the request. |
| 50 | |
| 51 | To proper handle ranged GetObject, you will need to modify the mock server code. Check function `handle_get_object` for details. |