def test_from_dict_lower_case_fields(self): err = httpbakery.Error.from_dict({ 'message': 'm', 'code': 'c', }) self.assertEqual( err, httpbakery.Error( code='c', message='m', info=None, version=bakery.LATEST_VERSION, ))
def check_third_party_caveat(self, ctx, info): InfoStorage.info = info raise InteractionRequiredError( httpbakery.Error( code=httpbakery.ERR_INTERACTION_REQUIRED, version=httpbakery.request_version( request.headers), message='interaction required', info=httpbakery.ErrorInfo( wait_url='http://0.3.2.1/wait?' 'dischargeid=1', visit_url='http://0.3.2.1/visit?' 'dischargeid=1'), ), )
def test_handle_error_cookie_path(self): macaroon = bakery.Macaroon(root_key=b'some key', id=b'xxx', location='some location', version=bakery.VERSION_0) info = { 'Macaroon': macaroon.to_dict(), 'MacaroonPath': '.', 'CookieNameSuffix': 'test' } error = httpbakery.Error(code=407, message='error', version=bakery.LATEST_VERSION, info=httpbakery.ErrorInfo.from_dict(info)) client = httpbakery.Client() client.handle_error(error, 'http://example.com/some/path') [cookie] = client.cookies self.assertEqual(cookie.path, "/some/")
async def _connect_with_login(self, endpoints): """Connect to the websocket. If uuid is None, the connection will be to the controller. Otherwise it will be to the model. :return: The response field of login response JSON object. """ success = False try: await self._connect(endpoints) # It's possible that we may get several discharge-required errors, # corresponding to different levels of authentication, so retry # a few times. for i in range(0, 2): result = (await self.login())['response'] macaroonJSON = result.get('discharge-required') if macaroonJSON is None: self.info = result success = True return result macaroon = bakery.Macaroon.from_dict(macaroonJSON) self.bakery_client.handle_error( httpbakery.Error( code=httpbakery.ERR_DISCHARGE_REQUIRED, message=result.get('discharge-required-error'), version=macaroon.version, info=httpbakery.ErrorInfo( macaroon=macaroon, macaroon_path=result.get('macaroon-path'), ), ), # note: remove the port number. 'https://' + self.endpoint + '/', ) raise errors.JujuAuthError('failed to authenticate ' 'after several attempts') finally: if not success: await self.close() else: self._pinger_task.start()