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

add UploadTokenRequiredAuthenticationCheck #858

Merged
merged 3 commits into from
Oct 7, 2024
Merged

add UploadTokenRequiredAuthenticationCheck #858

merged 3 commits into from
Oct 7, 2024

Conversation

nora-codecov
Copy link
Contributor

Purpose/Motivation

NEW auth class to check for TrueTokenless

Links to relevant tickets

codecov/engineering-team#2298

What does this PR do?

This will be placed at the top of the list for the auth methods on upload endpoints (so it is checked first). In a separate pr.

@nora-codecov nora-codecov requested a review from a team October 4, 2024 23:02
@codecov-notifications
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.31%. Comparing base (2f718ab) to head (ba74866).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #858   +/-   ##
=======================================
  Coverage   96.31%   96.31%           
=======================================
  Files         818      818           
  Lines       18985    19007   +22     
=======================================
+ Hits        18285    18307   +22     
  Misses        700      700           
Flag Coverage Δ
unit 92.64% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 92.64% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@giovanni-guidini giovanni-guidini left a comment

Choose a reason for hiding this comment

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

I like how you made it easier to reuse code in the tests. Particularly having the valid_params_to_test be an independent list that can be reused 👍

Also left a few nit comments

# There's a non-zero chance that the full test name would be mis-interpreted by pytest
# And these tests would never work with ATS.
# Sadly there's no way to escape the '::' sequence
request_uri = request_uri.replace("SEPARATOR", "::::")
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Ah this is no longer necessary.
Well 1 because we're not using ATS anymore, so who cares.
But 2 because @michelletran-codecov showed me that parametrized tests can have an id.

So we can just add custom ids to the tests and we don't have to leave that SEPARATOR there.

I'm personally favor pytest.param with id= keyword argument

service: Service, repo_identifier: str
) -> typing.Optional[Repository]:
service: Service, repo_identifier: str, include_owner: bool = False
) -> typing.Optional[Repository] | tuple[Repository | None, Owner | None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]
this include_owner is unnecessarily complicating this function.

And it looks like it was added for the benefit of get_repository_and_owner_from_string. We have a _get_owner_from_string already.

I'd personally think the extra logic should be moved to get_repository_and_owner_from_string. Have that make use of the 2 other funcitons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree! updating...

Comment on lines 43 to 48
def get_repository_and_owner_from_string(
service: Service, repo_identifier: str
) -> tuple[Repository | None, Owner | None]:
return get_repository_from_string(
service=service, repo_identifier=repo_identifier, include_owner=True
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually turn this around:

Move all the logic that does the resolution into get_repository_and_owner_from_string, and remove that include_owner parameter.
Then call this from get_repository_from_string, returning just result[0], which should make things simpler.

The type system can’t reason about that a True parameter means you get a tuple, and otherwise a Repository | None.
So I’m pretty sure the code as is will cause a type error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great suggestion!! updating...

@nora-codecov nora-codecov enabled auto-merge October 7, 2024 20:44
@nora-codecov nora-codecov added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit 44c82bc Oct 7, 2024
18 of 19 checks passed
@nora-codecov nora-codecov deleted the nora/2298 branch October 7, 2024 21:02
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.

3 participants