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

Method test_basic_auth

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

Source from the content-addressed store, hash-verified

1601 "http://acme.example.com/protected")
1602
1603 def test_basic_auth(self):
1604 realm = "realm2@example.com"
1605 realm2 = "realm2@example.com"
1606 basic = f'Basic realm="{realm}"'
1607 basic2 = f'Basic realm="{realm2}"'
1608 other_no_realm = 'Otherscheme xxx'
1609 digest = (f'Digest realm="{realm2}", '
1610 f'qop="auth, auth-int", '
1611 f'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '
1612 f'opaque="5ccc069c403ebaf9f0171e9517f40e41"')
1613 for realm_str in (
1614 # test "quote" and 'quote'
1615 f'Basic realm="{realm}"',
1616 f"Basic realm='{realm}'",
1617
1618 # charset is ignored
1619 f'Basic realm="{realm}", charset="UTF-8"',
1620
1621 # Multiple challenges per header
1622 f'{basic}, {basic2}',
1623 f'{basic}, {other_no_realm}',
1624 f'{other_no_realm}, {basic}',
1625 f'{basic}, {digest}',
1626 f'{digest}, {basic}',
1627 ):
1628 headers = [f'WWW-Authenticate: {realm_str}']
1629 self.check_basic_auth(headers, realm)
1630
1631 # no quote: expect a warning
1632 with warnings_helper.check_warnings(("Basic Auth Realm was unquoted",
1633 UserWarning)):
1634 headers = [f'WWW-Authenticate: Basic realm={realm}']
1635 self.check_basic_auth(headers, realm)
1636
1637 # Multiple headers: one challenge per header.
1638 # Use the first Basic realm.
1639 for challenges in (
1640 [basic, basic2],
1641 [basic, digest],
1642 [digest, basic],
1643 ):
1644 headers = [f'WWW-Authenticate: {challenge}'
1645 for challenge in challenges]
1646 self.check_basic_auth(headers, realm)
1647
1648 def test_proxy_basic_auth(self):
1649 opener = OpenerDirector()

Callers

nothing calls this directly

Calls 1

check_basic_authMethod · 0.95

Tested by

no test coverage detected