File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 24
24
25
25
def get_netrc_auth (url , netrc ):
26
26
"""
27
- Return login and password if the hostname is in netrc
27
+ Return login and password if either the hostname is in netrc or a default is set in netrc
28
28
else return login and password as None
29
29
"""
30
30
hostname = urlparse (url ).hostname
@@ -33,6 +33,11 @@ def get_netrc_auth(url, netrc):
33
33
url_auth = hosts .get (hostname )
34
34
# netrc returns a tuple of (login, account, password)
35
35
return (url_auth [0 ], url_auth [2 ])
36
+
37
+ if 'default' in hosts :
38
+ default_auth = hosts .get ('default' )
39
+ return (default_auth [0 ], default_auth [2 ])
40
+
36
41
return (None , None )
37
42
38
43
Original file line number Diff line number Diff line change
1
+ machine example.com login test password test123
2
+ default login defaultuser password defaultpass
Original file line number Diff line number Diff line change @@ -67,6 +67,14 @@ def test_get_netrc_auth_with_with_subdomains():
67
67
assert get_netrc_auth (url = "https://another.example.com/simple" , netrc = parsed_netrc ) == (None , None )
68
68
69
69
70
+ def test_get_netrc_auth_with_default ():
71
+ netrc_file = test_env .get_test_loc ("test-default.netrc" )
72
+ parsed_netrc = netrc (netrc_file )
73
+
74
+ assert get_netrc_auth (url = "https://example.com/simple" , netrc = parsed_netrc ) == ("test" , "test123" )
75
+ assert get_netrc_auth (url = "https://non-existing.org/simple" , netrc = parsed_netrc ) == ("defaultuser" , "defaultpass" )
76
+
77
+
70
78
@pytest .mark .asyncio
71
79
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "requires python3.8 or higher" )
72
80
@mock .patch ("python_inspector.utils_pypi.CACHE.get" )
You can’t perform that action at this time.
0 commit comments