Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Conversation

@ghost
Copy link

@ghost ghost commented Nov 26, 2024

Purpose/Motivation

The new endpoint upload/<service>/<slug>/upload-coverage does not follow the regex upload/<service>/<slug>/commits/..., which is used in for example:

  • upload/<service>/<slug>/commits/<commit-sha>
  • upload/<service>/<slug>/commits/<commit-sha>/report/<report-code>
  • upload/<service>/<slug>/commits/<commit-sha>/report/<report-code>/upload)

and this fix adds upload-coverage to the regex to correct auth behaviour for the new endpoint.

Links to relevant tickets

What does this PR do?

Include a brief description of the changes in this PR. Bullet points are your friend.

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-notifications
Copy link

codecov-notifications bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Nov 26, 2024

❌ 56 Tests Failed:

Tests completed Failed Passed Skipped
2691 56 2635 6
View the top 3 failed tests by shortest run time
codecov_auth/tests/unit/test_repo_authentication.py::TestTokenlessAuth::test_tokenless_matches_paths[/upload/github/owner::::the_repo/commits/9652fb7ff577f554588ea83afded9000acd084ee/reports/-owner/the_repo-9652fb7ff577f554588ea83afded9000acd084ee]
Stack Traces | 0.012s run time
self = <codecov_auth.tests.unit.test_repo_authentication.TestTokenlessAuth object at 0x7f6f1bec3c50>
request_uri = '.../upload/github/owner::::.../commits/9652fb7ff577f554588ea83afded9000acd084ee/reports/'
repo_slug = 'owner/the_repo'
commitid = '9652fb7ff577f554588ea83afded9000acd084ee', db = None

    @pytest.mark.parametrize("request_uri,repo_slug,commitid", valid_params_to_test)
    def test_tokenless_matches_paths(self, request_uri, repo_slug, commitid, db):
        author_name, repo_name = repo_slug.split("/")
        repo = RepositoryFactory(
            name=repo_name, author__username=author_name, private=False
        )
        assert repo.service == "github"
        request = APIRequestFactory().post(
            request_uri, {"branch": "fork:branch"}, format="json"
        )
        authentication = TokenlessAuthentication()
>       assert authentication._get_info_from_request_path(request) == (repo, commitid)
E       AssertionError: assert (<Repository:...9000acd084ee') == (<Repository:...9000acd084ee')
E         
E         At index 1 diff: 'commits/9652fb7ff577f554588ea83afded9000acd084ee' != '9652fb7ff577f554588ea83afded9000acd084ee'
E         Use -v to get more diff

.../tests/unit/test_repo_authentication.py:501: AssertionError
codecov_auth/tests/unit/test_repo_authentication.py::TestTokenlessAuth::test_tokenless_matches_paths[/upload/github/owner::::the_repo/commits/9652fb7ff577f554588ea83afded9000acd084ee/reports/default/uploads-owner/the_repo-9652fb7ff577f554588ea83afded9000acd084ee]
Stack Traces | 0.012s run time
self = <codecov_auth.tests.unit.test_repo_authentication.TestTokenlessAuth object at 0x7f6f1bec3d10>
request_uri = '.../upload/github/owner::::.../reports/default/uploads'
repo_slug = 'owner/the_repo'
commitid = '9652fb7ff577f554588ea83afded9000acd084ee', db = None

    @pytest.mark.parametrize("request_uri,repo_slug,commitid", valid_params_to_test)
    def test_tokenless_matches_paths(self, request_uri, repo_slug, commitid, db):
        author_name, repo_name = repo_slug.split("/")
        repo = RepositoryFactory(
            name=repo_name, author__username=author_name, private=False
        )
        assert repo.service == "github"
        request = APIRequestFactory().post(
            request_uri, {"branch": "fork:branch"}, format="json"
        )
        authentication = TokenlessAuthentication()
>       assert authentication._get_info_from_request_path(request) == (repo, commitid)
E       AssertionError: assert (<Repository:...9000acd084ee') == (<Repository:...9000acd084ee')
E         
E         At index 1 diff: 'commits/9652fb7ff577f554588ea83afded9000acd084ee' != '9652fb7ff577f554588ea83afded9000acd084ee'
E         Use -v to get more diff

