MCPcopy Index your code
hub / github.com/python/cpython / _test_basic_auth

Method _test_basic_auth

Lib/test/test_urllib2.py:1735–1770  ·  view source on GitHub ↗
(self, opener, auth_handler, auth_header,
                         realm, http_handler, password_manager,
                         request_url, protected_url)

Source from the content-addressed store, hash-verified

1733 self.assertRaises(ValueError, opener.open, "http://www.example.com")
1734
1735 def _test_basic_auth(self, opener, auth_handler, auth_header,
1736 realm, http_handler, password_manager,
1737 request_url, protected_url):
1738 import base64
1739 user, password = "wile", "coyote"
1740
1741 # .add_password() fed through to password manager
1742 auth_handler.add_password(realm, request_url, user, password)
1743 self.assertEqual(realm, password_manager.realm)
1744 self.assertEqual(request_url, password_manager.url)
1745 self.assertEqual(user, password_manager.user)
1746 self.assertEqual(password, password_manager.password)
1747
1748 opener.open(request_url)
1749
1750 # should have asked the password manager for the username/password
1751 self.assertEqual(password_manager.target_realm, realm)
1752 self.assertEqual(password_manager.target_url, protected_url)
1753
1754 # expect one request without authorization, then one with
1755 self.assertEqual(len(http_handler.requests), 2)
1756 self.assertFalse(http_handler.requests[0].has_header(auth_header))
1757 userpass = bytes('%s:%s' % (user, password), "ascii")
1758 auth_hdr_value = ('Basic ' +
1759 base64.encodebytes(userpass).strip().decode())
1760 self.assertEqual(http_handler.requests[1].get_header(auth_header),
1761 auth_hdr_value)
1762 self.assertEqual(http_handler.requests[1].unredirected_hdrs[auth_header],
1763 auth_hdr_value)
1764 # if the password manager can't find a password, the handler won't
1765 # handle the HTTP auth error
1766 password_manager.user = password_manager.password = None
1767 http_handler.reset()
1768 opener.open(request_url)
1769 self.assertEqual(len(http_handler.requests), 1)
1770 self.assertFalse(http_handler.requests[0].has_header(auth_header))
1771
1772 def test_basic_prior_auth_auto_send(self):
1773 # Assume already authenticated if is_authenticated=True

Callers 3

check_basic_authMethod · 0.95
test_proxy_basic_authMethod · 0.95

Calls 9

assertFalseMethod · 0.80
add_passwordMethod · 0.45
assertEqualMethod · 0.45
openMethod · 0.45
has_headerMethod · 0.45
decodeMethod · 0.45
stripMethod · 0.45
get_headerMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected