MCPcopy Index your code
hub / github.com/RustPython/RustPython / _test_basic_auth

Method _test_basic_auth

Lib/test/test_urllib2.py:1718–1753  ·  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

1716 self.assertRaises(ValueError, opener.open, "http://www.example.com")
1717
1718 def _test_basic_auth(self, opener, auth_handler, auth_header,
1719 realm, http_handler, password_manager,
1720 request_url, protected_url):
1721 import base64
1722 user, password = "wile", "coyote"
1723
1724 # .add_password() fed through to password manager
1725 auth_handler.add_password(realm, request_url, user, password)
1726 self.assertEqual(realm, password_manager.realm)
1727 self.assertEqual(request_url, password_manager.url)
1728 self.assertEqual(user, password_manager.user)
1729 self.assertEqual(password, password_manager.password)
1730
1731 opener.open(request_url)
1732
1733 # should have asked the password manager for the username/password
1734 self.assertEqual(password_manager.target_realm, realm)
1735 self.assertEqual(password_manager.target_url, protected_url)
1736
1737 # expect one request without authorization, then one with
1738 self.assertEqual(len(http_handler.requests), 2)
1739 self.assertFalse(http_handler.requests[0].has_header(auth_header))
1740 userpass = bytes('%s:%s' % (user, password), "ascii")
1741 auth_hdr_value = ('Basic ' +
1742 base64.encodebytes(userpass).strip().decode())
1743 self.assertEqual(http_handler.requests[1].get_header(auth_header),
1744 auth_hdr_value)
1745 self.assertEqual(http_handler.requests[1].unredirected_hdrs[auth_header],
1746 auth_hdr_value)
1747 # if the password manager can't find a password, the handler won't
1748 # handle the HTTP auth error
1749 password_manager.user = password_manager.password = None
1750 http_handler.reset()
1751 opener.open(request_url)
1752 self.assertEqual(len(http_handler.requests), 1)
1753 self.assertFalse(http_handler.requests[0].has_header(auth_header))
1754
1755 def test_basic_prior_auth_auto_send(self):
1756 # Assume already authenticated if is_authenticated=True

Callers 3

check_basic_authMethod · 0.95
test_proxy_basic_authMethod · 0.95

Calls 10

lenFunction · 0.85
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