def compare_dns_experiments(self, experiment_dns_answers): if self.control['dns']['failure'] is not None and \ self.control['dns']['failure'] == self.report['dns_experiment_failure']: self.report['dns_consistency'] = 'consistent' return True control_addrs = set(self.control['dns']['addrs']) experiment_addrs = set(experiment_dns_answers) if control_addrs == experiment_addrs: return True for experiment_addr in experiment_addrs: if is_public_ipv4_address(experiment_addr) is False: return False if len(control_addrs.intersection(experiment_addrs)) > 0: return True experiment_asns = set(map(lambda x: geoip.ip_to_location(x)['asn'], experiment_addrs)) control_asns = set(map(lambda x: geoip.ip_to_location(x)['asn'], control_addrs)) # Remove the instance of AS0 when we fail to find the ASN control_asns.discard('AS0') experiment_asns.discard('AS0') if len(control_asns.intersection(experiment_asns)) > 0: return True return False
def test_web_connectivity(self): log.msg("") log.msg("Starting test for {}".format(self.input)) experiment_dns = self.experiment_dns_query() @experiment_dns.addErrback def dns_experiment_err(failure): self.report['dns_experiment_failure'] = failureToString(failure) return [] experiment_dns_answers = yield experiment_dns port = 80 parsed_url = urlparse(self.input) if parsed_url.port: port = parsed_url.port elif parsed_url.scheme == 'https': port = 443 sockets = [] for ip_address in experiment_dns_answers: if is_public_ipv4_address(ip_address) is True: sockets.append("{}:{}".format(ip_address, port)) # STEALTH in here we should make changes to make the test more stealth dl = [] for socket in sockets: dl.append(self.experiment_tcp_connect(socket)) results = yield defer.DeferredList(dl) experiment_http = self.experiment_http_get_request() @experiment_http.addErrback def http_experiment_err(failure): failure_string = failureToString(failure) log.msg("Failed to perform HTTP request %s" % failure_string) self.report['http_experiment_failure'] = failure_string experiment_http_response = yield experiment_http control_request = self.control_request(sockets) @control_request.addErrback def control_err(failure): failure_string = failureToString(failure) log.err("Failed to perform control lookup: %s" % failure_string) self.report['control_failure'] = failure_string yield control_request if self.report['control_failure'] is None: self.report['blocking'] = self.determine_blocking(experiment_http_response, experiment_dns_answers) log.msg("") log.msg("Result for %s" % self.input) log.msg("-----------" + "-"*len(self.input)) if self.report['blocking'] is None: log.msg("* Could not determine status of blocking due to " "failing control request") elif self.report['blocking'] is False: log.msg("* No blocking detected") else: log.msg("* BLOCKING DETECTED due to %s" % (self.report['blocking'])) if (self.report['http_experiment_failure'] == None and self.report['dns_experiment_failure'] == None and self.report['blocking'] in (False, None)): self.report['accessible'] = True log.msg("* Is accessible") else: log.msg("* Is NOT accessible") self.report['accessible'] = False log.msg("")
def test_is_public_ipv4(self): self.assertTrue(is_public_ipv4_address('8.8.8.8')) self.assertFalse(is_public_ipv4_address('example.com')) self.assertFalse(is_public_ipv4_address('127.0.0.1')) self.assertFalse(is_public_ipv4_address('192.168.1.1'))