MCPcopy Create free account
hub / github.com/python/cpython / test_password_manager

Method test_password_manager

Lib/test/test_urllib2.py:146–230  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

144 self.assertFalse(req.has_header("Unredirected-spam"))
145
146 def test_password_manager(self):
147 mgr = urllib.request.HTTPPasswordMgr()
148 add = mgr.add_password
149 find_user_pass = mgr.find_user_password
150
151 add("Some Realm", "http://example.com/", "joe", "password")
152 add("Some Realm", "http://example.com/ni", "ni", "ni")
153 add("Some Realm", "http://c.example.com:3128", "3", "c")
154 add("Some Realm", "d.example.com", "4", "d")
155 add("Some Realm", "e.example.com:3128", "5", "e")
156
157 # For the same realm, password set the highest path is the winner.
158 self.assertEqual(find_user_pass("Some Realm", "example.com"),
159 ('joe', 'password'))
160 self.assertEqual(find_user_pass("Some Realm", "http://example.com/ni"),
161 ('joe', 'password'))
162 self.assertEqual(find_user_pass("Some Realm", "http://example.com"),
163 ('joe', 'password'))
164 self.assertEqual(find_user_pass("Some Realm", "http://example.com/"),
165 ('joe', 'password'))
166 self.assertEqual(find_user_pass("Some Realm",
167 "http://example.com/spam"),
168 ('joe', 'password'))
169 self.assertEqual(find_user_pass("Some Realm",
170 "http://example.com/spam/spam"),
171 ('joe', 'password'))
172
173 # You can have different passwords for different paths.
174
175 add("c", "http://example.com/foo", "foo", "ni")
176 add("c", "http://example.com/bar", "bar", "nini")
177 add("c", "http://example.com/foo/bar", "foobar", "nibar")
178
179 self.assertEqual(find_user_pass("c", "http://example.com/foo"),
180 ('foo', 'ni'))
181 self.assertEqual(find_user_pass("c", "http://example.com/bar"),
182 ('bar', 'nini'))
183 self.assertEqual(find_user_pass("c", "http://example.com/foo/"),
184 ('foo', 'ni'))
185 self.assertEqual(find_user_pass("c", "http://example.com/foo/bar"),
186 ('foo', 'ni'))
187 self.assertEqual(find_user_pass("c", "http://example.com/foo/baz"),
188 ('foo', 'ni'))
189 self.assertEqual(find_user_pass("c", "http://example.com/foobar"),
190 (None, None))
191
192 add("c", "http://example.com/baz/", "baz", "ninini")
193
194 self.assertEqual(find_user_pass("c", "http://example.com/baz"),
195 (None, None))
196 self.assertEqual(find_user_pass("c", "http://example.com/baz/"),
197 ('baz', 'ninini'))
198 self.assertEqual(find_user_pass("c", "http://example.com/baz/bar"),
199 ('baz', 'ninini'))
200
201 # For the same path, newer password should be considered.
202
203 add("b", "http://example.com/", "first", "blah")

Callers

nothing calls this directly

Calls 2

addFunction · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected