Example #1
0
    def test_ping_with_basic_authentication(self):

        # Try with valid authentication
        url_field = URLField("test_ping", "title", "this is a test")
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" +
                                                  str(self.web_server_port)),
                              timeout=3,
                              username="******",
                              password="******")

        self.assertEquals(result.response_code, 200)

        self.assertEquals(result.response_md5,
                          '1f6c14189070f50c4c06ada640c14850'
                          )  # This is 1f6c14189070f50c4c06ada640c14850 on disk
        self.assertEquals(
            result.response_sha224,
            'deaf4c0062539c98b4e957712efcee6d42832fed2d803c2bbf984b23')

        # Verify that bad authentication fails
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" +
                                                  str(self.web_server_port)),
                              timeout=3,
                              username="******",
                              password="******")

        self.assertEquals(result.response_code, 401)
        self.assertGreater(result.request_time, 0)
Example #2
0
    def test_determine_auth_method_ntlm_comma_header(self):

        # Try with digest auth
        url_field = URLField( "test_ping", "title", "this is a test")
        auth_type = WebPing.determine_auth_type(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/ntlm_auth_negotiate"))

        self.assertEqual(auth_type, WebPing.HTTP_AUTH_NTLM)
Example #3
0
    def test_ping_with_ntlm_negotiate_authentication(self):

        # Try with valid authentication
        url_field = URLField("test_ping", "title", "this is a test")
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/ntlm_auth_negotiate"), timeout=3, username="******", password="******")

        self.assertEqual(result.response_code, 200)
 def test_ping_with_digest_authentication(self):
     
     # Try with valid authentication
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://httpbin.org/digest-auth/auth/user/passwd"), timeout=3, username="******", password="******" )
     
     self.assertEquals(result.response_code, 200)
 def test_determine_auth_method_basic(self):
     
     # Try with basic auth
     url_field = URLField( "test_ping", "title", "this is a test" )
     auth_type = WebPing.determine_auth_type( url_field.to_python("http://127.0.0.1:8888"))
     
     self.assertEquals(auth_type, WebPing.HTTP_AUTH_BASIC)
 def test_determine_auth_method_digest(self):
     
     # Try with digest auth
     url_field = URLField( "test_ping", "title", "this is a test" )
     auth_type = WebPing.determine_auth_type( url_field.to_python("http://httpbin.org/digest-auth/auth/user/passwd"))
     
     self.assertEquals(auth_type, WebPing.HTTP_AUTH_DIGEST)
Example #7
0
    def test_ping_timeout(self):
        url_field = URLField("test_ping_timeout", "title", "this is a test")

        result = WebPing.ping(url_field.to_python("https://192.168.30.23/"),
                              timeout=3)

        self.assertEquals(result.timed_out, True)
 def test_determine_auth_method_none(self):
     
     # Try with digest auth
     url_field = URLField( "test_ping", "title", "this is a test" )
     auth_type = WebPing.determine_auth_type( url_field.to_python("http://127.0.0.1:8888/test_page"))
     
     self.assertEquals(auth_type, WebPing.HTTP_AUTH_NONE)
Example #9
0
 def test_ping(self):
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     
     result = WebPing.ping( url_field.to_python("https://www.google.com/"), timeout=3 )
     
     self.assertEquals(result.response_code, 200)
     self.assertGreater(result.request_time, 0)
 def test_ping(self):
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     
     result = WebPing.ping( url_field.to_python("https://www.google.com/"), timeout=3 )
     
     self.assertEquals(result.response_code, 200)
     self.assertGreater(result.request_time, 0)
Example #11
0
    def test_ping(self):

        url_field = URLField("test_ping", "title", "this is a test")

        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page"), timeout=3)

        self.assertEqual(result.response_code, 200)
        self.assertGreater(result.request_time, 0)
 def test_ping_non_existent_domain(self):
     # https://answers.splunk.com/answers/337070/website-monitoring-app-setup.html#answer-338487
     
     url_field = URLField( "test_ping_non_existent_domain", "title", "this is a test" )
     
     result = WebPing.ping( url_field.to_python("http://xyz"), timeout=3 )
     
     self.assertEquals(result.response_code, 0)
     self.assertEquals(result.request_time, 0)
Example #13
0
    def test_url_field_invalid(self):
        url_field = URLField("test_url_field_invalid", "title",
                             "this is a test")

        self.assertRaises(FieldValidationException,
                          lambda: url_field.to_python("hxxp://google.com"))
        self.assertRaises(FieldValidationException,
                          lambda: url_field.to_python("http://"))
        self.assertRaises(FieldValidationException,
                          lambda: url_field.to_python("google.com"))
 def test_hash(self):
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     
     result = WebPing.ping( url_field.to_python("http://127.0.0.1:8888/test_page"), timeout=3 )
     
     self.assertEquals(result.response_code, 200)
     
     self.assertEquals(result.response_md5, '1f6c14189070f50c4c06ada640c14850') # This is 1f6c14189070f50c4c06ada640c14850 on disk
     self.assertEquals(result.response_sha224, 'deaf4c0062539c98b4e957712efcee6d42832fed2d803c2bbf984b23')
Example #15
0
 def test_hash(self):
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     
     result = WebPing.ping( url_field.to_python("http://127.0.0.1:8888/test_page"), timeout=3 )
     
     self.assertEquals(result.response_code, 200)
     
     self.assertEquals(result.response_md5, '1f6c14189070f50c4c06ada640c14850') # This is 1f6c14189070f50c4c06ada640c14850 on disk
     self.assertEquals(result.response_sha224, 'deaf4c0062539c98b4e957712efcee6d42832fed2d803c2bbf984b23')
Example #16
0
    def test_ping_super_long_url(self):
        # https://answers.splunk.com/answers/488784/why-my-website-monitoring-only-check-1-time.html

        url_field = URLField("test_ping", "title", "this is a test")

        #result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page?s=superloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"), timeout=3)
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page_superlooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"), timeout=3)

        self.assertEqual(result.response_code, 200)
        self.assertGreater(result.request_time, 0)
Example #17
0
    def test_ping_over_proxy(self):

        url_field = URLField("test_ping", "title", "this is a test")
        result = WebPing.ping(url_field.to_python("http://textcritical.com"),
                              timeout=3,
                              proxy_type=self.proxy_type,
                              proxy_server=self.proxy_address,
                              proxy_port=self.proxy_port)

        self.assertEquals(result.response_code, 200)
Example #18
0
    def test_ping_with_headers(self):

        url_field = URLField("test_ping", "title", "this is a test")

        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page"), timeout=3, return_headers=True)

        self.assertEqual(result.response_code, 200)
        self.assertGreater(result.request_time, 0)
        self.assertGreater(len(result.headers), 0)
        self.assertEqual(result.headers['Content-type'], 'text/html')
Example #19
0
    def test_should_contain_string_no_match(self):

        url_field = URLField("test_ping", "title", "this is a test")

        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page"), timeout=3, should_contain_string="<h1>Should not Match!</h1>")

        self.assertEqual(result.response_code, 200)

        self.assertEqual(result.response_md5, '1f6c14189070f50c4c06ada640c14850') # This is 1f6c14189070f50c4c06ada640c14850 on disk
        self.assertEqual(result.response_sha224, 'deaf4c0062539c98b4e957712efcee6d42832fed2d803c2bbf984b23')
        self.assertEqual(result.has_expected_string, False)
 def test_output_result(self):
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("https://www.google.com/"), timeout=3 )
     
     out = StringIO()
     
     web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)
     
     self.assertTrue(out.getvalue().find("response_code=200") >= 0)
 def test_output_result_unavailable(self):
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://192.168.30.23/"), timeout=3 )
     
     out = StringIO()
     
     web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)
     
     self.assertTrue(out.getvalue().find("timed_out=True") >= 0)
Example #22
0
    def test_output_result(self):
        web_ping = WebPing(timeout=3)

        url_field = URLField("test_ping", "title", "this is a test")
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page"), timeout=3)

        out = StringIO()

        web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)

        self.assertTrue(out.getvalue().find("response_code=200") >= 0)
Example #23
0
    def test_ping_with_ntlm_authentication_missing_domain(self):

        # Try with missing domain
        url_field = URLField("test_ping", "title", "this is a test")
        self.assertRaises(
            NTLMAuthenticationValueException,
            lambda: WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(
                self.web_server_port) + "/ntlm_auth"),
                                 timeout=3,
                                 username="******",
                                 password="******"))
Example #24
0
 def test_output_result_unavailable(self):
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://192.168.30.23/"), timeout=3 )
     
     out = StringIO()
     
     web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)
     
     self.assertTrue(out.getvalue().find("timed_out=True") >= 0)
Example #25
0
 def test_output_result(self):
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("https://www.google.com/"), timeout=3 )
     
     out = StringIO()
     
     web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)
     
     self.assertTrue(out.getvalue().find("response_code=200") >= 0)
Example #26
0
    def test_url_field_valid(self):
        url_field = URLField("test_url_field_valid", "title", "this is a test")

        self.assertEqual(
            url_field.to_python("http://google.com").geturl(),
            "http://google.com")
        self.assertEqual(
            url_field.to_python("http://google.com/with/path").geturl(),
            "http://google.com/with/path")
        self.assertEqual(
            url_field.to_python("http://google.com:8080/with/port").geturl(),
            "http://google.com:8080/with/port")
