def test_discovery_request(self): discovery_request1 = tm10.DiscoveryRequest( message_id=tm10.generate_message_id(), # Required # Extended headers are optional for every message type, but only demonstrated here extended_headers={'ext_header1': 'value1', 'ext_header2': 'value2'}) # Optional. round_trip_message(discovery_request1)
def test_01(self): """ Send a discovery request, look to get a discovery response back """ dr = tm10.DiscoveryRequest(generate_message_id()) msg = make_request(DISCOVERY_11_PATH, dr.to_xml(), get_headers(VID_TAXII_SERVICES_10, False), MSG_DISCOVERY_RESPONSE)
def _discovery_request(self, uri): request = tm10.DiscoveryRequest(message_id=self._generate_id()) response = self._execute_request(request, uri=uri) return response
def create_request_message(self, args): return tm10.DiscoveryRequest(message_id=generate_message_id())
def test_05(self): """ For each set of TAXII Headers, test the following: - One header missing - A bad value for each header - Other permutations in the future? """ #TODO: The responses could probably be checked better #TODO: This whole thing can probably be done better, # but it's probably sufficient for now #Tuples of services version / is_secure HTTP = False HTTPS = True tuples = ((VID_TAXII_SERVICES_11, HTTPS), (VID_TAXII_SERVICES_11, HTTP), (VID_TAXII_SERVICES_10, HTTPS), (VID_TAXII_SERVICES_10, HTTP)) # Create a list of headers for mangling header values tmp_headers = get_headers(tuples[0][0], tuples[0][1]) header_list = tmp_headers.keys() # Iterate over every TAXII Service version / is_secure value, # over every header, and try that header with a bad value # and not present for tuple in tuples: if tuple[0] == VID_TAXII_SERVICES_11: disc_req_xml = tm11.DiscoveryRequest( generate_message_id()).to_xml() else: disc_req_xml = tm10.DiscoveryRequest( generate_message_id()).to_xml() for header in header_list: expected_code = 200 if header != 'HTTP_ACCEPT' else 406 r_msg = MSG_STATUS_MESSAGE request_headers = get_headers(tuple[0], tuple[1]) # Try the bad header value request_headers[header] = 'THIS_IS_A_BAD_VALUE' #print header, request_headers[header] msg = make_request(post_data=disc_req_xml, path=DISCOVERY_11_PATH, response_msg_type=r_msg, header_dict=request_headers, expected_code=expected_code) #print msg.to_xml(pretty_print=True) # Now try without the header if header in ( 'HTTP_ACCEPT', 'HTTP_X_TAXII_ACCEPT' ): # These headers, if missing, should result an a valid response being sent expected_code = 200 r_msg = MSG_DISCOVERY_RESPONSE del request_headers[header] msg = make_request(post_data=disc_req_xml, path=DISCOVERY_11_PATH, response_msg_type=r_msg, header_dict=request_headers, expected_code=expected_code) #print msg.to_xml(pretty_print=True) # Good, now on to the next one! pass
def test_discovery_exchange(self): """Send a discovery request, look to get a discovery response back.""" req = tm10.DiscoveryRequest(tm10.generate_message_id()) response = self.post(DISCOVERY_PATH, req.to_xml()) self.assertDiscoveryResponse(response)