def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_template.xml") xroad_message_ids = [] client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_before_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) ### Repeat a regular X-Road request with a different message ID. print("\n---- Sending regular X-Road requests to the client's security server ----\n") for _ in range(30): message_id = common.generate_message_id() xroad_message_ids.append(message_id) print("Sending a request with message ID %s" % (message_id, )) request_contents = common.format_xroad_request_template( xroad_request_template_filename, message_id) response = common.post_xml_request( client_security_server_address, request_contents) common.check_soap_fault(minidom.parseString(response.text)) time.sleep(1) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) ### Make operational data requests until all the records have been received or ### no more are offered. print("\n---- Sending operational data requests to the client ----\n") _query_operational_data( query_data_client_template_filename, client_security_server_address, client_timestamp_before_requests, client_timestamp_after_requests, copy.deepcopy(xroad_message_ids)) print("\n---- Sending operational data requests to the producer ----\n") _query_operational_data( query_data_producer_template_filename, producer_security_server_address, producer_timestamp_before_requests, producer_timestamp_after_requests, copy.deepcopy(xroad_message_ids), is_client=False)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_ss_owner_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_ss_owner_template.xml") ### Metadata and operational data requests and the relevant checks client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) print( "\n---- Sending a verificationconf request to the client's security server ----\n" ) response = common.make_get_request(client_security_server_address + "/verificationconf") common.check_status(response) print("Received the following status code and response headers: \n") common.print_response_status_and_headers(response) print( "\n---- Sending a listClients request to the client's security server ----\n" ) response = common.make_get_request(client_security_server_address + "/listClients") common.check_status(response) print("Received the following response: \n") common.print_response_status_and_headers(response) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) # Now make an operational data request to the client's security server and check the # response payload. # We expect that neither of the requests sent above have been stored in the # operational monitoring database. print( "\n---- Sending an operational data request to the client's security server ----\n" ) message_id = common.generate_message_id() print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print( "Generated the following query data request for the client's security server: \n" ) print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) common.check_record_count(record_count, 0) else: common.parse_and_check_soap_response(raw_response) # Wait a second to ensure that the previous operational data request is not included # in the operational data that we request below. time.sleep(1) print( "\n---- Sending a wsdl request to the client's security server ----\n") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_before_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) response = common.make_get_request( client_security_server_address + "/wsdl?xRoadInstance=" \ "XTEE-CI-XM&memberClass=GOV&memberCode=00000000&subsystemCode=" \ "Center&serviceCode=xroadGetRandom&version=v1") common.check_status(response) print("Received the following response: \n") common.print_response_status_and_headers(response) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) # Now make operational data requests to both security servers and check the # response payloads. We expect that the wsdl request has been stored in the # operational monitoring database. print( "\n---- Sending an operational data request to the client's security server ----\n" ) message_id = common.generate_message_id() print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print( "Generated the following query data request for the client's security server: \n" ) print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. common.assert_present_in_json( json_payload, _expected_keys_and_values_of_wsdl_query_rec( client_security_server_address, "Client")) # Check if the timestamps in the response are in the expected range. common.assert_expected_timestamp_values( json_payload, client_timestamp_before_requests, client_timestamp_after_requests) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response) print("\n---- Sending an operational data request to the producer's " \ "security server ----\n") message_id = common.generate_message_id() print("\nGenerated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_producer_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests) print("Generated the following query data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request(producer_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. common.assert_present_in_json( json_payload, _expected_keys_and_values_of_wsdl_query_rec( producer_security_server_address, "Producer")) # Check timestamp values common.assert_expected_timestamp_values( json_payload, producer_timestamp_before_requests, producer_timestamp_after_requests) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") listmethods_query_template_filename = os.path.join( request_template_dir, "listmethods_client_query_template.xml") soap_fault_query_template_filename = os.path.join( request_template_dir, "soap_fault_query_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_health_data_client_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_health_data_producer_template.xml") query_data_invalid_client_template_filename = os.path.join( request_template_dir, "query_health_data_invalid_client_template.xml") query_data_unknown_client_template_filename = os.path.join( request_template_dir, "query_health_data_unknown_client_template.xml") query_data_without_client_template_filename = os.path.join( request_template_dir, "query_health_data_without_client.xml") producer_health_data_request = None client_health_data_request = None producer_initial_timestamp = common.get_remote_timestamp( producer_security_server_address, ssh_user) producer_opmonitor_restart_timestamp = common.get_opmonitor_restart_timestamp( producer_security_server_address, ssh_user) client_opmonitor_restart_timestamp = common.get_opmonitor_restart_timestamp( client_security_server_address, ssh_user) ### First, send a regular X-Road request. xroad_message_id = common.generate_message_id() print("\nGenerated message ID %s for X-Road request" % (xroad_message_id, )) print( "\n---- Sending an X-Road request to the client's security server ----\n" ) request_contents = common.format_xroad_request_template( xroad_request_template_filename, xroad_message_id) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) print("Received the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) common.wait_for_operational_data() ### Make a health check request to the producer. print("\n---- Sending a health data request to the producer's " \ "security server ----\n") message_id = common.generate_message_id() print("Generated message ID %s for health data request" % (message_id, )) request_contents = common.format_query_health_data_request_template( query_data_producer_template_filename, message_id) producer_health_data_request = request_contents print("Generated the following health data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request(producer_security_server_address, request_contents) xml = common.parse_and_clean_xml(response.text) print("Received the following health data response:\n") print(xml.toprettyxml()) common.check_soap_fault(xml) _assert_monitoring_daemon_start_timestamp_in_range( response, producer_opmonitor_restart_timestamp) _assert_stats_period(response, STATISTICS_PERIOD_SECONDS) print("Looking for the xroadGetRandom service in the response") event_data = _find_health_data_events_for_service(response, GET_RANDOM_SERVICE_XML) if event_data is None: raise Exception( "Health data about xroadGetRandom was not found in the response") _assert_last_successful_event_timestamp_in_range( event_data, producer_initial_timestamp) _assert_successful_events_count(event_data, 1) _assert_unsuccessful_events_count(event_data, 0) _assert_xml_tags_present(event_data, SAMPLE_PRODUCER_GET_RANDOM_STATS.keys()) _assert_xml_tags_match_values(event_data, PREDICTABLE_FIELDS, SAMPLE_PRODUCER_GET_RANDOM_STATS) ### Send a listMethods request to the client. listmethods_message_id = common.generate_message_id() print( "\nGenerated message ID %s for the listMethods request to the client" % (listmethods_message_id, )) print( "\n---- Sending a listMethods request to the client's security server ----\n" ) request_contents = common.format_xroad_request_template( listmethods_query_template_filename, listmethods_message_id) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part = common.get_multipart_soap(mime_parts[0]) common.print_multipart_soap(soap_part) else: common.parse_and_check_soap_response(raw_response) common.wait_for_operational_data() ### Send a health data request to the client. client_pre_health_data_timestamp = common.get_remote_timestamp( client_security_server_address, ssh_user) message_id = common.generate_message_id() print("Generated message ID %s for health data request" % (message_id, )) print("\n---- Sending a health data request to the client's " \ "security server ----\n") request_contents = common.format_query_health_data_request_template( query_data_client_template_filename, message_id) client_health_data_request = request_contents print("Generated the following health data request for the client's " \ "security server: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) xml = common.parse_and_clean_xml(response.text) print("Received the following health data response:\n") print(xml.toprettyxml()) common.check_soap_fault(xml) _assert_monitoring_daemon_start_timestamp_in_range( response, client_opmonitor_restart_timestamp) _assert_stats_period(response, STATISTICS_PERIOD_SECONDS) print("Looking for the listMethods service in the response") event_data = _find_health_data_events_for_service(response, LISTMETHODS_SERVICE_XML) if event_data is None: raise Exception( "Health data about listMethods was not found in the response") _assert_last_successful_event_timestamp_in_range( event_data, client_pre_health_data_timestamp) _assert_successful_events_count(event_data, 1) _assert_unsuccessful_events_count(event_data, 0) _assert_xml_tags_present(event_data, SAMPLE_CLIENT_LISTMETHODS_STATS.keys()) _assert_xml_tags_match_values(event_data, PREDICTABLE_FIELDS, SAMPLE_CLIENT_LISTMETHODS_STATS) ### Send a health data request to the client, using an invalid client ID in the ### query criteria. message_id = common.generate_message_id() print("Generated message ID %s for health data request" % (message_id, )) print("\n---- Sending a health data request to the client's " \ "security server, using an invalid client in the filter criteria ----\n") request_contents = common.format_query_health_data_request_template( query_data_invalid_client_template_filename, message_id) print("Generated the following health data request for the client's " \ "security server: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) xml = common.parse_and_clean_xml(response.text) print("Received the following health data response:\n") print(xml.toprettyxml()) # Using an invalid client ID must result in a SOAP fault. common.assert_soap_fault(xml) ### Send an unfiltered health data request to the client, using the producer ### as the service provider. message_id = common.generate_message_id() print("Generated message ID %s for health data request" % (message_id, )) print("\n---- Sending an unfiltered health data request to the client's " \ "security server, using the producer as the service provider ----\n") request_contents = common.format_query_health_data_request_template( query_data_without_client_template_filename, message_id) print("Generated the following health data request for the client's " \ "security server: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) xml = common.parse_and_clean_xml(response.text) print("Received the following health data response:\n") print(xml.toprettyxml()) # This response must contain several serviceEvents elements (for all the # requests that were made to the producer above, including the initial health # data request). _assert_service_events_min_count(response, 2) event_data = _find_health_data_events_for_service(response, GET_RANDOM_SERVICE_XML) if event_data is None: raise Exception( "Health data about xroadGetRandom was not found in the response") event_data = _find_health_data_events_for_service( response, GET_HEALTH_DATA_SERVICE_XML) if event_data is None: raise Exception( "Health data about getSecurityServerHealthData was not found in the response" ) ### Send a request using an unknown client ID in the filter. Expect an empty response ### is returned. message_id = common.generate_message_id() print("Generated message ID %s for health data request" % (message_id, )) print("\n---- Sending a health data request with an unknown client ID to the client's " \ "security server ----\n") request_contents = common.format_query_health_data_request_template( query_data_unknown_client_template_filename, message_id) print("Generated the following health data request for the client's " \ "security server: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) xml = common.parse_and_clean_xml(response.text) print("Received the following health data response:\n") print(xml.toprettyxml()) common.check_soap_fault(xml) _assert_no_events(response) ### Sleep and expect that the health data will be reset. print("Waiting for the health metrics to be reset\n") time.sleep(STATISTICS_PERIOD_SECONDS) ### Repeat the health data requests and check if the health data has been reset. print("Repeating the health data request to the producer\n") response = common.post_xml_request(producer_security_server_address, producer_health_data_request) xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) _assert_monitoring_daemon_start_timestamp_in_range( response, producer_opmonitor_restart_timestamp) _assert_stats_period(response, STATISTICS_PERIOD_SECONDS) event_data = _find_health_data_events_for_service(response, GET_RANDOM_SERVICE_XML) if event_data is None: raise Exception( "Health data about xroadGetRandom was not found in the response") _assert_successful_events_count(event_data, 0) _assert_unsuccessful_events_count(event_data, 0) _assert_xml_tags_missing(event_data, STATISTICS_FIELDS) print("Repeating the health data request to the client\n") response = common.post_xml_request(client_security_server_address, client_health_data_request) xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) _assert_monitoring_daemon_start_timestamp_in_range( response, client_opmonitor_restart_timestamp) _assert_stats_period(response, STATISTICS_PERIOD_SECONDS) event_data = _find_health_data_events_for_service(response, LISTMETHODS_SERVICE_XML) if event_data is None: raise Exception( "Health data about listMethods was not found in the response") _assert_successful_events_count(event_data, 0) _assert_unsuccessful_events_count(event_data, 0) _assert_xml_tags_missing(event_data, STATISTICS_FIELDS) ### Now make an unusuccessful request and check the relevant health data. producer_pre_unsuccessful_timestamp = common.get_remote_timestamp( producer_security_server_address, ssh_user) message_id = common.generate_message_id() print( "\nGenerated message ID %s for an X-Road request that will cause a SOAP fault" % (message_id, )) print("\n---- Sending an X-Road request that will cause a SOAP fault at the " \ "service provider, to the client's security server ----\n") request_contents = common.format_xroad_request_template( soap_fault_query_template_filename, message_id) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.assert_soap_fault(xml) common.wait_for_operational_data() # Send a health check request to the producer. print("\n---- Sending a health data request to the producer's " \ "security server ----\n") message_id = common.generate_message_id() print("Generated message ID %s for health data request" % (message_id, )) request_contents = common.format_query_health_data_request_template( query_data_producer_template_filename, message_id) print("Generated the following health data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request(producer_security_server_address, request_contents) xml = common.parse_and_clean_xml(response.text) print("Received the following health data response:\n") print(xml.toprettyxml()) common.check_soap_fault(xml) # The service is xRoadGetRandom but the result was a fault. print("Looking for the xroadGetRandom service in the response") event_data = _find_health_data_events_for_service(response, GET_RANDOM_SERVICE_XML) if event_data is None: raise Exception( "Health data about xroadGetRandom was not found in the response") _assert_successful_events_count(event_data, 0) _assert_unsuccessful_events_count(event_data, 1) _assert_last_unsuccessful_event_timestamp_in_range( event_data, producer_pre_unsuccessful_timestamp)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): unknown_member_query_template_filename = os.path.join( request_template_dir, "unknown_member_query_template.xml") unknown_service_query_template_filename = os.path.join( request_template_dir, "unknown_service_query_template.xml") soap_fault_query_template_filename = os.path.join( request_template_dir, "soap_fault_query_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_ss_owner_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_ss_owner_template.xml") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_before_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) message_id_serverproxy = common.generate_message_id() print("\nGenerated message ID %s for X-Road request to unknown service" % (message_id_serverproxy, )) ### Regular and operational data requests and the relevant checks print("\n---- Sending an X-Road request to an unknown service to the client's " \ "security server ----\n") request_contents = common.format_xroad_request_template( unknown_service_query_template_filename, message_id_serverproxy) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.assert_soap_fault(xml) message_id_clientproxy = common.generate_message_id() print("\nGenerated message ID %s for X-Road request from unknown member" % (message_id_clientproxy, )) print("\n---- Sending an X-Road request from an unknown member to the " \ "client's security server ----\n") request_contents = common.format_xroad_request_template( unknown_member_query_template_filename, message_id_clientproxy) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.assert_soap_fault(xml) message_id_service = common.generate_message_id() print( "\nGenerated message ID %s for X-Road request that will cause a SOAP fault" % (message_id_service, )) print("\n---- Sending an X-Road request that will cause a SOAP fault to the " \ "client's security server ----\n") request_contents = common.format_xroad_request_template( soap_fault_query_template_filename, message_id_service) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.assert_soap_fault(xml) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) # Now make operational data requests to both security servers and check the # response payloads. print( "\n---- Sending an operational data request to the client's security server ----\n" ) message_id = common.generate_message_id() message_id_client = message_id print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print( "Generated the following query data request for the client's security server: \n" ) print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. # The record describing the X-Road request that caused a fault in server proxy common.assert_present_in_json( json_payload, _expected_keys_and_values_of_unknown_service_query_rec( message_id_serverproxy, client_security_server_address, "Client")) # The record describing the X-Road request that caused a fault in client proxy common.assert_present_in_json( json_payload, _expected_keys_and_values_of_unknown_member_query_rec( message_id_clientproxy, client_security_server_address, "Client")) # The record describing the X-Road request that caused a fault in test service common.assert_present_in_json( json_payload, _expected_keys_and_values_of_soap_fault_query_rec( message_id_service, client_security_server_address, "Client")) # Check if the timestamps in the response are in the expected range. common.assert_expected_timestamp_values( json_payload, client_timestamp_before_requests, client_timestamp_after_requests) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response) print("\n---- Sending an operational data request to the producer's " \ "security server ----\n") message_id = common.generate_message_id() message_id_producer = message_id print("\nGenerated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_producer_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests) print("Generated the following query data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request(producer_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. # The record describing the X-Road request that caused a fault in server proxy common.assert_present_in_json( json_payload, _expected_keys_and_values_of_unknown_service_query_rec( message_id_serverproxy, producer_security_server_address, "Producer")) # The record describing the X-Road request that caused a fault in test service common.assert_present_in_json( json_payload, _expected_keys_and_values_of_soap_fault_query_rec( message_id_service, producer_security_server_address, "Producer")) # Check timestamp values common.assert_expected_timestamp_values( json_payload, producer_timestamp_before_requests, producer_timestamp_after_requests) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_template.xml") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_before_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) xroad_message_id = common.generate_message_id() print("\nGenerated message ID %s for X-Road request" % (xroad_message_id, )) # The headers will be extracted after the request template has been # formatted. xroad_request_headers = None ### Regular and operational data requests and the relevant checks print("\n---- Sending an X-Road request to the client's security server ----\n") request_contents = common.format_xroad_request_template( xroad_request_template_filename, xroad_message_id) print("Generated the following X-Road request: \n") print(request_contents) request_xml = common.parse_and_clean_xml(request_contents) xroad_request_headers = request_xml.getElementsByTagName( "SOAP-ENV:Header")[0].toprettyxml() response = common.post_xml_request( client_security_server_address, request_contents) print("Received the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) # Now make operational data requests to both security servers and check the # response payloads. print("\n---- Sending an operational data request to the client's security server ----\n") message_id = common.generate_message_id() message_id_client = message_id print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print("Generated the following query data request for the client's security server: \n") print(request_contents) response = common.post_xml_request( client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, "Client")) # As operational data is queried by regular client, the field # 'securityServerInternalIp' is not expected to be included # in the response payload. common.assert_missing_in_json(json_payload, "securityServerInternalIp") # Check if the timestamps in the response are in the expected range. common.assert_expected_timestamp_values( json_payload, client_timestamp_before_requests, client_timestamp_after_requests) common.print_multipart_query_data_response(json_payload, xroad_message_id) else: common.parse_and_check_soap_response(raw_response) print("\nThe headers of the original request were: \n") print(xroad_request_headers) print("\n---- Sending an operational data request to the producer's " \ "security server ----\n") message_id = common.generate_message_id() message_id_producer = message_id print("\nGenerated message ID %s for operational data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_producer_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests) print("Generated the following operational data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request( producer_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, "Producer")) # As operational data is queried by regular client, the field # 'securityServerInternalIp' is not expected to be included # in the response payload. common.assert_missing_in_json(json_payload, "securityServerInternalIp") # Check timestamp values common.assert_expected_timestamp_values( json_payload, producer_timestamp_before_requests, producer_timestamp_after_requests) common.print_multipart_query_data_response( json_payload, xroad_message_id) else: common.parse_and_check_soap_response(raw_response) print("\nThe headers of the original request were: \n") print(xroad_request_headers) # Repeat both query_data requests after a second, to ensure the initial attempts # were also stored in the operational_data table. time.sleep(1) print("\n---- Repeating the query_data request to the client's security server ----\n") client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) message_id = common.generate_message_id() print("\nGenerated message ID %s for operational data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print("Generated the following operational data request for the client's " \ "security server: \n") print(request_contents) response = common.post_xml_request( client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of the required fields in the JSON structures. # The record describing the original X-Road request common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, "Client")) # The record describing the query data request at the client proxy side in the # client's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_query_data_client_rec( message_id_client, "Client")) # The record describing the query data request at the server proxy side in the # client's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_query_data_client_rec( message_id_client, "Producer")) # Check if the value of "responseSoapSize" is in the expected range. common.assert_response_soap_size_in_range( json_payload, message_id_client, 1837, 2) # Check if the value of "responseMimeSize" is in the expected range. common.assert_response_mime_size_in_range( json_payload, message_id_client, 2274, 2) # As operational data is queried by regular client, the field # 'securityServerInternalIp' is not expected to be included # in the response payload. common.assert_missing_in_json(json_payload, "securityServerInternalIp") # Check timestamp values common.assert_expected_timestamp_values( json_payload, client_timestamp_before_requests, client_timestamp_after_requests) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response) print("\n----- Repeating the query_data request to the producer's security server ----\n") message_id = common.generate_message_id() print("\nGenerated message ID %s for operational data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_producer_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests) print("Generated the following operational data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request( producer_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of the required fields in the JSON structures. # The record describing the original X-Road request common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, "Producer")) # The record describing the query data request at the client proxy side in the # producer's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_query_data_producer_rec( message_id_producer, "Client")) # The record describing the query data request at the server proxy side in the # producer's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_query_data_producer_rec( message_id_producer, "Producer")) # Check if the value of "responseSoapSize" is in the expected range. common.assert_response_soap_size_in_range( json_payload, message_id_producer, 1872, 2) # Check if the value of "responseMimeSize" is in the expected range. common.assert_response_mime_size_in_range( json_payload, message_id_producer, 2311, 2) # As operational data is queried by regular client, the field # 'securityServerInternalIp' is not expected to be included # in the response payload. common.assert_missing_in_json(json_payload, "securityServerInternalIp") # Check timestamp values common.assert_expected_timestamp_values( json_payload, producer_timestamp_before_requests, producer_timestamp_after_requests) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") xroad_request_attachments_template_filename = os.path.join( request_template_dir, "xroad_query_for_attachments_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_template.xml") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_before_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) message_id_one_attachment = common.generate_message_id() print("\nGenerated message ID %s for X-Road request with one " \ "attachment" % (message_id_one_attachment, )) ### Regular and operational data requests and the relevant checks print("\n---- Sending an X-Road request with one attachment to the " \ "service that will respond with three attachments ----\n") request_contents = common.format_xroad_request_template( xroad_request_attachments_template_filename, message_id_one_attachment) response = common.post_multipart_request( client_security_server_address, request_contents, attachment_count=1, get_raw_stream=True) # Expecting a multipart response with attachments. mime_parts, raw_response = common.parse_multipart_response(response) print("Received the following X-Road response: \n") print(raw_response.decode("utf-8")) if not mime_parts: common.parse_and_check_soap_response(raw_response) message_id_five_attachments = common.generate_message_id() print("\nGenerated message ID %s for X-Road request with five " \ "attachments" % (message_id_five_attachments, )) print("\n---- Sending an X-Road request with five attachments to the " \ "client's security server ----\n") request_contents = common.format_xroad_request_template( xroad_request_template_filename, message_id_five_attachments) # Expecting a simple SOAP response. response = common.post_multipart_request( client_security_server_address, request_contents, attachment_count=5) print("Received the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) common.wait_for_operational_data() client_timestamp_after_request = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_request = common.get_remote_timestamp( producer_security_server_address, ssh_user) # Now make operational data requests to both security servers and check the # response payloads. print("\n---- Sending an operational data request to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_request) print("Generated the following query data request for the client's security server: \n") print(request_contents) response = common.post_xml_request( client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. # The record describing the query with one attachment common.assert_present_in_json( json_payload, _expected_keys_and_values_of_one_attachment_query_rec( message_id_one_attachment, "Client")) # The record describing the query with five attachments common.assert_present_in_json( json_payload, _expected_keys_and_values_of_five_attachments_query_rec( message_id_five_attachments, "Client")) # As operational data is queried by regular client, the field # 'securityServerInternalIp' is not expected to be included # in the response payload. common.assert_missing_in_json(json_payload, "securityServerInternalIp") # Check if the timestamps in the response are in the expected range. common.assert_expected_timestamp_values( json_payload, client_timestamp_before_requests, client_timestamp_after_request) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response) print("\n---- Sending an operational data request to the producer's " \ "security server ----\n") message_id = common.generate_message_id() print("\nGenerated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_producer_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_request) print("Generated the following query data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request( producer_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of all the required fields in at least one JSON structure. # The record describing the query with one attachment common.assert_present_in_json( json_payload, _expected_keys_and_values_of_one_attachment_query_rec( message_id_one_attachment, "Producer")) # The record describing the query with five attachments common.assert_present_in_json( json_payload, _expected_keys_and_values_of_five_attachments_query_rec( message_id_five_attachments, "Producer")) # As operational data is queried by regular client, the field # 'securityServerInternalIp' is not expected to be included # in the response payload. common.assert_missing_in_json(json_payload, "securityServerInternalIp") # Check if the timestamps in the response are in the expected range. common.assert_expected_timestamp_values( json_payload, producer_timestamp_before_requests, producer_timestamp_after_request) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_template.xml") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_before_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) xroad_message_id = common.generate_message_id() print("\nGenerated message ID %s for X-Road request" % (xroad_message_id, )) ### Regular and operational data requests and the relevant checks print( "\n---- Sending an X-Road request to the client's security server ----\n" ) request_contents = common.format_xroad_request_template( xroad_request_template_filename, xroad_message_id) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents) print("Received the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) producer_timestamp_after_requests = common.get_remote_timestamp( producer_security_server_address, ssh_user) # Now make operational data requests to both security servers and check the # response payloads. print( "\n---- Sending an operational data request to the client's security server ----\n" ) message_id = common.generate_message_id() print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print( "Generated the following query data request for the client's security server: \n" ) print(request_contents) response = common.post_xml_request(client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) # op-monitor-buffer.size=0 must result in an empty response common.check_record_count(record_count, 0) else: common.parse_and_check_soap_response(raw_response) message_id = common.generate_message_id() print("\nGenerated message ID %s for operational data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_producer_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests) print("Generated the following operational data request for the producer's " \ "security server: \n") print(request_contents) response = common.post_xml_request(producer_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count( mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False) # op-monitor-buffer.size=0 must result in an empty response common.check_record_count(record_count, 0) else: common.parse_and_check_soap_response(raw_response)
def run(client_security_server_address, producer_security_server_address, ssh_user, request_template_dir): xroad_query_to_ss0_service_template_filename = os.path.join( request_template_dir, "xroad_query_to_ss0_service_template.xml") xroad_query_to_ss2_service_template_filename = os.path.join( request_template_dir, "xroad_query_to_ss2_service_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_template.xml") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) message_id_ss0 = common.generate_message_id() print("\nGenerated message ID %s for X-Road request" % (message_id_ss0, )) ### Regular and operational data requests and the relevant checks print("\n---- Sending an X-Road request to the service provider in " \ "security server 00000000_1 ----\n") request_contents = common.format_xroad_request_template( xroad_query_to_ss0_service_template_filename, message_id_ss0) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request( client_security_server_address, request_contents) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) message_id_ss2 = common.generate_message_id() print("\nGenerated message ID %s for X-Road request" % (message_id_ss2, )) print("\n---- Sending an X-Road request to the service provider in " \ "security server 00000002_1 ----\n") request_contents = common.format_xroad_request_template( xroad_query_to_ss2_service_template_filename, message_id_ss2) print("Generated the following X-Road request: \n") print(request_contents) response = common.post_xml_request( client_security_server_address, request_contents) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) common.check_soap_fault(xml) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) # Now make an operational data request to the client's security server # and check the response payload. print("\n---- Sending an operational data request to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID %s for query data request" % (message_id, )) request_contents = common.format_query_operational_data_request_template( query_data_client_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests) print("Generated the following query data request for the client's security server: \n") print(request_contents) response = common.post_xml_request( client_security_server_address, request_contents, get_raw_stream=True) mime_parts, raw_response = common.parse_multipart_response(response) if mime_parts: soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0]) common.print_multipart_soap_and_record_count(soap_part, record_count) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Check the presence of the required fields in at least one JSON structure. # The record describing the X-Road request to service provider in # security server 00000000_1 common.assert_present_in_json( json_payload, _expected_keys_and_values_of_cluster_query_rec( message_id_ss0, "xtee8.ci.kit")) # The record describing the X-Road request to service provider in # security server 00000002_1 common.assert_present_in_json( json_payload, _expected_keys_and_values_of_cluster_query_rec( message_id_ss2, "xtee10.ci.kit")) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)