Example #27
0
    def test_missing_servername(self):
        """
        Some web-servers require that the "Host" be included on SSL connections when the server is hosting multiple domains on the same IP.

        Without the host header, the server is unable to determine which certificate to provide and thus closes the connection.

        http://lukemurphey.net/issues/1035
        """

        url_field = URLField("test_ping", "title", "this is a test")
        result = WebPing.ping(url_field.to_python("https://lukemurphey.net"), timeout=3)

        self.assertEqual(result.response_code, 200)
Example #28
0
 def test_ping_with_basic_authentication_optional(self):
     
     # Try with valid authentication
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://127.0.0.1:8888/optional_auth"), timeout=3, username="******", password="******" )
     
     self.assertEquals(result.response_code, 203)
     
     # Verify that no authentication still works
     result = WebPing.ping( url_field.to_python("http://127.0.0.1:8888/optional_auth"), timeout=3)
     
     self.assertEquals(result.response_code, 202)
     self.assertGreater(result.request_time, 0)
Example #29
0
 def test_missing_servername(self):
     """
     Some web-servers require that the "Host" be included on SSL connections when the server is hosting multiple domains on the same IP.
     
     Without the host header, the server is unable to determine which certificate to provide and thus closes the connection.
     
     http://lukemurphey.net/issues/1035
     """
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("https://www.penfolds.com"), timeout=3 )
     
     self.assertEquals(result.response_code, 200)
Example #30
0
    def test_custom_user_agent(self):
        """
        http://lukemurphey.net/issues/1341
        """

        url_field = URLField("test_ping", "title", "this is a test")

        # Make sure that the server is validating the user-agent by returning 200 when the user-agent doesn't match
        # This just validates that the test case works
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/user_agent_check"), user_agent="USER_AGENT_CHECK_DOESNT_MATCH", timeout=3)
        self.assertEqual(result.response_code, 200)

        # Make sure that the server is validating the user-agent which returns 201 when the user-agent matches "USER_AGENT_CHECK"
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/user_agent_check"), user_agent="USER_AGENT_CHECK", timeout=3)
        self.assertEqual(result.response_code, 201)
 def test_ping_over_proxy(self):
     
     if self.proxy_address is None:
         print "No proxy address defined, proxy based test will not run"
         return
         
     if self.proxy_port is None:
         print "No proxy port defined, proxy based test will not run"
         return
         
     if self.proxy_type is None:
         print "No proxy type defined, proxy based test will not run"
         return
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://textcritical.com"), timeout=3, proxy_type=self.proxy_type, proxy_server=self.proxy_address, proxy_port=self.proxy_port)
     
     self.assertEquals(result.response_code, 200)
Example #32
0
 def test_ping_over_proxy(self):
     
     if self.proxy_address is None:
         print "No proxy address defined, proxy based test will not run"
         return
         
     if self.proxy_port is None:
         print "No proxy port defined, proxy based test will not run"
         return
         
     if self.proxy_type is None:
         print "No proxy type defined, proxy based test will not run"
         return
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://textcritical.com"), timeout=3, proxy_type=self.proxy_type, proxy_server=self.proxy_address, proxy_port=self.proxy_port)
     
     self.assertEquals(result.response_code, 200)
Example #33
0
 def test_url_field_invalid(self):
     url_field = URLField( "test_url_field_invalid", "title", "this is a test" )
     
     self.assertRaises( FieldValidationException, lambda: url_field.to_python("hxxp://google.com") )
     self.assertRaises( FieldValidationException, lambda: url_field.to_python("http://") )
     self.assertRaises( FieldValidationException, lambda: url_field.to_python("google.com") )
Example #34
0
 def test_url_field_valid(self):
     url_field = URLField( "test_url_field_valid", "title", "this is a test" )
     
     self.assertEqual( url_field.to_python("http://google.com").geturl(), "http://google.com" )
     self.assertEqual( url_field.to_python("http://google.com/with/path").geturl(), "http://google.com/with/path" )
     self.assertEqual( url_field.to_python("http://google.com:8080/with/port").geturl(), "http://google.com:8080/with/port" )
Example #35
0
 def test_ping_timeout(self):
     url_field = URLField( "test_ping_timeout", "title", "this is a test" )
     
     result = WebPing.ping( url_field.to_python("https://192.168.30.23/"), timeout=3 )
     
     self.assertEquals(result.timed_out, True)