Exemplo n.º 1
0
 def test_build_url_forward_headers(self):
     request = DummyRequest()
     request.environ = {
         "SERVER_NAME": "example.com"
     }
     request.registry.settings = {
         "checker": {
             "forward_headers": ["Cookie"]
         }
     }
     request.headers["Cookie"] = "test"
     self.assertEqual(
         build_url(
             "Test",
             "https://camptocamp.com/toto?titi#tutu",
             request
         ),
         {
             "url": "https://camptocamp.com/toto?titi#tutu",
             "headers": {
                 "Cache-Control": "no-cache",
                 "Cookie": "test",
             }
         }
     )
Exemplo n.º 2
0
 def test_build_url_other(self):
     self.assertEqual(
         build_url("Test", "https://camptocamp.com/toto?titi#tutu",
                   self._create_dummy_request()), {
                       "url": "https://camptocamp.com/toto?titi#tutu",
                       "headers": {
                           "Cache-Control": "no-cache",
                       }
                   })
Exemplo n.º 3
0
 def check(request):
     params = request.params
     display = host["display"]
     if "host" not in params or display == params["host"]:
         url_headers = build_url(
             "check_collector", "%s%s/health_check" % (host["url"], c2c_base), request
         )
         r = requests.get(params={"max_level": str(host.get("max_level", max_level))}, **url_headers)
         r.raise_for_status()
Exemplo n.º 4
0
 def test_build_url_https(self):
     self.assertEqual(
         build_url("Test", "https://example.com/toto?titi#tutu",
                   self._create_dummy_request()), {
                       "url": "http://localhost/toto?titi#tutu",
                       "headers": {
                           "Cache-Control": "no-cache",
                           "Host": "example.com"
                       }
                   })
 def check(request):
     params = request.params
     display = host["display"]
     if "host" not in params or display == params["host"]:
         url_headers = build_url(
             "check_collector",
             "%s/%s/health_check" % (host["url"], c2c_base), request)
         r = requests.get(params={
             "max_level":
             str(host.get("max_level", max_level))
         },
                          **url_headers)
         r.raise_for_status()
Exemplo n.º 6
0
 def test_build_url_docker(self):
     request = DummyRequest()
     request.registry.settings = {
         "checker": {
             "base_internal_url": "http://localhost:8080",
         }
     }
     self.assertEqual(
         build_url("Test", "/toto?titi#tutu", request), {
             "url": "http://localhost:8080/toto?titi#tutu",
             "headers": {
                 "Cache-Control": "no-cache",
             }
         })
Exemplo n.º 7
0
 def test_build_url_other(self):
     self.assertEqual(
         build_url(
             "Test",
             "https://camptocamp.com/toto?titi#tutu",
             self._create_dummy_request()
         ),
         {
             "url": "https://camptocamp.com/toto?titi#tutu",
             "headers": {
                 "Cache-Control": "no-cache",
             }
         }
     )
Exemplo n.º 8
0
 def test_build_url_https(self):
     self.assertEqual(
         build_url(
             "Test",
             "https://example.com/toto?titi#tutu",
             self._create_dummy_request()
         ),
         {
             "url": "http://localhost/toto?titi#tutu",
             "headers": {
                 "Cache-Control": "no-cache",
                 "Host": "example.com"
             }
         }
     )
Exemplo n.º 9
0
 def test_build_url_https(self):
     request = DummyRequest()
     request.registry.settings = {
         "checker": {
             "base_internal_url": "https://localhost",
             "forward_host": True,
         }
     }
     self.assertEqual(
         build_url("Test", "/toto?titi#tutu", request), {
             "url": "https://localhost/toto?titi#tutu",
             "headers": {
                 "Cache-Control": "no-cache",
                 "Host": "example.com:80"
             }
         })
Exemplo n.º 10
0
 def test_build_url_forward_headers(self):
     request = DummyRequest()
     request.registry.settings = {
         "checker": {
             "base_internal_url": "http://localhost",
             "forward_headers": ["Cookie"]
         }
     }
     request.headers["Cookie"] = "test"
     self.assertEqual(
         build_url("Test", "/toto?titi#tutu", request), {
             "url": "http://localhost/toto?titi#tutu",
             "headers": {
                 "Cache-Control": "no-cache",
                 "Cookie": "test",
             }
         })
Exemplo n.º 11
0
 def test_build_url_forward_headers(self):
     request = DummyRequest()
     request.environ = {"SERVER_NAME": "example.com"}
     request.registry.settings = {
         "checker": {
             "forward_headers": ["Cookie"]
         }
     }
     request.headers["Cookie"] = "test"
     self.assertEqual(
         build_url("Test", "https://camptocamp.com/toto?titi#tutu",
                   request), {
                       "url": "https://camptocamp.com/toto?titi#tutu",
                       "headers": {
                           "Cache-Control": "no-cache",
                           "Cookie": "test",
                       }
                   })
Exemplo n.º 12
0
 def __call__(self, request) -> Any:  # pylint: disable=inconsistent-return-statements
     params = request.params
     display = self.host["display"]
     if "host" not in params or display == params["host"]:
         url_headers = build_url(
             "check_collector",
             "%s/%s/health_check" %
             (self.host["url"].rstrip("/"), c2c_base.strip("/")),
             request,
         )
         r = requests.get(
             params={
                 "max_level":
                 str(self.host.get("max_level", max_level))
             },
             timeout=120,
             **url_headers,
         )
         r.raise_for_status()
         return r.json()
Exemplo n.º 13
0
 def __call__(
         self, request: pyramid.request.Request
 ) -> Optional[Dict[str, Any]]:
     params = request.params
     display = self.host["display"]
     if "host" not in params or display == params["host"]:
         url_headers = build_url(
             "check_collector",
             f"{self.host['url'].rstrip('/')}/{c2c_base.strip('/')}/health_check",
             request,
         )
         r = requests.get(
             params={
                 "max_level":
                 str(self.host.get("max_level", max_level))
             },
             timeout=120,
             **url_headers,  # type: ignore
         )
         r.raise_for_status()
         return cast(Dict[str, Any], r.json())
     return None