~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-12-29 14:29:16 UTC
  • mfrom: (3920.1.1 bzr.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20081229142916-z08eu2alga2acrh6
(vila) Fix bug #300347 by allowing authentication.conf to be used
        even if no user appears in HTTP[S] urls

Show diffs side-by-side

added added

removed removed

Lines of Context:
1447
1447
    def _testing_pycurl(self):
1448
1448
        return pycurl_present and self._transport == PyCurlTransport
1449
1449
 
1450
 
    def get_user_url(self, user=None, password=None):
 
1450
    def get_user_url(self, user, password):
1451
1451
        """Build an url embedding user and password"""
1452
1452
        url = '%s://' % self.server._url_protocol
1453
1453
        if user is not None:
1458
1458
        url += '%s:%s/' % (self.server.host, self.server.port)
1459
1459
        return url
1460
1460
 
1461
 
    def get_user_transport(self, user=None, password=None):
 
1461
    def get_user_transport(self, user, password):
1462
1462
        return self._transport(self.get_user_url(user, password))
1463
1463
 
1464
1464
    def test_no_user(self):
1465
1465
        self.server.add_user('joe', 'foo')
1466
 
        t = self.get_user_transport()
 
1466
        t = self.get_user_transport(None, None)
1467
1467
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
1468
1468
        # Only one 'Authentication Required' error should occur
1469
1469
        self.assertEqual(1, self.server.auth_required_errors)
1557
1557
        # Only one 'Authentication Required' error should occur
1558
1558
        self.assertEqual(1, self.server.auth_required_errors)
1559
1559
 
 
1560
    def test_user_from_auth_conf(self):
 
1561
        if self._testing_pycurl():
 
1562
            raise tests.TestNotApplicable(
 
1563
                'pycurl does not support authentication.conf')
 
1564
        user = 'joe'
 
1565
        password = 'foo'
 
1566
        self.server.add_user(user, password)
 
1567
        # Create a minimal config file with the right password
 
1568
        conf = config.AuthenticationConfig()
 
1569
        conf._get_config().update(
 
1570
            {'httptest': {'scheme': 'http', 'port': self.server.port,
 
1571
                          'user': user, 'password': password}})
 
1572
        conf._save()
 
1573
        t = self.get_user_transport(None, None)
 
1574
        # Issue a request to the server to connect
 
1575
        self.assertEqual('contents of a\n', t.get('a').read())
 
1576
        # Only one 'Authentication Required' error should occur
 
1577
        self.assertEqual(1, self.server.auth_required_errors)
 
1578
 
1560
1579
    def test_changing_nonce(self):
1561
1580
        if self._auth_scheme != 'digest':
1562
1581
            raise tests.TestNotApplicable('HTTP auth digest only test')
1608
1627
                protocol_version=self._protocol_version)
1609
1628
        return server
1610
1629
 
1611
 
    def get_user_transport(self, user=None, password=None):
 
1630
    def get_user_transport(self, user, password):
1612
1631
        self._install_env({'all_proxy': self.get_user_url(user, password)})
1613
1632
        return self._transport(self.server.get_url())
1614
1633