Пример #1
0
	def compareUrls(self, hostHeader, url1, url2):

		for retry in xrange(URL_COMPARE_RETRIES):
			if retry != 0:
				time.sleep(URL_COMPARE_RETRIES_SLEEP_INTERVAL)

			if LOG_LEVEL['UrlCompareLog']:
				self.writeOutput('Compare %s with %s  (retry %d)' % (url1, url2, retry))

			code1, headers1, body1 = self.getURL(hostHeader, url1)
			code2, headers2, body2 = self.getURL(hostHeader, url2)
			if code1 != code2:
				self.writeOutput('Error: got different status codes %s vs %s, url1=%s, url2=%s' % (code1, code2, url1, url2))
				continue

			headerCompare = compare_utils.compareHeaders(headers1, headers2)
			if headerCompare != None:
				self.writeOutput(headerCompare)
				continue

			if str(code1) != '200':
				self.writeOutput('Notice: got status code %s, url1=%s, url2=%s' % (code1, url1, url2))

			if body1 != body2:
				if retry >= URL_COMPARE_RETRIES-1:
					severity = "Error"
				else:
					severity = "Notice"
				self.writeOutput('%s: comparison failed, url1=%s, url2=%s\n%s\n%s' % (severity, url1, url2, convertBody(body1), convertBody(body2)))
				continue

			return code1, headers1, body1

		return False
Пример #2
0
    def compareUrls(self, hostHeader, url1, url2):
        code1, headers1, body1 = self.getURL(hostHeader, url1)
        code2, headers2, body2 = self.getURL(hostHeader, url2)
        if code1 != code2:
            self.writeOutput(
                'Error: got different status codes %s vs %s, url1=%s, url2=%s'
                % (code1, code2, url1, url2))
            return False

        headerCompare = compare_utils.compareHeaders(headers1, headers2)
        if headerCompare != None:
            self.writeOutput(headerCompare)
            return False

        if str(code1) != '200':
            self.writeOutput('Notice: got status code %s, url1=%s, url2=%s' %
                             (code1, url1, url2))

        if body1 != body2:
            self.writeOutput('Error: comparison failed, url1=%s, url2=%s' %
                             (url1, url2))
            self.writeOutput(body1)
            self.writeOutput(body2)
            return False

        return code1, headers1, body1
Пример #3
0
	def compareUrls(self, hostHeader, url1, url2):

		for retry in xrange(URL_COMPARE_RETRIES):
			if retry != 0:
				time.sleep(URL_COMPARE_RETRIES_SLEEP_INTERVAL)

			if LOG_LEVEL['UrlCompareLog']:
				self.writeOutput('Compare %s with %s  (retry %d)' % (url1, url2, retry))

			code1, headers1, body1 = self.getURL(hostHeader, url1)
			code2, headers2, body2 = self.getURL(hostHeader, url2)
			if code1 != code2:
				self.writeOutput('Error: got different status codes %s vs %s, url1=%s, url2=%s' % (code1, code2, url1, url2))
				continue

			headerCompare = compare_utils.compareHeaders(headers1, headers2)
			if headerCompare != None:
				self.writeOutput(headerCompare)
				continue

			if str(code1) != '200':
				self.writeOutput('Notice: got status code %s, url1=%s, url2=%s' % (code1, url1, url2))

			if body1 != body2:
				if retry >= URL_COMPARE_RETRIES-1:
					severity = "Error"
				else:
					severity = "Notice"
				self.writeOutput('%s: comparison failed, url1=%s, url2=%s\n%s\n%s' % (severity, url1, url2, convertBody(body1), convertBody(body2)))
				continue

			return code1, headers1, body1

		return False
Пример #4
0
	def runTest(self, uri):
		hostHeader, uri = uri.split(' ')
	
		urlBase1 = random.choice(URL1_BASE)
		urlBase2 = random.choice(URL2_BASE)
		url1 = urlBase1 + uri
		url2 = urlBase2 + uri
		
		self.writeOutput('Info: testing %s %s' % (url1, url2))

		# avoid billing real partners
		useRealPartner = False
		for curPrefix in USE_REAL_PARTNER_PREFIXES:
			if uri.startswith(curPrefix):
				useRealPartner = True
		if not useRealPartner:
			url1 = re.sub('/p/\d+/sp/\d+/', '/p/%s/sp/%s00/' % (TEST_PARTNER_ID, TEST_PARTNER_ID), url1)
			url2 = re.sub('/p/\d+/sp/\d+/', '/p/%s/sp/%s00/' % (TEST_PARTNER_ID, TEST_PARTNER_ID), url2)

		code1, headers1, body1 = self.getURL(hostHeader, url1)
		code2, headers2, body2 = self.getURL(hostHeader, url2)
		if code1 != code2:
			self.writeOutput('Error: got different status codes %s vs %s' % (code1, code2))
			return False
		
		headerCompare = compare_utils.compareHeaders(headers1, headers2)
		if headerCompare != None:
			self.writeOutput(headerCompare)
			return False
		
		if str(code1) != '200':
			self.writeOutput('Notice: got status code %s' % (code1))
			body1 = re.sub('nginx/\d+\.\d+\.\d+', 'nginx/0.0.0', body1)
			body2 = re.sub('nginx/\d+\.\d+\.\d+', 'nginx/0.0.0', body2)
		
		if (headers1.has_key('content-type') and 
			headers1['content-type'][0] in set(['application/vnd.apple.mpegurl', 'application/dash+xml'])):
			body1 = body1.replace(urlBase1, urlBase2)
			body1 = body1.replace('-a1-v1', '-v1-a1')
			body2 = body2.replace('-a1-v1', '-v1-a1')
			# must strip CF tokens since they sign the domain
			body1 = re.sub('&Signature=[^&]+', '&Signature=', re.sub('\?Policy=[^&]+', '?Policy=', body1))
			body2 = re.sub('&Signature=[^&]+', '&Signature=', re.sub('\?Policy=[^&]+', '?Policy=', body2))
		
		if body1.startswith('<?xml'):
			body1 = re.sub('<executionTime>[0-9\.]+<\/executionTime>', '', body1)
			body2 = re.sub('<executionTime>[0-9\.]+<\/executionTime>', '', body2)
			
		if body1 != body2:
			self.writeOutput('Error: comparison failed - url1=%s, url2=%s' % (url1, url2))
			self.writeOutput(body1)
			self.writeOutput(body2)
			return False
			
		return True
