Skip to content

Commit 1f5425f

Browse files
authored
Add helpful explaination to test_password_manager tests. (#936)
Also uncomment and fix a path test.
1 parent b94d7fd commit 1f5425f

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

Lib/test/test_urllib2.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,44 +141,55 @@ def test_password_manager(self):
141141
mgr = urllib.request.HTTPPasswordMgr()
142142
add = mgr.add_password
143143
find_user_pass = mgr.find_user_password
144+
144145
add("Some Realm", "http://example.com/", "joe", "password")
145146
add("Some Realm", "http://example.com/ni", "ni", "ni")
146-
add("c", "http://example.com/foo", "foo", "ni")
147-
add("c", "http://example.com/bar", "bar", "nini")
148-
add("b", "http://example.com/", "first", "blah")
149-
add("b", "http://example.com/", "second", "spam")
150-
add("a", "http://example.com", "1", "a")
151147
add("Some Realm", "http://c.example.com:3128", "3", "c")
152148
add("Some Realm", "d.example.com", "4", "d")
153149
add("Some Realm", "e.example.com:3128", "5", "e")
154150

151+
# For the same realm, password set the highest path is the winner.
155152
self.assertEqual(find_user_pass("Some Realm", "example.com"),
156153
('joe', 'password'))
157-
158-
#self.assertEqual(find_user_pass("Some Realm", "http://example.com/ni"),
159-
# ('ni', 'ni'))
160-
154+
self.assertEqual(find_user_pass("Some Realm", "http://example.com/ni"),
155+
('joe', 'password'))
161156
self.assertEqual(find_user_pass("Some Realm", "http://example.com"),
162157
('joe', 'password'))
163158
self.assertEqual(find_user_pass("Some Realm", "http://example.com/"),
164159
('joe', 'password'))
165-
self.assertEqual(
166-
find_user_pass("Some Realm", "http://example.com/spam"),
167-
('joe', 'password'))
168-
self.assertEqual(
169-
find_user_pass("Some Realm", "http://example.com/spam/spam"),
170-
('joe', 'password'))
160+
self.assertEqual(find_user_pass("Some Realm",
161+
"http://example.com/spam"),
162+
('joe', 'password'))
163+
164+
self.assertEqual(find_user_pass("Some Realm",
165+
"http://example.com/spam/spam"),
166+
('joe', 'password'))
167+
168+
# You can have different passwords for different paths.
169+
170+
add("c", "http://example.com/foo", "foo", "ni")
171+
add("c", "http://example.com/bar", "bar", "nini")
172+
171173
self.assertEqual(find_user_pass("c", "http://example.com/foo"),
172174
('foo', 'ni'))
175+
173176
self.assertEqual(find_user_pass("c", "http://example.com/bar"),
174177
('bar', 'nini'))
178+
179+
# For the same path, newer password should be considered.
180+
181+
add("b", "http://example.com/", "first", "blah")
182+
add("b", "http://example.com/", "second", "spam")
183+
175184
self.assertEqual(find_user_pass("b", "http://example.com/"),
176185
('second', 'spam'))
177186

178187
# No special relationship between a.example.com and example.com:
179188

189+
add("a", "http://example.com", "1", "a")
180190
self.assertEqual(find_user_pass("a", "http://example.com/"),
181191
('1', 'a'))
192+
182193
self.assertEqual(find_user_pass("a", "http://a.example.com/"),
183194
(None, None))
184195

0 commit comments

Comments
 (0)