@@ -3815,11 +3815,11 @@ def failing_verify(_self, _verifier, _policy, _dist):
3815
3815
("https://google.com" , False ), # Totally different
3816
3816
("https://github.com/foo" , False ), # Missing parts
3817
3817
("https://github.com/foo/bar/" , True ), # Exactly the same
3818
- ("https://github.com/foo/bar/readme.md" , True ), # Additonal parts
3818
+ ("https://github.com/foo/bar/readme.md" , True ), # Additional parts
3819
3819
("https://github.com/foo/bar" , True ), # Missing trailing slash
3820
3820
],
3821
3821
)
3822
- def test_release_url_verified (
3822
+ def test_new_release_url_verified (
3823
3823
self , monkeypatch , pyramid_config , db_request , metrics , url , expected
3824
3824
):
3825
3825
project = ProjectFactory .create ()
@@ -3878,6 +3878,86 @@ def test_release_url_verified(
3878
3878
assert release_url is not None
3879
3879
assert release_url .verified == expected
3880
3880
3881
+ def test_new_publisher_verifies_existing_release_url (
3882
+ self ,
3883
+ monkeypatch ,
3884
+ pyramid_config ,
3885
+ db_request ,
3886
+ metrics ,
3887
+ ):
3888
+ repo_name = "my_new_repo"
3889
+ verified_url = "https://github.com/foo/bar"
3890
+ unverified_url = f"https://github.com/foo/{ repo_name } "
3891
+
3892
+ project = ProjectFactory .create ()
3893
+ release = ReleaseFactory .create (project = project , version = "1.0" )
3894
+ # We start with an existing release, with one verified URL and one unverified
3895
+ # URL. Uploading a new file with a Trusted Publisher that matches the unverified
3896
+ # URL should mark it as verified.
3897
+ release .project_urls = {
3898
+ "verified_url" : {"url" : verified_url , "verified" : True },
3899
+ "unverified_url" : {"url" : unverified_url , "verified" : False },
3900
+ }
3901
+ publisher = GitHubPublisherFactory .create (projects = [project ])
3902
+ publisher .repository_owner = "foo"
3903
+ publisher .repository_name = repo_name
3904
+ claims = {"sha" : "somesha" }
3905
+ identity = PublisherTokenContext (publisher , SignedClaims (claims ))
3906
+ db_request .oidc_publisher = identity .publisher
3907
+ db_request .oidc_claims = identity .claims
3908
+
3909
+ db_request .db .add (Classifier (classifier = "Environment :: Other Environment" ))
3910
+ db_request .db .add (Classifier (classifier = "Programming Language :: Python" ))
3911
+
3912
+ filename = "{}-{}.tar.gz" .format (project .name , "1.0" )
3913
+
3914
+ pyramid_config .testing_securitypolicy (identity = identity )
3915
+ db_request .user_agent = "warehouse-tests/6.6.6"
3916
+ db_request .POST = MultiDict (
3917
+ {
3918
+ "metadata_version" : "1.2" ,
3919
+ "name" : project .name ,
3920
+ "version" : "1.0" ,
3921
+ "summary" : "This is my summary!" ,
3922
+ "filetype" : "sdist" ,
3923
+ "md5_digest" : _TAR_GZ_PKG_MD5 ,
3924
+ "content" : pretend .stub (
3925
+ filename = filename ,
3926
+ file = io .BytesIO (_TAR_GZ_PKG_TESTDATA ),
3927
+ type = "application/tar" ,
3928
+ ),
3929
+ }
3930
+ )
3931
+ db_request .POST .extend (
3932
+ [
3933
+ ("classifiers" , "Environment :: Other Environment" ),
3934
+ ("classifiers" , "Programming Language :: Python" ),
3935
+ ("requires_dist" , "foo" ),
3936
+ ("requires_dist" , "bar (>1.0)" ),
3937
+ ("requires_external" , "Cheese (>1.0)" ),
3938
+ ("provides" , "testing" ),
3939
+ ]
3940
+ )
3941
+ db_request .POST .add ("project_urls" , f"verified_url, { verified_url } " )
3942
+ db_request .POST .add ("project_urls" , f"unverified_url, { unverified_url } " )
3943
+
3944
+ storage_service = pretend .stub (store = lambda path , filepath , meta : None )
3945
+ db_request .find_service = lambda svc , name = None , context = None : {
3946
+ IFileStorage : storage_service ,
3947
+ IMetricsService : metrics ,
3948
+ }.get (svc )
3949
+
3950
+ legacy .file_upload (db_request )
3951
+
3952
+ # After successful upload, the Release should have now both URLs verified
3953
+ release_urls = (
3954
+ db_request .db .query (ReleaseURL ).filter (Release .project == project ).all ()
3955
+ )
3956
+ release_urls = {r .name : r .verified for r in release_urls }
3957
+ assert "verified_url" in release_urls and "unverified_url" in release_urls
3958
+ assert release_urls ["verified_url" ]
3959
+ assert release_urls ["unverified_url" ]
3960
+
3881
3961
@pytest .mark .parametrize (
3882
3962
"version, expected_version" ,
3883
3963
[
0 commit comments