12
12
["input_url" , "url" , "username" , "password" ],
13
13
[
14
14
(
15
- "http ://user%40email.com:[email protected] /path" ,
16
- "http ://example.com/path" ,
15
+ "https ://user%40email.com:[email protected] /path" ,
16
+ "https ://example.com/path" ,
17
17
18
18
"password" ,
19
19
),
20
20
(
21
- "http ://username:[email protected] /path" ,
22
- "http ://example.com/path" ,
21
+ "https ://username:[email protected] /path" ,
22
+ "https ://example.com/path" ,
23
23
"username" ,
24
24
"password" ,
25
25
),
26
26
(
27
-
28
- "http ://example.com/path" ,
27
+
28
+ "https ://example.com/path" ,
29
29
"token" ,
30
30
"" ,
31
31
),
32
32
(
33
- "http ://example.com/path" ,
34
- "http ://example.com/path" ,
33
+ "https ://example.com/path" ,
34
+ "https ://example.com/path" ,
35
35
None ,
36
36
None ,
37
37
),
@@ -50,43 +50,91 @@ def test_get_credentials_parses_correctly(
50
50
(username is None and password is None )
51
51
or
52
52
# Credentials were found and "cached" appropriately
53
- auth . passwords [ "example.com" ] == (username , password )
53
+ ( url , (username , password )) in auth . passwords
54
54
)
55
55
56
56
57
57
def test_get_credentials_not_to_uses_cached_credentials () -> None :
58
58
auth = MultiDomainBasicAuth ()
59
- auth .passwords [ " example.com"] = ("user" , "pass" )
59
+ auth .passwords . append (( "https:// example.com", ("user" , "pass" )) )
60
60
61
- got = auth .
_get_url_and_credentials (
"http ://foo:[email protected] /path" )
62
- expected = ("http ://example.com/path" , "foo" , "bar" )
61
+ got = auth .
_get_url_and_credentials (
"https ://foo:[email protected] /path" )
62
+ expected = ("https ://example.com/path" , "foo" , "bar" )
63
63
assert got == expected
64
64
65
65
66
- def test_get_credentials_not_to_uses_cached_credentials_only_username () -> None :
66
+ def test_get_credentials_not_to_use_cached_credentials_only_username () -> None :
67
67
auth = MultiDomainBasicAuth ()
68
- auth .passwords [ " example.com"] = ("user" , "pass" )
68
+ auth .passwords . append (( "https:// example.com", ("user" , "pass" )) )
69
69
70
- got = auth .
_get_url_and_credentials (
"http://[email protected] /path" )
71
- expected = ("http://example.com/path" , "foo" , "" )
70
+ got = auth .
_get_url_and_credentials (
"https://[email protected] /path" )
71
+ expected = ("https://example.com/path" , "foo" , "" )
72
+ assert got == expected
73
+
74
+
75
+ def test_multi_domain_credentials_match () -> None :
76
+ auth = MultiDomainBasicAuth ()
77
+ auth .passwords .append (("https://example.com" , ("user" , "pass" )))
78
+ auth .passwords .append (("https://example.com/path" , ("user" , "pass2" )))
79
+
80
+ got = auth .
_get_url_and_credentials (
"https://[email protected] /path" )
81
+ expected = ("https://example.com/path" , "user" , "pass2" )
82
+ assert got == expected
83
+
84
+
85
+ def test_multi_domain_credentials_longest_match () -> None :
86
+ auth = MultiDomainBasicAuth ()
87
+ auth .passwords .append (("https://example.com" , ("user" , "pass" )))
88
+ auth .passwords .append (("https://example.com/path" , ("user" , "pass2" )))
89
+ auth .passwords .append (("https://example.com/path/subpath" , ("user" , "pass3" )))
90
+
91
+ got = auth .
_get_url_and_credentials (
"https://[email protected] /path" )
92
+ expected = ("https://example.com/path" , "user" , "pass2" )
72
93
assert got == expected
73
94
74
95
75
96
def test_get_credentials_uses_cached_credentials () -> None :
76
97
auth = MultiDomainBasicAuth ()
77
- auth .passwords ["example.com" ] = ("user" , "pass" )
98
+ auth .passwords .append (("https://example.com" , ("user" , "pass" )))
99
+
100
+ got = auth ._get_url_and_credentials ("https://example.com/path" )
101
+ expected = ("https://example.com/path" , "user" , "pass" )
102
+ assert got == expected
103
+
104
+
105
+ def test_get_credentials_not_uses_cached_credentials_different_scheme_http () -> None :
106
+ auth = MultiDomainBasicAuth ()
107
+ auth .passwords .append (("http://example.com" , ("user" , "pass" )))
108
+
109
+ got = auth ._get_url_and_credentials ("https://example.com/path" )
110
+ expected = ("https://example.com/path" , None , None )
111
+ assert got == expected
112
+
113
+
114
+ def test_get_credentials_not_uses_cached_credentials_different_scheme_https () -> None :
115
+ auth = MultiDomainBasicAuth ()
116
+ auth .passwords .append (("https://example.com" , ("user" , "pass" )))
78
117
79
118
got = auth ._get_url_and_credentials ("http://example.com/path" )
80
- expected = ("http://example.com/path" , "user" , "pass" )
119
+ expected = ("http://example.com/path" , None , None )
81
120
assert got == expected
82
121
83
122
84
123
def test_get_credentials_uses_cached_credentials_only_username () -> None :
85
124
auth = MultiDomainBasicAuth ()
86
- auth .passwords ["example.com" ] = ("user" , "pass" )
125
+ auth .passwords .append (("https://example.com" , ("user" , "pass" )))
126
+
127
+ got = auth .
_get_url_and_credentials (
"https://[email protected] /path" )
128
+ expected = ("https://example.com/path" , "user" , "pass" )
129
+ assert got == expected
130
+
131
+
132
+ def test_get_credentials_uses_cached_credentials_wrong_username () -> None :
133
+ auth = MultiDomainBasicAuth ()
134
+ auth .passwords .append (("https://example.com" , ("user" , "pass" )))
87
135
88
- got = auth ._get_url_and_credentials ("http ://user @example.com/path" )
89
- expected = ("http ://example.com/path" , "user " , "pass " )
136
+ got = auth ._get_url_and_credentials ("https ://user2 @example.com/path" )
137
+ expected = ("https ://example.com/path" , "user2 " , "" )
90
138
assert got == expected
91
139
92
140
0 commit comments