Skip to content

require that the user and github token owner match#19

Merged
mgedmin merged 2 commits intomgedmin:masterfrom
dhellmann:validate-user-and-token
Jul 17, 2022
Merged

require that the user and github token owner match#19
mgedmin merged 2 commits intomgedmin:masterfrom
dhellmann:validate-user-and-token

Conversation

@dhellmann
Copy link
Contributor

No description provided.

@mgedmin
Copy link
Owner

mgedmin commented Jul 14, 2022

Oof, the cog failure on git master not being recognized as failure of the overall build means that I was right to suspect continue-on-error: true for linter jobs.

Should be fixed on git master.

else:
self.responses[self.user_endpoint] = MockResponse(
json={'login': user},
)
Copy link
Owner

Choose a reason for hiding this comment

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

I'd like to make the mock a bit smarter and return a response only when the request contains an Authorization header, failing with a 401 otherwise.

I think that would have caught the use case where you're now calling _verify_user_token() even if the user hasn't provided a token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if the user is None, the response should be 401 instead of failing with an error because the mock wasn't completely configured?

Copy link
Owner

Choose a reason for hiding this comment

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

I've just checked: get_json_and_links() converts all 4xx errors to an exception, so I don't think the distinction between 401 and 404 really matters for these tests.

Copy link
Owner

@mgedmin mgedmin left a comment

Choose a reason for hiding this comment

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

Overall response: I think this breaks unauthenticated access again by doing the token check too soon, which will return a 401 from GitHub, which IIRC will raise an exception from the get_json_and_links() helper, aborting the process.

Details in single comments.

@dhellmann dhellmann force-pushed the validate-user-and-token branch from 807cd27 to 312ff14 Compare July 16, 2022 13:18
@dhellmann
Copy link
Contributor Author

I've updated this PR to fix the location of the validation and remove the extra changes in the tests.

Copy link
Owner

@mgedmin mgedmin left a comment

Choose a reason for hiding this comment

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

LGTM!

Thank you very much!

@mgedmin mgedmin merged commit d6a4ec8 into mgedmin:master Jul 17, 2022
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.

2 participants