@@ -4799,84 +4799,6 @@ def test_missing_trailing_slash_redirect(pyramid_request):
4799
4799
assert resp .headers ["Location" ] == "/legacy/"
4800
4800
4801
4801
4802
- @pytest .mark .parametrize (
4803
- ("url" , "publisher_url" , "expected" ),
4804
- [
4805
- ( # GitHub trivial case
4806
- "https://github.com/owner/project" ,
4807
- "https://github.com/owner/project" ,
4808
- True ,
4809
- ),
4810
- ( # ActiveState trivial case
4811
- "https://platform.activestate.com/owner/project" ,
4812
- "https://platform.activestate.com/owner/project" ,
4813
- True ,
4814
- ),
4815
- ( # GitLab trivial case
4816
- "https://gitlab.com/owner/project" ,
4817
- "https://gitlab.com/owner/project" ,
4818
- True ,
4819
- ),
4820
- ( # URL is a sub-path of the TP URL
4821
- "https://github.com/owner/project/issues" ,
4822
- "https://github.com/owner/project" ,
4823
- True ,
4824
- ),
4825
- ( # Normalization
4826
- "https://GiThUB.com/owner/project/" ,
4827
- "https://github.com/owner/project" ,
4828
- True ,
4829
- ),
4830
- ( # TP URL is a prefix, but not a parent of the URL
4831
- "https://github.com/owner/project22" ,
4832
- "https://github.com/owner/project" ,
4833
- False ,
4834
- ),
4835
- ( # URL is a parent of the TP URL
4836
- "https://github.com/owner" ,
4837
- "https://github.com/owner/project" ,
4838
- False ,
4839
- ),
4840
- ( # Scheme component does not match
4841
- "http://github.com/owner/project" ,
4842
- "https://github.com/owner/project" ,
4843
- False ,
4844
- ),
4845
- ( # Host component does not match
4846
- "https://gitlab.com/owner/project" ,
4847
- "https://github.com/owner/project" ,
4848
- False ,
4849
- ),
4850
- ( # Host component matches, but contains user and port info
4851
- "https://[email protected] :443/owner/project" ,
4852
- "https://github.com/owner/project" ,
4853
- False ,
4854
- ),
4855
- ( # URL path component is empty
4856
- "https://github.com" ,
4857
- "https://github.com/owner/project" ,
4858
- False ,
4859
- ),
4860
- ( # TP URL path component is empty
4861
- # (currently no TPs have an empty path, so even if the given URL is a
4862
- # sub-path of the TP URL, we fail the verification)
4863
- "https://github.com/owner/project" ,
4864
- "https://github.com" ,
4865
- False ,
4866
- ),
4867
- ( # Both path components are empty
4868
- # (currently no TPs have an empty path, so even if the given URL is the
4869
- # same as the TP URL, we fail the verification)
4870
- "https://github.com" ,
4871
- "https://github.com" ,
4872
- False ,
4873
- ),
4874
- ],
4875
- )
4876
- def test_verify_url_with_trusted_publisher (url , publisher_url , expected ):
4877
- assert legacy ._verify_url_with_trusted_publisher (url , publisher_url ) == expected
4878
-
4879
-
4880
4802
@pytest .mark .parametrize (
4881
4803
("url" , "project_name" , "project_normalized_name" , "expected" ),
4882
4804
[
@@ -4992,24 +4914,27 @@ def test_verify_url_pypi(url, project_name, project_normalized_name, expected):
4992
4914
4993
4915
def test_verify_url ():
4994
4916
# `_verify_url` is just a helper function that calls `_verify_url_pypi` and
4995
- # `_verify_url_with_trusted_publisher`, where the actual verification logic lives.
4917
+ # `OIDCPublisher.verify_url`, where the actual verification logic lives.
4918
+ publisher_verifies = pretend .stub (verify_url = lambda url : True )
4919
+ publisher_fails = pretend .stub (verify_url = lambda url : False )
4920
+
4996
4921
assert legacy ._verify_url (
4997
4922
url = "https://pypi.org/project/myproject/" ,
4998
- publisher_url = None ,
4923
+ publisher = None ,
4999
4924
project_name = "myproject" ,
5000
4925
project_normalized_name = "myproject" ,
5001
4926
)
5002
4927
5003
4928
assert legacy ._verify_url (
5004
4929
url = "https://github.com/org/myproject/issues" ,
5005
- publisher_url = "https://github.com/org/myproject" ,
4930
+ publisher = publisher_verifies ,
5006
4931
project_name = "myproject" ,
5007
4932
project_normalized_name = "myproject" ,
5008
4933
)
5009
4934
5010
4935
assert not legacy ._verify_url (
5011
4936
url = "example.com" ,
5012
- publisher_url = "https://github.com/or/myproject" ,
4937
+ publisher = publisher_fails ,
5013
4938
project_name = "myproject" ,
5014
4939
project_normalized_name = "myproject" ,
5015
4940
)
0 commit comments