def http_request(self, url, method="GET", **kwargs): _kwargs = copy.copy(self.request_args) if kwargs: _kwargs.update(kwargs) if self.cookiejar: _kwargs["cookies"] = self._cookies() logger.debug("SENT COOKIEs: %s" % (_kwargs["cookies"],)) try: r = requests.request(method, url, **_kwargs) except Exception as err: logger.error( "http_request failed: %s, url: %s, htargs: %s, method: %s" % ( err, url, _kwargs, method)) raise if self.event_store is not None: self.event_store.store('http response header', r.headers, ref=url) try: _cookie = r.headers["set-cookie"] # Telekom fix # set_cookie = set_cookie.replace( # "=;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT;HttpOnly,", "") logger.debug("RECEIVED COOKIEs: %s" % _cookie) try: set_cookie(self.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) raise NonFatalException(r, "{}".format(err)) except (AttributeError, KeyError) as err: pass return r
def http_request(self, url, method="GET", **kwargs): _kwargs = copy.copy(self.request_args) if kwargs: _kwargs.update(kwargs) if self.cookiejar: _kwargs["cookies"] = self._cookies() logger.debug("SENT COOKIEs: %s" % (_kwargs["cookies"],)) try: r = requests.request(method, url, **_kwargs) except Exception as err: logger.error( "http_request failed: %s, url: %s, htargs: %s, method: %s" % ( err, url, _kwargs, method)) raise try: _cookie = r.headers["set-cookie"] # Telekom fix # set_cookie = set_cookie.replace( # "=;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT;HttpOnly,", "") logger.debug("RECEIVED COOKIEs: %s" % _cookie) set_cookie(self.cookiejar, SimpleCookie(_cookie)) except (AttributeError, KeyError), err: pass
def http_request(self, url, method="GET", **kwargs): """ Run a HTTP request to fetch the given url This wraps the requests library, so you can pass most requests kwargs to this method to override defaults. :param url: The URL to fetch :param method: The HTTP method to use. :param kwargs: Additional keyword arguments to pass through. """ _kwargs = copy.copy(self.request_args) if kwargs: _kwargs.update(kwargs) if self.cookiejar: _kwargs["cookies"] = self._cookies() logger.debug("SENT {} COOKIES".format(len(_kwargs["cookies"]))) if self.req_callback is not None: _kwargs = self.req_callback(method, url, **_kwargs) try: r = requests.request(method, url, **_kwargs) except Exception as err: logger.error( "http_request failed: %s, url: %s, htargs: %s, method: %s" % ( err, url, sanitize(_kwargs), method)) raise if self.events is not None: self.events.store('HTTP response', r, ref=url) try: _cookie = r.headers["set-cookie"] # Telekom fix # set_cookie = set_cookie.replace( # "=;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT;HttpOnly,", "") logger.debug("RECEIVED COOKIE") try: set_cookie(self.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) raise NonFatalException(r, "{}".format(err)) except (AttributeError, KeyError): pass return r
def test_set_cookie(): cookiejar = FileCookieJar() _cookie = {"value_0": "v_0", "value_1": "v_1", "value_2": "v_2"} c: SimpleCookie = SimpleCookie(_cookie) domain_0 = ".test_domain" domain_1 = "test_domain" max_age = "09 Feb 1994 22:23:32 GMT" expires = http2time(max_age) path = "test/path" c["value_0"]["max-age"] = max_age c["value_0"]["domain"] = domain_0 c["value_0"]["path"] = path c["value_1"]["domain"] = domain_1 util.set_cookie(cookiejar, c) cookies = cookiejar._cookies # type: ignore c_0 = cookies[domain_0][path]["value_0"] c_1 = cookies[domain_1][""]["value_1"] c_2 = cookies[""][""]["value_2"] assert not (c_2.domain_specified and c_2.path_specified) assert ( c_1.domain_specified and not c_1.domain_initial_dot and not c_1.path_specified ) assert c_0.domain_specified and c_0.domain_initial_dot and c_0.path_specified assert c_0.expires == expires assert c_0.domain == domain_0 assert c_0.name == "value_0" assert c_0.path == path assert c_0.value == "v_0" assert not c_1.expires assert c_1.domain == domain_1 assert c_1.name == "value_1" assert c_1.path == "" assert c_1.value == "v_1" assert not c_2.expires assert c_2.domain == "" assert c_2.name == "value_2" assert c_2.path == "" assert c_2.value == "v_2"
def construct_message(self): _kwargs = {'request': self.conv.events.last_item(EV_REQUEST)} _kwargs.update(self.msg_args) _kwargs.update(self.op_args) _op = self.conv.entity _cookie = self.conv.events.last_item('Cookie') try: set_cookie(_op.server.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) else: _kwargs['cookie'] = _op.server._cookies() resp = _op.authorization_endpoint(**_kwargs) return resp
def http_request(self, url, method="GET", **kwargs): """ Run a HTTP request to fetch the given url. This wraps the requests library, so you can pass most requests kwargs to this method to override defaults. :param url: The URL to fetch :param method: The HTTP method to use. :param kwargs: Additional keyword arguments to pass through. """ _kwargs = copy.copy(self.request_args) if kwargs: _kwargs.update(kwargs) if self.cookiejar: _kwargs["cookies"] = self._cookies() logger.debug("SENT {} COOKIES".format(len(_kwargs["cookies"]))) if self.req_callback is not None: _kwargs = self.req_callback(method, url, **_kwargs) try: r = requests.request(method, url, **_kwargs) except Exception as err: logger.error( "http_request failed: %s, url: %s, htargs: %s, method: %s" % (err, url, sanitize(_kwargs), method)) raise if self.events is not None: self.events.store('HTTP response', r, ref=url) try: _cookie = r.headers["set-cookie"] logger.debug("RECEIVED COOKIE") try: set_cookie(self.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) raise NonFatalException(r, "{}".format(err)) except (AttributeError, KeyError): pass return r
def test_set_cookie(): cookiejar = FileCookieJar() _cookie = {"value_0": "v_0", "value_1": "v_1", "value_2": "v_2"} c = SimpleCookie(_cookie) domain_0 = ".test_domain" domain_1 = "test_domain" max_age = "09 Feb 1994 22:23:32 GMT" expires = http2time(max_age) path = "test/path" c["value_0"]["max-age"] = max_age c["value_0"]["domain"] = domain_0 c["value_0"]["path"] = path c["value_1"]["domain"] = domain_1 util.set_cookie(cookiejar, c) cookies = cookiejar._cookies c_0 = cookies[domain_0][path]["value_0"] c_1 = cookies[domain_1][""]["value_1"] c_2 = cookies[""][""]["value_2"] assert not (c_2.domain_specified and c_2.path_specified) assert c_1.domain_specified and not c_1.domain_initial_dot and not c_1.path_specified assert c_0.domain_specified and c_0.domain_initial_dot and c_0.path_specified assert c_0.expires == expires assert c_0.domain == domain_0 assert c_0.name == "value_0" assert c_0.path == path assert c_0.value == "v_0" assert not c_1.expires assert c_1.domain == domain_1 assert c_1.name == "value_1" assert c_1.path == "" assert c_1.value == "v_1" assert not c_2.expires assert c_2.domain == "" assert c_2.name == "value_2" assert c_2.path == "" assert c_2.value == "v_2"
def http_request(self, url, method="GET", **kwargs): _kwargs = copy.copy(self.request_args) if kwargs: _kwargs.update(kwargs) if self.cookiejar: _kwargs["cookies"] = self._cookies() logger.debug("SENT {} COOKIES".format(len(_kwargs["cookies"]))) if self.req_callback is not None: _kwargs = self.req_callback(method, url, **_kwargs) try: r = requests.request(method, url, **_kwargs) except Exception as err: logger.error( "http_request failed: %s, url: %s, htargs: %s, method: %s" % (err, url, sanitize(_kwargs), method)) raise if self.events is not None: self.events.store('HTTP response', r, ref=url) try: _cookie = r.headers["set-cookie"] # Telekom fix # set_cookie = set_cookie.replace( # "=;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT;HttpOnly,", "") logger.debug("RECEIVED COOKIE") try: set_cookie(self.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) raise NonFatalException(r, "{}".format(err)) except (AttributeError, KeyError) as err: pass return r
def construct_message(self): _kwargs = {'request': self.conv.events.last_item(EV_REQUEST)} _kwargs.update(self.msg_args) _kwargs.update(self.op_args) _op = self.conv.entity try: _cookie = self.conv.events.last_item('Cookie') except NoSuchEvent: pass else: try: set_cookie(_op.server.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) else: _kwargs['cookie'] = _op.server._cookies() resp = _op.authorization_endpoint(**_kwargs) if isinstance(resp, SeeOther): save_response(self.conv.events, resp, oic.message.AuthorizationResponse, oic.message.AuthorizationErrorResponse) return resp