~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Martin Pool
  • Date: 2010-10-12 07:19:06 UTC
  • mto: This revision was merged to the branch mainline in revision 5487.
  • Revision ID: mbp@sourcefrog.net-20101012071906-q14axyz0rpmmt5aw
Add failing test for AbstractAuthHandler and bug 654684

Show diffs side-by-side

added added

removed removed

Lines of Context:
1604
1604
        ui.ui_factory = tests.TestUIFactory(stdin=stdin_content,
1605
1605
                                            stderr=tests.StringIOWrapper())
1606
1606
        # Create a minimal config file with the right password
1607
 
        conf = config.AuthenticationConfig()
1608
 
        conf._get_config().update(
1609
 
            {'httptest': {'scheme': 'http', 'port': self.server.port,
1610
 
                          'user': user, 'password': password}})
1611
 
        conf._save()
 
1607
        _setup_authentication_config(
 
1608
            scheme='http', 
 
1609
            port=self.server.port,
 
1610
            user=user,
 
1611
            password=password)
1612
1612
        # Issue a request to the server to connect
1613
1613
        self.assertEqual('contents of a\n',t.get('a').read())
1614
1614
        # stdin should have  been left untouched
1616
1616
        # Only one 'Authentication Required' error should occur
1617
1617
        self.assertEqual(1, self.server.auth_required_errors)
1618
1618
 
1619
 
    def test_user_from_auth_conf(self):
1620
 
        if self._testing_pycurl():
1621
 
            raise tests.TestNotApplicable(
1622
 
                'pycurl does not support authentication.conf')
1623
 
        user = 'joe'
1624
 
        password = 'foo'
1625
 
        self.server.add_user(user, password)
1626
 
        # Create a minimal config file with the right password
1627
 
        conf = config.AuthenticationConfig()
1628
 
        conf._get_config().update(
1629
 
            {'httptest': {'scheme': 'http', 'port': self.server.port,
1630
 
                          'user': user, 'password': password}})
1631
 
        conf._save()
1632
 
        t = self.get_user_transport(None, None)
1633
 
        # Issue a request to the server to connect
1634
 
        self.assertEqual('contents of a\n', t.get('a').read())
1635
 
        # Only one 'Authentication Required' error should occur
1636
 
        self.assertEqual(1, self.server.auth_required_errors)
1637
 
 
1638
1619
    def test_changing_nonce(self):
1639
1620
        if self._auth_server not in (http_utils.HTTPDigestAuthServer,
1640
1621
                                     http_utils.ProxyDigestAuthServer):
1656
1637
        # initial 'who are you' and a second 'who are you' with the new nonce)
1657
1638
        self.assertEqual(2, self.server.auth_required_errors)
1658
1639
 
 
1640
    def test_user_from_auth_conf(self):
 
1641
        if self._testing_pycurl():
 
1642
            raise tests.TestNotApplicable(
 
1643
                'pycurl does not support authentication.conf')
 
1644
        user = 'joe'
 
1645
        password = 'foo'
 
1646
        self.server.add_user(user, password)
 
1647
        _setup_authentication_config(
 
1648
            scheme='http', 
 
1649
            port=self.server.port,
 
1650
            user=user,
 
1651
            password=password)
 
1652
        t = self.get_user_transport(None, None)
 
1653
        # Issue a request to the server to connect
 
1654
        self.assertEqual('contents of a\n', t.get('a').read())
 
1655
        # Only one 'Authentication Required' error should occur
 
1656
        self.assertEqual(1, self.server.auth_required_errors)
 
1657
 
 
1658
 
 
1659
def _setup_authentication_config(**kwargs):
 
1660
    conf = config.AuthenticationConfig()
 
1661
    conf._get_config().update({'httptest': kwargs})
 
1662
    conf._save()
 
1663
 
 
1664
 
 
1665
 
 
1666
class TestUrllib2AuthHandler(tests.TestCase):
 
1667
    """Unit tests for glue by which urllib2 asks us for authentication"""
 
1668
 
 
1669
    def test_get_user_password_without_port(self):
 
1670
        """We cope if urllib2 doesn't tell us the port.
 
1671
 
 
1672
        See https://bugs.launchpad.net/bzr/+bug/654684
 
1673
        """
 
1674
        user = 'joe'
 
1675
        password = 'foo'
 
1676
        _setup_authentication_config(
 
1677
            scheme='http', 
 
1678
            port=80,
 
1679
            host='localhost',
 
1680
            user=user,
 
1681
            password=password)
 
1682
        handler = _urllib2_wrappers.AbstractAuthHandler()
 
1683
        got_pass = handler.get_user_password(dict(
 
1684
            protocol='http',
 
1685
            host='localhost',
 
1686
            path='/',
 
1687
            realm='Realm',
 
1688
            ))
 
1689
        self.assertEquals(password, got_pass)
1659
1690
 
1660
1691
 
1661
1692
class TestProxyAuth(TestAuth):