Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
Give test_main.test_input_headers its own fixture.

Use "if not callback" instead of "if callback is None".
  • Loading branch information
rmol committed Dec 18, 2019
1 parent 3cd657f commit 5097c2c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
94 changes: 94 additions & 0 deletions fixtures/main_input_headers.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion securedrop_proxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion securedrop_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5097c2c

Please sign in to comment.