コード例 #1
0
    def verify(self, base_url):
        '''
        Parses the given HTML string and asks the
        FortuneHTMLParser whether the parsed string is a
        valid fortune response
        '''

        url = base_url + self.fortune_url
        headers, body = self.request_headers_and_body(url)

        _, problems = basic_body_verification(body, url, is_json_check=False)

        if len(problems) > 0:
            return problems

        parser = FortuneHTMLParser()
        parser.feed(body)
        (valid, diff) = parser.isValidFortune(self.name, body)

        if valid:
            problems += verify_headers(self.request_headers_and_body,
                                       headers,
                                       url,
                                       should_be='html')

            if len(problems) == 0:
                return [('pass', '', url)]
            else:
                return problems
        else:
            failures = []
            failures.append(
                ('fail', 'Invalid according to FortuneHTMLParser', url))
            failures += self._parseDiffForFailure(diff, failures, url)
            return failures
コード例 #2
0
    def verify(self, base_url):
        """
        Validates the response is a JSON object of 
        { 'message' : 'hello, world!' }. Case insensitive and 
        quoting style is ignored
        """

        url = base_url + self.json_url
        headers, body = self.request_headers_and_body(url)

        response, problems = basic_body_verification(body, url)

        if len(problems) > 0:
            return problems

        problems += verify_helloworld_object(response, url)
        problems += verify_headers(self.request_headers_and_body,
                                   headers,
                                   url,
                                   should_be="json")

        if len(problems) > 0:
            return problems
        else:
            return [("pass", "", url)]
コード例 #3
0
    def verify(self, base_url):
        '''
        Parses the given HTML string and asks the
        FortuneHTMLParser whether the parsed string is a
        valid fortune response
        '''

        url = base_url + self.fortune_url
        headers, body = self.request_headers_and_body(url)

        _, problems = basic_body_verification(body, url, is_json_check=False)

        if len(problems) > 0:
            return problems

        parser = FortuneHTMLParser()
        parser.feed(body)
        (valid, diff) = parser.isValidFortune(self.name, body)

        if valid:
            problems += verify_headers(headers, url, should_be='html')

            if len(problems) == 0:
                return [('pass', '', url)]
            else:
                return problems
        else:
            failures = []
            failures.append(('fail', 'Invalid according to FortuneHTMLParser',
                             url))
            failures += self._parseDiffForFailure(diff, failures, url)
            return failures
コード例 #4
0
    def verify(self, base_url):
        url = base_url + self.plaintext_url
        headers, body = self.request_headers_and_body(url)

        _, problems = basic_body_verification(body, url, is_json_check=False)

        if len(problems) > 0:
            return problems

        # Case insensitive
        body = body.lower()
        expected = "hello, world!"
        extra_bytes = len(body) - len(expected)

        if expected not in body:
            return [('fail', "Could not find 'Hello, World!' in response.",
                     url)]

        if extra_bytes > 0:
            problems.append(
                ('warn',
                 ("Server is returning %s more bytes than are required. "
                  "This may negatively affect benchmark performance." %
                  extra_bytes), url))

        problems += verify_headers(self.request_headers_and_body, headers, url, should_be='plaintext')

        if len(problems) == 0:
            return [('pass', '', url)]
        else:
            return problems
コード例 #5
0
    def verify(self, base_url):
        url = base_url + self.plaintext_url
        headers, body = self.request_headers_and_body(url)

        _, problems = basic_body_verification(body, url, is_json_check=False)

        if len(problems) > 0:
            return problems

        # Case insensitive
        body = body.lower()
        expected = "hello, world!"
        extra_bytes = len(body) - len(expected)

        if expected not in body:
            return [('fail', "Could not find 'Hello, World!' in response.",
                     url)]

        if extra_bytes > 0:
            problems.append(
                ('warn',
                 ("Server is returning %s more bytes than are required. "
                  "This may negatively affect benchmark performance." %
                  extra_bytes), url))

        problems += verify_headers(self.request_headers_and_body,
                                   headers,
                                   url,
                                   should_be='plaintext')

        if len(problems) == 0:
            return [('pass', '', url)]
        else:
            return problems
