Module: check_mk
Branch: master
Commit: 104e72ce3f000d7551a8afcf23be031381be8d81
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=104e72ce3f000d…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jan 3 14:22:12 2019 +0100
Decouple Respose from Request.
Change-Id: Id422425e0ad39166d290ca2f14c486167720e724
---
cmk/gui/http.py | 8 +++-----
tests/unit/cmk/gui/conftest.py | 2 +-
tests/unit/cmk/gui/old/classes.py | 2 +-
tests/unit/cmk/gui/test_http.py | 3 +--
web/app/index.wsgi | 2 +-
5 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/cmk/gui/http.py b/cmk/gui/http.py
index a2c428a..99334bc 100644
--- a/cmk/gui/http.py
+++ b/cmk/gui/http.py
@@ -256,12 +256,10 @@ class Response(object):
over to the WSGI server for sending the response to the client.
"""
- def __init__(self, request):
+ def __init__(self, secure):
super(Response, self).__init__()
self._logger = log.logger.getChild("http.Response")
-
- self._request = request
-
+ self._secure = secure
self._status_code = cmk.gui.http_status.HTTP_OK
self._output = []
self._headers_out = []
@@ -300,7 +298,7 @@ class Response(object):
# Tell client not to use the cookie within javascript
httponly=True,
# Tell client to only use the cookie for SSL connections
- secure=self._request.is_ssl_request,
+ secure=self._secure,
expires=expires,
)
diff --git a/tests/unit/cmk/gui/conftest.py b/tests/unit/cmk/gui/conftest.py
index 17f10ad..fae87a4 100644
--- a/tests/unit/cmk/gui/conftest.py
+++ b/tests/unit/cmk/gui/conftest.py
@@ -21,6 +21,6 @@ def register_builtin_html():
"REQUEST_URI": "",
}
_request = http.Request(wsgi_environ)
- _response = http.Response(_request)
+ _response = http.Response(_request.is_ssl_request)
html.set_current(htmllib.html(_request, _response))
diff --git a/tests/unit/cmk/gui/old/classes.py b/tests/unit/cmk/gui/old/classes.py
index 64960ba..c863dd9 100644
--- a/tests/unit/cmk/gui/old/classes.py
+++ b/tests/unit/cmk/gui/old/classes.py
@@ -18,7 +18,7 @@ class HTMLTester(htmllib.html):
"SCRIPT_NAME" : "",
}
_request = http.Request(wsgi_environ)
- _response = http.Response(_request)
+ _response = http.Response(_request.is_ssl_request)
super(HTMLTester, self).__init__(_request, _response)
diff --git a/tests/unit/cmk/gui/test_http.py b/tests/unit/cmk/gui/test_http.py
index bcf03d0..8cc0c96 100644
--- a/tests/unit/cmk/gui/test_http.py
+++ b/tests/unit/cmk/gui/test_http.py
@@ -52,8 +52,7 @@ def test_response_set_cookie(register_builtin_html):
def test_response_set_cookie_secure(register_builtin_html, monkeypatch):
- # TODO: Find better way to directly patch the property html.request.is_ssl_request
- monkeypatch.setitem(html.request._wsgi_environ, "HTTP_X_FORWARDED_PROTO",
"https")
+ monkeypatch.setattr(html.response, "_secure", True)
html.response.set_cookie("auth_SITE", "user:123456:abcdefg")
diff --git a/web/app/index.wsgi b/web/app/index.wsgi
index 43d73e5..6f62693 100644
--- a/web/app/index.wsgi
+++ b/web/app/index.wsgi
@@ -66,7 +66,7 @@ class Application(object):
def __init__(self, wsgi_environ, start_response):
self._start_response = start_response
self._request = cmk.gui.http.Request(wsgi_environ)
- self._response = cmk.gui.http.Response(self._request)
+ self._response = cmk.gui.http.Response(self._request.is_ssl_request)
# Create an object that contains all data about the request and
# helper functions for creating valid HTML. Parse URI and