.../tests/unit/test_repo_authentication.py:501: AssertionError
codecov_auth/tests/unit/test_repo_authentication.py::TestTokenlessAuth::test_tokenless_success[False-None-fork:branch-False]
Stack Traces | 0.012s run time
self = <codecov_auth.tests.unit.test_repo_authentication.TestTokenlessAuth object at 0x7f6f1bed0710>
db = None, mocker = <pytest_mock.plugin.MockerFixture object at 0x7f6edcfee840>
private = False, branch = 'fork:branch', existing_commit = False
commit_branch = None

    @pytest.mark.parametrize("private", [False, True])
    @pytest.mark.parametrize("branch", ["branch", "fork:branch"])
    @pytest.mark.parametrize(
        "existing_commit,commit_branch",
        [(False, None), (True, "branch"), (True, "fork:branch")],
    )
    def test_tokenless_success(
        self,
        db,
        mocker,
        private,
        branch,
        existing_commit,
        commit_branch,
    ):
        repo = RepositoryFactory(private=private)
    
        if existing_commit:
            commit = CommitFactory()
            commit.branch = commit_branch
            commit.repository = repo
            commit.save()
    
            request = APIRequestFactory().post(
                f"/upload/github/{repo.author.username}::::{repo.name}/commits/{commit.commitid}.../reports/report_code/uploads",
                {"branch": branch},
                format="json",
            )
    
        else:
            request = APIRequestFactory().post(
                f"/upload/github/{repo.author.username}::::{repo.name}/commits",
                {"branch": branch},
                format="json",
            )
    
        authentication = TokenlessAuthentication()
        expected = private is False and (
            (existing_commit is False and ":" in branch)
            or (existing_commit is True and ":" in commit_branch)
        )
    
        if expected:
>           res = authentication.authenticate(request)

.../tests/unit/test_repo_authentication.py:546: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
codecov_auth/authentication/repo_auth.py:308: in authenticate
    branch = self.get_branch(request, repository.repoid, commitid)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <codecov_auth.authentication.repo_auth.TokenlessAuthentication object at 0x7f6efc1c48f0>
request = <WSGIRequest: POST '.../upload/github/montgomerypatrick::::fine/commits'>
repoid = 285, commitid = 'commits'

    def get_branch(self, request, repoid=None, commitid=None):
        if repoid and commitid:
            commit = Commit.objects.filter(
                repository_id=repoid, commitid=commitid
            ).first()
            if not commit:
>               raise exceptions.AuthenticationFailed(self.auth_failed_message)
E               rest_framework.exceptions.AuthenticationFailed: Not valid tokenless upload

codecov_auth/authentication/repo_auth.py:292: AuthenticationFailed

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@codecov-public-qa
Copy link

codecov-public-qa bot commented Nov 26, 2024

❌ 56 Tests Failed:

Tests completed Failed Passed Skipped
2691 56 2635 6
View the top 3 failed tests by shortest run time
codecov_auth/tests/unit/test_repo_authentication.py::TestTokenlessAuth::test_tokenless_matches_paths[/upload/github/owner::::the_repo/commits/9652fb7ff577f554588ea83afded9000acd084ee/reports/-owner/the_repo-9652fb7ff577f554588ea83afded9000acd084ee]
Stack Traces | 0.012s run time
self = &lt;codecov_auth.tests.unit.test_repo_authentication.TestTokenlessAuth object at 0x7f6f1bec3c50&gt;
request_uri = '.../upload/github/owner::::.../commits/9652fb7ff577f554588ea83afded9000acd084ee/reports/'
repo_slug = 'owner/the_repo'
commitid = '9652fb7ff577f554588ea83afded9000acd084ee', db = None

    @pytest.mark.parametrize("request_uri,repo_slug,commitid", valid_params_to_test)
    def test_tokenless_matches_paths(self, request_uri, repo_slug, commitid, db):
        author_name, repo_name = repo_slug.split("/")
        repo = RepositoryFactory(
            name=repo_name, author__username=author_name, private=False
        )
        assert repo.service == "github"
        request = APIRequestFactory().post(
            request_uri, {"branch": "fork:branch"}, format="json"
        )
        authentication = TokenlessAuthentication()
&gt;       assert authentication._get_info_from_request_path(request) == (repo, commitid)
E       AssertionError: assert (&lt;Repository:...9000acd084ee') == (&lt;Repository:...9000acd084ee')
E         
E         At index 1 diff: 'commits/9652fb7ff577f554588ea83afded9000acd084ee' != '9652fb7ff577f554588ea83afded9000acd084ee'
E         Use -v to get more diff

.../tests/unit/test_repo_authentication.py:501: AssertionError
codecov_auth/tests/unit/test_repo_authentication.py::TestTokenlessAuth::test_tokenless_matches_paths[/upload/github/owner::::the_repo/commits/9652fb7ff577f554588ea83afded9000acd084ee/reports/default/uploads-owner/the_repo-9652fb7ff577f554588ea83afded9000acd084ee]
Stack Traces | 0.012s run time
self = &lt;codecov_auth.tests.unit.test_repo_authentication.TestTokenlessAuth object at 0x7f6f1bec3d10&gt;
request_uri = '.../upload/github/owner::::.../reports/default/uploads'
repo_slug = 'owner/the_repo'
commitid = '9652fb7ff577f554588ea83afded9000acd084ee', db = None

    @pytest.mark.parametrize("request_uri,repo_slug,commitid", valid_params_to_test)
    def test_tokenless_matches_paths(self, request_uri, repo_slug, commitid, db):
        author_name, repo_name = repo_slug.split("/")
        repo = RepositoryFactory(
            name=repo_name, author__username=author_name, private=False
        )
        assert repo.service == "github"
        request = APIRequestFactory().post(
            request_uri, {"branch": "fork:branch"}, format="json"
        )
        authentication = TokenlessAuthentication()