コード例 #6
0
    def verify(self, base_url):
        '''
        Ensures body is valid JSON with a key 'id' and a key 
        'randomNumber', both of which must map to integers
        '''

        # Initialization for query counting
        repetitions = 1
        concurrency = max(self.config.concurrency_levels)
        expected_queries = repetitions * concurrency

        url = base_url + self.db_url
        headers, body = self.request_headers_and_body(url)

        response, problems = basic_body_verification(body, url)

        if len(problems) > 0:
            return problems

        # We are allowing the single-object array
        # e.g. [{'id':5, 'randomNumber':10}] for now,
        # but will likely make this fail at some point
        if type(response) == list:
            response = response[0]
            problems.append((
                'warn',
                'Response is a JSON array. Expected JSON object (e.g. [] vs {})',
                url))

            # Make sure there was a JSON object inside the array
            if type(response) != dict:
                problems.append((
                    'fail',
                    'Response is not a JSON object or an array of JSON objects',
                    url))
                return problems

        # Verify response content
        problems += verify_randomnumber_object(response, url)
        problems += verify_headers(self.request_headers_and_body, headers, url, should_be='json')

        if len(problems) == 0:
            problems += verify_queries_count(self, "World", url, concurrency, repetitions, expected_queries, expected_queries)
        if len(problems) == 0:
            return [('pass', '', url)]
        else:
            return problems
コード例 #7
0
    def verify(self, base_url):
        """
        Ensures body is valid JSON with a key 'id' and a key 
        'randomNumber', both of which must map to integers
        """

        url = base_url + self.db_url
        headers, body = self.request_headers_and_body(url)

        response, problems = basic_body_verification(body, url)

        if len(problems) > 0:
            return problems

        # We are allowing the single-object array
        # e.g. [{'id':5, 'randomNumber':10}] for now,
        # but will likely make this fail at some point
        if type(response) == list:
            response = response[0]
            problems.append((
                "warn",
                "Response is a JSON array. Expected JSON object (e.g. [] vs {})",
                url,
            ))

            # Make sure there was a JSON object inside the array
            if type(response) != dict:
                problems.append((
                    "fail",
                    "Response is not a JSON object or an array of JSON objects",
                    url,
                ))
                return problems

        # Verify response content
        problems += verify_randomnumber_object(response, url)
        problems += verify_headers(self.request_headers_and_body,
                                   headers,
                                   url,
                                   should_be="json")

        if len(problems) == 0:
            return [("pass", "", url)]
        else:
            return problems
コード例 #8
0
    def verify(self, base_url):
        '''
        Parses the given HTML string and asks the
        FortuneHTMLParser whether the parsed string is a
        valid fortune response
        '''
        # Initialization for query counting
        repetitions = 1
        concurrency = max(self.config.concurrency_levels)
        expected_queries = repetitions * concurrency
        expected_rows = 12 * expected_queries

        url = base_url + self.fortune_url
        headers, body = self.request_headers_and_body(url)

        _, problems = basic_body_verification(body, url, is_json_check=False)

        if len(problems) > 0:
            return problems

        parser = FortuneHTMLParser()
        parser.feed(body)
        (valid, diff) = parser.isValidFortune(self.name, body)

        if valid:
            problems += verify_headers(self.request_headers_and_body,
                                       headers,
                                       url,
                                       should_be='html')
            if len(problems) == 0:
                problems += verify_queries_count(self, "fortune", url,
                                                 concurrency, repetitions,
                                                 expected_queries,
                                                 expected_rows)
            if len(problems) == 0:
                return [('pass', '', url)]
            else:
                return problems
        else:
            failures = []
            failures.append(
                ('fail', 'Invalid according to FortuneHTMLParser', url))
            failures += self._parseDiffForFailure(diff, failures, url)
            return failures
コード例 #9
0
    def verify(self, base_url):
        '''
        Ensures body is valid JSON with a key 'id' and a key 
        'randomNumber', both of which must map to integers
        '''

        url = base_url + self.db_url
        headers, body = self.request_headers_and_body(url)

        response, problems = basic_body_verification(body, url)

        if len(problems) > 0:
            return problems

        # We are allowing the single-object array
        # e.g. [{'id':5, 'randomNumber':10}] for now,
        # but will likely make this fail at some point
        if type(response) == list:
            response = response[0]
            problems.append((
                'warn',
                'Response is a JSON array. Expected JSON object (e.g. [] vs {})',
                url))

            # Make sure there was a JSON object inside the array
            if type(response) != dict:
                problems.append((
                    'fail',
                    'Response is not a JSON object or an array of JSON objects',
                    url))
                return problems

        # Verify response content
        problems += verify_randomnumber_object(response, url)
        problems += verify_headers(self.request_headers_and_body, headers, url, should_be='json')

        if len(problems) == 0:
            return [('pass', '', url)]
        else:
            return problems
コード例 #10
0
    def verify(self, base_url):
        '''
        Validates the response is a JSON object of 
        { 'message' : 'hello, world!' }. Case insensitive and 
        quoting style is ignored
        '''

        url = base_url + self.json_url
        headers, body = self.request_headers_and_body(url)

        response, problems = basic_body_verification(body, url)

        if len(problems) > 0:
            return problems

        problems += verify_helloworld_object(response, url)
        problems += verify_headers(self.request_headers_and_body, headers, url, should_be='json')

        if len(problems) > 0:
            return problems
        else:
            return [('pass', '', url)]