Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teach vcrpy our proxy v2 request/response semantics #1778

Closed
cfm opened this issue Jan 24, 2024 · 4 comments · Fixed by #1718
Closed

teach vcrpy our proxy v2 request/response semantics #1778

cfm opened this issue Jan 24, 2024 · 4 comments · Fixed by #1718
Assignees
Labels

Comments

@cfm
Copy link
Member

cfm commented Jan 24, 2024

Tests need fixing, they're currently using vcr. We either need to reimplement vcr for our mock format or mock the proxying to use requests and then keep using vcr.

Originally posted by @legoktm in #1718 (comment)

@cfm cfm changed the title teach vcrpry our request/response semantics teach vcrpry our proxy v2 request/response semantics Jan 24, 2024
@cfm
Copy link
Member Author

cfm commented Jan 24, 2024

We know that requests look like:

if method == "POST" and body:
data["body"] = body
if headers:
data["headers"] = headers
if timeout:
data["timeout"] = timeout
data_str = json.dumps(data).encode()

And responses look like either of:

@dataclass(frozen=True)
class StreamedResponse:
contents: bytes
sha256sum: str
filename: str
@dataclass(frozen=True)
class JSONResponse:
data: dict
status: int
headers: Dict[str, str]

So, working backwards:

  1. we have an obvious custom persister; and
  2. we need to hook vcrpy itself into sdk._send_json_request().

@cfm cfm changed the title teach vcrpry our proxy v2 request/response semantics teach vcrpy our proxy v2 request/response semantics Jan 24, 2024
@cfm
Copy link
Member Author

cfm commented Jan 31, 2024

This is well underway in proxy-rusting, where VCR.py is able to de/serialize our new {JSON,Streamed}Responses without any further intervention on our part. The interesting bits are f3a5c5a...4763792.

Next up is to deduplicate test_apiproxy.py and test_api.py, which are redundant now that we intend for the SDK to always use the proxy.

@cfm
Copy link
Member Author

cfm commented Feb 2, 2024

This is implemented in f3a5c5a...b82720b. The diffstat looks horrific (99 files changed, 14113 insertions(+), 5595 deletions(-) because a bunch of one-line JSON fixtures are now multi-line YAML fixtures. There are still fewer of them—50% fewer, in fact, in a single converged test path instead of two.

Commits are marked [WIP] because there are two subtleties in the VCR.py instrumentation of securedrop_client.sdk.API._send_json_request() that I should document.

@cfm
Copy link
Member Author

cfm commented Feb 6, 2024

This will be reviewed as part of #1718.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants