def __init__(self, url, username, password, **kwargs): super(GerritSession, self).__init__( headers=Headers([('Content-Type', 'application/json')]), **kwargs ) self.url = url self.auth = HTTPDigestAuth(username, password)
def test_digest_authentication(self): sessions = self.client() r = yield from sessions.get(self.httpbin('digest-auth/luca/bla/auth')) self.assertEqual(r.status_code, 401) r = yield from sessions.get(self.httpbin('digest-auth/luca/bla/auth'), auth=HTTPDigestAuth('luca', 'bla')) self.assertEqual(r.status_code, 200)
async def test_digest_authentication_failure(self): sessions = self.client() r = await sessions.get(self.httpbin('digest-auth/luca/bla/auth')) self.assertEqual(r.status_code, 401) r = await sessions.get(self.httpbin('digest-auth/luca/bla/auth'), auth=HTTPDigestAuth('luca', 'foo')) self.assertEqual(r.status_code, 401)
def test_digest_auth(self): auth = HTTPDigestAuth('bla', options={'realm': 'fake realm'}) self.assertEqual(auth.type, 'digest') self.assertEqual(auth.username, 'bla') self.assertEqual(auth.password, None) self.assertEqual(auth.options['realm'], 'fake realm')