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

Canonical json form for signed responses #3035

Merged
merged 10 commits into from
Nov 15, 2023

Conversation

michellemounde
Copy link
Contributor

Fixes #1112

  1. Add canonicaljson dependency to requirements
  2. Replace response json implementation with canonicaljson implementation

@michellemounde michellemounde changed the title Canonical json responses Canonical json form for signed responses Oct 25, 2023
Copy link
Contributor

@bhearsum bhearsum left a comment

Choose a reason for hiding this comment

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

I know this is still just a draft, but I just want to note that we'll want one or more tests for this in https://github.com/mozilla-releng/balrog/blob/main/tests/web/test_json.py.

Also, if you need a hand with updating the requirements please let me know. Running maintenance/pin.sh should do it though.

@michellemounde michellemounde force-pushed the canonical-json-responses branch from 3155b23 to 2b6a725 Compare November 2, 2023 15:27
@michellemounde
Copy link
Contributor Author

@bhearsum I have a question. The canonical JSON tests are passing but they are also passing when I just use JSON.

Should I also test for the signature in this case? I am not sure if I should do this or if it would just give the same result.

I tried mocking a unique signature for the test cases but I still got the same signature because I don't know how to pass a non-null content to:

def get_content_signature_headers(content, product):

Copy link
Contributor

@bhearsum bhearsum left a comment

Choose a reason for hiding this comment

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

@bhearsum I have a question. The canonical JSON tests are passing but they are also passing when I just use JSON.

I left a comment below about this.

Should I also test for the signature in this case? I am not sure if I should do this or if it would just give the same result.

No - don't worry about the signature or any other headers here. It's out of scope for these new tests.

)
def testGuardianResponseWithCanonicalJson(client, version, buildTarget, channel, code, response):
ret1 = client.get(f"/json/1/Guardian/{version}/{buildTarget}/{channel}/update.json")
ret2 = client.get(f"/json/1/Guardian/{version}/{buildTarget}/{channel}/update.json")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not entirely certain what you're testing here. You seem to make making the same request twice, and asserting that the results are the same (which I would assume they would be...).

I think what you should be doing is comparing a string version of the JSON with a string that is hardcoded in the expected, canonical order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the requested change.

@michellemounde michellemounde marked this pull request as ready for review November 7, 2023 09:40
Copy link
Contributor

@bhearsum bhearsum left a comment

Choose a reason for hiding this comment

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

One small thing below, but otherwise this is ready to merge.

assert ret.status_code == code
if code == 200:
assert ret.mimetype == "application/json"
assert ret.get_json() == response
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and the response entries it uses) are unnecessary. Comparing the raw text to the expected JSON is all we need to do here.

(Calling get_json is just re-parsing the raw text into a dictionary - so we're effectively checking the expected result twice.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated this as requested

@michellemounde
Copy link
Contributor Author

I tried rebasing and resolving merge conflicts but I got an error when running maintenance/pin.sh. The error:
"Package platformdirs was resolved to different versions in different environments: 3.11.0 and 4.0.0
RuntimeError: Please add constraints for the package version listed above"

@bhearsum
Copy link
Contributor

I tried rebasing and resolving merge conflicts but I got an error when running maintenance/pin.sh. The error: "Package platformdirs was resolved to different versions in different environments: 3.11.0 and 4.0.0 RuntimeError: Please add constraints for the package version listed above"

Hm...it looks like this is a general problem unrelated to this patch. I'll try to put together a fix for it.

@bhearsum
Copy link
Contributor

I tried rebasing and resolving merge conflicts but I got an error when running maintenance/pin.sh. The error: "Package platformdirs was resolved to different versions in different environments: 3.11.0 and 4.0.0 RuntimeError: Please add constraints for the package version listed above"

Hm...it looks like this is a general problem unrelated to this patch. I'll try to put together a fix for it.

Once #3050 is merged you should be able to rebase and update the requirements.

@michellemounde michellemounde force-pushed the canonical-json-responses branch from 47a1fdf to 70bfd23 Compare November 15, 2023 16:36
Copy link
Contributor

@bhearsum bhearsum left a comment

Choose a reason for hiding this comment

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

Thank you, nice work!!

@bhearsum bhearsum merged commit 8fa6999 into mozilla-releng:main Nov 15, 2023
bhearsum added a commit to bhearsum/balrog that referenced this pull request Nov 24, 2023
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.

use canonical json form for signed responses
2 participants