示例#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)
示例#2
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)
示例#3
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)
示例#4
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)
示例#5
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_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)
示例#7
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)
示例#8
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(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)
示例#10
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)
示例#11
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)
示例#12
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')
示例#13
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')
示例#14
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)
示例#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')
示例#16
0
    def handle_results(self, results, session_key, in_preview):

        # FYI: we ignore results since this is a generating command

        # Make sure that the url field was provided
        if self.url is None:
            self.logger.warn("No url was provided")
            return

        # Parse the URL
        url_field = URLField('name', 'title', 'description')
        url_parsed = url_field.to_python(self.url)

        # Do the web-ping
        result = WebPing.ping(url_parsed,
                              logger=self.logger,
                              should_contain_string=self.expected_string,
                              return_headers=self.return_headers)

        # Prep the result dictionary
        data = {
            'response_code':
            result.response_code if result.response_code > 0 else '',
            'total_time':
            round(result.request_time, 2) if result.request_time > 0 else '',
            'timed_out':
            result.timed_out,
            'url':
            result.url
        }

        # Add the MD5 of the response if available
        if result.response_md5 is not None:
            data['content_md5'] = result.response_md5

        # Add the SHA-224 of the response if available
        if result.response_sha224 is not None:
            data['content_sha224'] = result.response_sha224

        # Add the size of the response if available
        if result.response_size is not None:
            data['content_size'] = result.response_size

        # Add the variable noting if the expected string was present
        if result.has_expected_string is not None:
            data['has_expected_string'] = str(
                result.has_expected_string).lower()

        # Add the the headers if present
        if result.headers is not None:
            for header in result.headers:
                data['header_' + header] = result.headers[header]

        # Output the results
        self.output_results([data])
示例#17
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)
示例#18
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)
示例#19
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="******"))
示例#20
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)
示例#21
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)
示例#22
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)
示例#23
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)
示例#24
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)
示例#25
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)
示例#26
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)
示例#27
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)
    def handle_results(self, results, session_key, in_preview):

        # FYI: we ignore results since this is a generating command

        # Make sure that the url field was provided
        if self.url is None:
            self.logger.warn("No url was provided")
            return

        # Parse the URL
        url_field = URLField('name','title','description')
        url_parsed = url_field.to_python(self.url)

        # Do the web-ping
        result = WebPing.ping(url_parsed, logger=self.logger, should_contain_string=self.expected_string)

        # Prep the result dictionary
        data = {
            'response_code': result.response_code if result.response_code > 0 else '',
            'total_time': round(result.request_time, 2) if result.request_time > 0 else '',
            'timed_out': result.timed_out,
            'url': result.url
        }

        # Add the MD5 of the response of available
        if result.response_md5 is not None:
            data['content_md5'] = result.response_md5

        # Add the SHA-224 of the response of available
        if result.response_sha224 is not None:
            data['content_sha224'] = result.response_sha224

        # Add the MD5 of the response of available
        if result.response_size is not None:
            data['content_size'] = result.response_size

        # Add the variable noting if the expected string was present
        if result.has_expected_string is not None:
            data['has_expected_string'] = str(result.has_expected_string).lower()

        # Output the results
        self.output_results([data])
示例#29
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)