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

Improve error handling, tests #53

Merged
merged 4 commits into from
Jan 6, 2020
Merged

Improve error handling, tests #53

merged 4 commits into from
Jan 6, 2020

Conversation

rmol
Copy link
Contributor

@rmol rmol commented Dec 17, 2019

Description

Try to ensure the proxy always returns a valid JSON response. Add specific handling of upstream error responses to proxy.py, and add tests and fixtures for that.

Replace the Proxy._on_done static method with an instance method.

In main.py, bail out upon receiving invalid input JSON, instead of printing an error response and then continuing to try to use it, resulting in printing another error response.

Have main.py use the callbacks on the proxy as given, instead of always overwriting them with the defaults from callbacks.py.

Rework entrypoint.py so that it should always print a JSON response, and add tests for it.

Fixes #128.

Testing

  1. Build the securedrop-proxy source distribution:
    • check out this branch
    • run python setup.py sdist
  2. Build the .deb:
    • in a clone of securedrop-debian-packaging, run PKG_PATH=/home/user/src/securedrop-proxy/dist/securedrop-proxy-0.1.6.tar.gz PKG_VERSION=0.1.6 make securedrop-proxy (adjust the path to your working copy of this repo as necessary)
  3. Install the .deb in sd-svs-buster-template:
    • qvm-copy ~/debbuild/packaging/securedrop-proxy_0.1.6+buster_all.deb and specify sd-svs-buster-template as the target VM
    • In a shell on sd-svs-buster-template, run:
      • cp ~/QubesIncoming/sd-dev/securedrop-proxy_0.1.6+buster_all.deb /tmp
      • sudo apt install /tmp/securedrop-proxy_0.1.6+buster_all.deb
  4. Reboot.
  5. Start the SecureDrop client in sd-svs and confirm that the proxy is communicating with the server: submissions and replies should populate with no errors.

Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few if X is None: statements in code, we should change those to if not X:.

Code + tests look good.
The test steps need a few changes.

  • we will have to update the version to 0.1.6 and then run python3 setup.py sdist
  • Then in the debian packaging repo, we will have to add a changelog entry to securedrop-proxy/debian/changelog-buster for 0.1.6.
  • After building the debian package, we should copy it to the sd-proxy-buster-template, the test instructions have the wrong template name.

My client can not reach the server after the update to the this branch. I am currently debugging the issue. But, it is not giving much of log.

The client works as expected with this PR. From my side, after the Truth value testing code change, I will approve this one. @rmol great work. 🌈

securedrop_proxy/entrypoint.py Show resolved Hide resolved
securedrop_proxy/main.py Show resolved Hide resolved
securedrop_proxy/main.py Outdated Show resolved Hide resolved
tests/test_main.py Show resolved Hide resolved
@redshiftzero
Copy link
Contributor

let's do the version bump in another PR (@rmol had asked me about this privately and I said let's do the release separately) since nightlies will build the latest even if we don't cut an official release

@kushaldas
Copy link
Contributor

let's do the version bump in another PR (@rmol had asked me about this privately and I said let's do the release separately) since nightlies will build the latest even if we don't cut an official release

Ah, my suggestion of version bump is for the reviewer for QA, not for the actual PR.

@rmol rmol self-assigned this Dec 18, 2019
@rmol
Copy link
Contributor Author

rmol commented Dec 18, 2019

@kushaldas Thanks for the thorough review. I think I've fixed all the callback checks, and addressed the fixture mismatch for test_input_headers.


def test_cannot_connect(self):
"""
Test for "502 Bad Gateway" when the server can't be reached.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great tests! note to other reviewers that this provides regression coverage for #13

redshiftzero
redshiftzero previously approved these changes Dec 19, 2019
Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving from my end based on visual review of the diff

rmol added 2 commits January 3, 2020 14:01
Try to ensure the proxy always returns a valid JSON response. Add
specific handling of upstream error responses to proxy.py, and add
tests and fixtures for that.

Replace the Proxy._on_done static method with an instance method.

In main.py, bail out upon receiving invalid input JSON, instead of
printing an error response and then continuing to try to use it,
resulting in printing another error response.

Have main.py use the callbacks on the proxy as given, instead of
always overwriting them with the defaults from callbacks.py.

Rework entrypoint.py so that it should always print a JSON response,
and add tests for it.
Give test_main.test_input_headers its own fixture.

Use "if not callback" instead of "if callback is None".
Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All is good from my side, I am approving this, but, will still wait for someone to have a second visual check before merging.

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8cb672b and 97eed4b look good to me, tests are now passing

@kushaldas kushaldas merged commit e12b896 into master Jan 6, 2020
@kushaldas kushaldas deleted the 13-get-graceful branch January 6, 2020 16:23
@rmol rmol mentioned this pull request Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[securedrop-proxy] gracefully handle connection failures
4 participants