Ejemplo n.º 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.out)

        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
Ejemplo n.º 2
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)

        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(headers, url, should_be='json')

        if len(problems) == 0:
            return [('pass', '', url)]
        else:
            return problems
Ejemplo n.º 3
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, is_json_check=False)

        if len(problems) > 0:
            return problems

        # Case insensitive
        orig = body
        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(headers, url, should_be='plaintext')

        if len(problems) == 0:
            return [('pass', '', url)]
        else:
            return problems
    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(headers, url, should_be='json')

        if len(problems) > 0:
            return problems
        else:
            return [('pass', '', url)]
Ejemplo n.º 5
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(headers, url, should_be='json')

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