From e2e9bf3ebed4a4803d45d984ad1466cf47419a07 Mon Sep 17 00:00:00 2001 From: John Hensley Date: Wed, 18 Dec 2019 10:45:04 -0500 Subject: [PATCH] Address review Give test_main.test_input_headers its own fixture. Use "if not callback" instead of "if callback is None". --- fixtures/main_input_headers.yaml | 94 ++++++++++++++++++++++++++++++++ securedrop_proxy/main.py | 2 +- securedrop_proxy/proxy.py | 2 +- tests/test_main.py | 2 +- 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 fixtures/main_input_headers.yaml diff --git a/fixtures/main_input_headers.yaml b/fixtures/main_input_headers.yaml new file mode 100644 index 0000000..606bfa7 --- /dev/null +++ b/fixtures/main_input_headers.yaml @@ -0,0 +1,94 @@ +interactions: +- request: + body: null + headers: + X-Test-Header: + - th + method: GET + uri: https://jsonplaceholder.typicode.com/posts?userId=1 + response: + body: + string: "[\n {\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut\ + \ facere repellat provident occaecati excepturi optio reprehenderit\",\n \ + \ \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita\ + \ et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem\ + \ sunt rem eveniet architecto\"\n },\n {\n \"userId\": 1,\n \"id\"\ + : 2,\n \"title\": \"qui est esse\",\n \"body\": \"est rerum tempore\ + \ vitae\\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\\nfugiat\ + \ blanditiis voluptate porro vel nihil molestiae ut reiciendis\\nqui aperiam\ + \ non debitis possimus qui neque nisi nulla\"\n },\n {\n \"userId\":\ + \ 1,\n \"id\": 3,\n \"title\": \"ea molestias quasi exercitationem repellat\ + \ qui ipsa sit aut\",\n \"body\": \"et iusto sed quo iure\\nvoluptatem\ + \ occaecati omnis eligendi aut ad\\nvoluptatem doloribus vel accusantium quis\ + \ pariatur\\nmolestiae porro eius odio et labore et velit aut\"\n },\n {\n\ + \ \"userId\": 1,\n \"id\": 4,\n \"title\": \"eum et est occaecati\"\ + ,\n \"body\": \"ullam et saepe reiciendis voluptatem adipisci\\nsit amet\ + \ autem assumenda provident rerum culpa\\nquis hic commodi nesciunt rem tenetur\ + \ doloremque ipsam iure\\nquis sunt voluptatem rerum illo velit\"\n },\n\ + \ {\n \"userId\": 1,\n \"id\": 5,\n \"title\": \"nesciunt quas odio\"\ + ,\n \"body\": \"repudiandae veniam quaerat sunt sed\\nalias aut fugiat\ + \ sit autem sed est\\nvoluptatem omnis possimus esse voluptatibus quis\\nest\ + \ aut tenetur dolor neque\"\n },\n {\n \"userId\": 1,\n \"id\": 6,\n\ + \ \"title\": \"dolorem eum magni eos aperiam quia\",\n \"body\": \"\ + ut aspernatur corporis harum nihil quis provident sequi\\nmollitia nobis aliquid\ + \ molestiae\\nperspiciatis et ea nemo ab reprehenderit accusantium quas\\\ + nvoluptate dolores velit et doloremque molestiae\"\n },\n {\n \"userId\"\ + : 1,\n \"id\": 7,\n \"title\": \"magnam facilis autem\",\n \"body\"\ + : \"dolore placeat quibusdam ea quo vitae\\nmagni quis enim qui quis quo nemo\ + \ aut saepe\\nquidem repellat excepturi ut quia\\nsunt ut sequi eos ea sed\ + \ quas\"\n },\n {\n \"userId\": 1,\n \"id\": 8,\n \"title\": \"\ + dolorem dolore est ipsam\",\n \"body\": \"dignissimos aperiam dolorem qui\ + \ eum\\nfacilis quibusdam animi sint suscipit qui sint possimus cum\\nquaerat\ + \ magni maiores excepturi\\nipsam ut commodi dolor voluptatum modi aut vitae\"\ + \n },\n {\n \"userId\": 1,\n \"id\": 9,\n \"title\": \"nesciunt\ + \ iure omnis dolorem tempora et accusantium\",\n \"body\": \"consectetur\ + \ animi nesciunt iure dolore\\nenim quia ad\\nveniam autem ut quam aut nobis\\\ + net est aut quod aut provident voluptas autem voluptas\"\n },\n {\n \"\ + userId\": 1,\n \"id\": 10,\n \"title\": \"optio molestias id quia eum\"\ + ,\n \"body\": \"quo et expedita modi cum officia vel magni\\ndoloribus\ + \ qui repudiandae\\nvero nisi sit\\nquos veniam quod sed accusamus veritatis\ + \ error\"\n }\n]" + headers: + Access-Control-Allow-Credentials: + - 'true' + Age: + - '1789' + CF-Cache-Status: + - HIT + CF-RAY: + - 54722d954de5e0ea-IAD + Cache-Control: + - max-age=14400 + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 18 Dec 2019 15:30:26 GMT + Etag: + - W/"aa6-j2NSH739l9uq40OywFMn7Y0C/iY" + Expect-CT: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Expires: + - '-1' + Pragma: + - no-cache + Server: + - cloudflare + Set-Cookie: + - __cfduid=d21e159ad4987bc5ba9d781aed2f9db5c1576683026; expires=Fri, 17-Jan-20 + 15:30:26 GMT; path=/; domain=.typicode.com; HttpOnly; SameSite=Lax + Transfer-Encoding: + - chunked + Vary: + - Origin, Accept-Encoding + Via: + - 1.1 vegur + X-Content-Type-Options: + - nosniff + X-Powered-By: + - Express + status: + code: 200 + message: OK +version: 1 diff --git a/securedrop_proxy/main.py b/securedrop_proxy/main.py index 8986449..e67f158 100644 --- a/securedrop_proxy/main.py +++ b/securedrop_proxy/main.py @@ -39,6 +39,6 @@ def __main__(incoming, p): req.body = client_req['body'] p.req = req - if p.on_save is None: + if not p.on_save: p.on_save = callbacks.on_save p.proxy() diff --git a/securedrop_proxy/proxy.py b/securedrop_proxy/proxy.py index 59a9a3a..dcdcbc0 100644 --- a/securedrop_proxy/proxy.py +++ b/securedrop_proxy/proxy.py @@ -135,7 +135,7 @@ def handle_response(self): def proxy(self): try: - if self.on_save is None: + if not self.on_save: self.simple_error( http.HTTPStatus.BAD_REQUEST, "Request on_save callback is not set." ) diff --git a/tests/test_main.py b/tests/test_main.py index 1c49461..0559518 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -124,7 +124,7 @@ def on_done(res): with self.assertRaises(SystemExit): main.__main__(test_input_json, p) - @vcr.use_cassette('fixtures/main_json_response.yaml') + @vcr.use_cassette('fixtures/main_input_headers.yaml') def test_input_headers(self): test_input = { "method": "GET",