&gt;       assert authentication._get_info_from_request_path(request) == (repo, commitid)
E       AssertionError: assert (&lt;Repository:...9000acd084ee') == (&lt;Repository:...9000acd084ee')
E         
E         At index 1 diff: 'commits/9652fb7ff577f554588ea83afded9000acd084ee' != '9652fb7ff577f554588ea83afded9000acd084ee'
E         Use -v to get more diff

.../tests/unit/test_repo_authentication.py:501: AssertionError
codecov_auth/tests/unit/test_repo_authentication.py::TestTokenlessAuth::test_tokenless_success[False-None-fork:branch-False]
Stack Traces | 0.012s run time
self = &lt;codecov_auth.tests.unit.test_repo_authentication.TestTokenlessAuth object at 0x7f6f1bed0710&gt;
db = None, mocker = &lt;pytest_mock.plugin.MockerFixture object at 0x7f6edcfee840&gt;
private = False, branch = 'fork:branch', existing_commit = False
commit_branch = None

    @pytest.mark.parametrize("private", [False, True])
    @pytest.mark.parametrize("branch", ["branch", "fork:branch"])
    @pytest.mark.parametrize(
        "existing_commit,commit_branch",
        [(False, None), (True, "branch"), (True, "fork:branch")],
    )
    def test_tokenless_success(
        self,
        db,
        mocker,
        private,
        branch,
        existing_commit,
        commit_branch,
    ):
        repo = RepositoryFactory(private=private)
    
        if existing_commit:
            commit = CommitFactory()
            commit.branch = commit_branch
            commit.repository = repo
            commit.save()
    
            request = APIRequestFactory().post(
                f"/upload/github/{repo.author.username}::::{repo.name}/commits/{commit.commitid}.../reports/report_code/uploads",
                {"branch": branch},
                format="json",
            )
    
        else:
            request = APIRequestFactory().post(
                f"/upload/github/{repo.author.username}::::{repo.name}/commits",
                {"branch": branch},
                format="json",
            )
    
        authentication = TokenlessAuthentication()
        expected = private is False and (
            (existing_commit is False and ":" in branch)
            or (existing_commit is True and ":" in commit_branch)
        )
    
        if expected:
&gt;           res = authentication.authenticate(request)

.../tests/unit/test_repo_authentication.py:546: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
codecov_auth/authentication/repo_auth.py:308: in authenticate
    branch = self.get_branch(request, repository.repoid, commitid)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;codecov_auth.authentication.repo_auth.TokenlessAuthentication object at 0x7f6efc1c48f0&gt;
request = &lt;WSGIRequest: POST '.../upload/github/montgomerypatrick::::fine/commits'&gt;
repoid = 285, commitid = 'commits'

    def get_branch(self, request, repoid=None, commitid=None):
        if repoid and commitid:
            commit = Commit.objects.filter(
                repository_id=repoid, commitid=commitid
            ).first()
            if not commit:
&gt;               raise exceptions.AuthenticationFailed(self.auth_failed_message)
E               rest_framework.exceptions.AuthenticationFailed: Not valid tokenless upload

codecov_auth/authentication/repo_auth.py:292: AuthenticationFailed

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2024

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@codecov
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.05%. Comparing base (6b66f3e) to head (59d7756).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1003   +/-   ##
=======================================
  Coverage   96.04%   96.05%           
=======================================
  Files         828      828           
  Lines       19211    19256   +45     
=======================================
+ Hits        18452    18497   +45     
  Misses        759      759           
Flag Coverage Δ
unit 92.28% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 92.28% <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

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

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

Lgtm, assuming you tested the regex online 👌. Also missing ling

@ghost
Copy link
Author

ghost commented Nov 26, 2024

Lgtm, assuming you tested the regex online 👌. Also missing ling

Pushed an extra fix on top of this since the previous one won't retain commitid

@ghost ghost added this pull request to the merge queue Nov 26, 2024
Merged via the queue into main with commit 160f0bd Nov 26, 2024
19 checks passed
@ghost ghost deleted the tony/upload-coverage-auth branch November 26, 2024 17:28
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants