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

Configurable GV Mock + HMAC Auth #10623

Merged
merged 8 commits into from
May 24, 2024

Conversation

jwalz
Copy link
Collaborator

@jwalz jwalz commented May 22, 2024

Purpose

Add

  1. a configurable mock for running tests against expected GravyValet output
  2. Utilities to generate HMAC signed headers to enable OSF to bypass auth callbacks to itself

Changes

  • osf/external/gravyvalet/auth_helpers is copied almost directly from GravyValet but adds support for sending X-Requesting-User-URI, X-Requested-Resource-URI, and X-Requested-Resource-Permissions headers (and including them in the HMAC signature).
    • The only notable changes are using the official spec for date header formats and parsing headers from requests in the requests.Request format instead of the rest_framework.Request format
    • notably, no changes were required to the validate_hmac_signed_headers function to accept the new headers
  • osf/external/gravyvalet/gv_mocks implements naive versions of the top-level GravyValet entities as Dataclasses, provides utilities for configuring new entities, and provides a context manager that mocks and re-routes requests to GravyValet to retrieve these configured entities.
  • Tests

QA Notes

Please make verification statements inspired by your code and what your code touches.

  • Verify
  • Verify

What are the areas of risk?

Any concerns/considerations/questions that development raised?

Documentation

Side Effects

Ticket

@jwalz jwalz marked this pull request as ready for review May 23, 2024 20:27
Copy link
Contributor

@aaxelb aaxelb left a comment

Choose a reason for hiding this comment

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

looks good! found some nits but it took some effort -- i like how you've used dataclasses for lightweight bespoke fakery

osf/external/gravy_valet/auth_helpers.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/auth_helpers.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/gv_mocks.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/gv_mocks.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/gv_mocks.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/gv_mocks.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/gv_mocks.py Outdated Show resolved Hide resolved
osf_tests/test_gv_utils.py Outdated Show resolved Hide resolved
osf/external/gravy_valet/auth_helpers.py Outdated Show resolved Hide resolved


@dataclasses.dataclass
class _MockGVEntity:
Copy link
Contributor

Choose a reason for hiding this comment

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

naming nitpick (feel free to disregard): could be confusing to call these things "mocks", since they have nothing to do with the standard Mock interface (with assert_called and friends) -- the word's not wrong, but the collision with a standard-lib term could be misleading...

Copy link
Contributor

@aaxelb aaxelb left a comment

Choose a reason for hiding this comment

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

🤿

@jwalz jwalz merged commit 491ecab into CenterForOpenScience:develop May 24, 2024
6 checks passed
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants