~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-17 17:22:26 UTC
  • mto: (2961.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2962.
  • Revision ID: v.ladeuil+lp@free.fr-20071017172226-335k9oh78ljavh54
Make http aware of authentication config.

* bzrlib/transport/ftp.py:
(FtpTransport._create_connection): Also provides port and path to
get_credentials since we know them.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.get_password): Try the authentication config
before prompting the user.

* bzrlib/tests/test_http.py:
(TestAuth.test_no_prompt_for_password_when_using_auth_config):
Corresponding test (applies to raw http and proxy).

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
import bzrlib
31
31
from bzrlib import (
 
32
    config,
32
33
    errors,
33
34
    osutils,
34
35
    ui,
1297
1298
        # Only one 'Authentication Required' error should occur
1298
1299
        self.assertEqual(1, self.server.auth_required_errors)
1299
1300
 
 
1301
    def test_no_prompt_for_password_when_using_auth_config(self):
 
1302
        user =' joe'
 
1303
        password = 'foo'
 
1304
        stdin_content = 'bar\n'  # Not the right password
 
1305
        self.server.add_user(user, password)
 
1306
        t = self.get_user_transport(user, None)
 
1307
        ui.ui_factory = TestUIFactory(stdin=stdin_content)
 
1308
        # Create a minimal config file with the right password
 
1309
        conf = config.AuthenticationConfig()
 
1310
        conf._get_config().update(
 
1311
            {'httptest': {'scheme': 'http', 'port': self.server.port,
 
1312
                          'user': user, 'password': password}})
 
1313
        conf._save()
 
1314
        # Issue a request to the server to connect
 
1315
        self.assertEqual('contents of a\n',t.get('a').read())
 
1316
        # stdin should have  been left untouched
 
1317
        self.assertEqual(stdin_content, ui.ui_factory.stdin.readline())
 
1318
 
 
1319
 
1300
1320
 
1301
1321
class TestHTTPAuth(TestAuth):
1302
1322
    """Test HTTP authentication schemes.