Пример #5
0
	def compareUrls(self, hostHeader, url1, url2):
		code1, headers1, body1 = self.getURL(hostHeader, url1)
		code2, headers2, body2 = self.getURL(hostHeader, url2)
		if code1 != code2:
			self.writeOutput('Error: got different status codes %s vs %s, url1=%s, url2=%s' % (code1, code2, url1, url2))
			return False
		
		headerCompare = compare_utils.compareHeaders(headers1, headers2)
		if headerCompare != None:
			self.writeOutput(headerCompare)
			return False
		
		if str(code1) != '200':
			self.writeOutput('Notice: got status code %s, url1=%s, url2=%s' % (code1, url1, url2))
					
		if body1 != body2:
			self.writeOutput('Error: comparison failed, url1=%s, url2=%s' % (url1, url2))
			self.writeOutput(body1)
			self.writeOutput(body2)
			return False
			
		return code1, headers1, body1
Пример #6
0
    def runTest(self, line):
        splittedLine = line.split(' ')
        if len(splittedLine) == 2:
            hostHeader, uri = splittedLine
            range = None
        elif len(splittedLine) == 3:
            range, hostHeader, uri = splittedLine
            range = range.split('/')[0]
        else:
            return True

        urlBase1 = random.choice(URL1_BASE)
        urlBase2 = random.choice(URL2_BASE)
        url1 = urlBase1 + uri
        url2 = urlBase2 + uri

        self.writeOutput('Info: testing %s %s' % (url1, url2))

        # avoid billing real partners
        useRealPartner = False
        for curPrefix in USE_REAL_PARTNER_PREFIXES:
            if uri.startswith(curPrefix):
                useRealPartner = True
        if not useRealPartner:
            url1 = re.sub(
                '/p/\d+/sp/\d+/',
                '/p/%s/sp/%s00/' % (TEST_PARTNER_ID, TEST_PARTNER_ID), url1)
            url2 = re.sub(
                '/p/\d+/sp/\d+/',
                '/p/%s/sp/%s00/' % (TEST_PARTNER_ID, TEST_PARTNER_ID), url2)

        code1, headers1, body1 = self.getURL(hostHeader, url1, range)
        code2, headers2, body2 = self.getURL(hostHeader, url2, range)
        if code1 != code2:
            self.writeOutput('Error: got different status codes %s vs %s' %
                             (code1, code2))
            return False

        headerCompare = compare_utils.compareHeaders(headers1, headers2)
        if headerCompare != None:
            self.writeOutput(headerCompare)
            return False

        if not str(code1) in ['200', '206']:
            self.writeOutput('Notice: got status code %s' % (code1))
            body1 = re.sub('nginx/\d+\.\d+\.\d+', 'nginx/0.0.0', body1)
            body2 = re.sub('nginx/\d+\.\d+\.\d+', 'nginx/0.0.0', body2)

        if (headers1.has_key('content-type')
                and headers1['content-type'][0] in set([
                    'application/vnd.apple.mpegurl', 'application/dash+xml'
                ])):
            body1 = body1.replace(urlBase1, urlBase2)
            body1 = body1.replace('-a1-v1', '-v1-a1')
            body2 = body2.replace('-a1-v1', '-v1-a1')
            # must strip CF tokens since they sign the domain
            body1 = re.sub('&Signature=[^&]+', '&Signature=',
                           re.sub('\?Policy=[^&]+', '?Policy=', body1))
            body2 = re.sub('&Signature=[^&]+', '&Signature=',
                           re.sub('\?Policy=[^&]+', '?Policy=', body2))

        if body1.startswith('<?xml'):
            body1 = re.sub('<executionTime>[0-9\.]+<\/executionTime>', '',
                           body1)
            body2 = re.sub('<executionTime>[0-9\.]+<\/executionTime>', '',
                           body2)

        if body1.startswith('<html>'):
            body1 = body1.replace(' bgcolor="white"', '')
            body2 = body2.replace(' bgcolor="white"', '')

        if body1 != body2:
            self.writeOutput('Error: comparison failed - url1=%s, url2=%s' %
                             (url1, url2))
            self.writeOutput(body1)
            self.writeOutput(body2)
            return False

        return True