def run(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") query_operational_data_producer_ss1_client_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_ss1_client_template.xml") query_operational_data_client_ss0_owner_template_filename = os.path.join( request_template_dir, "query_operational_data_client_ss0_owner_template.xml") query_operational_data_client_ss_owner_template_filename = os.path.join( request_template_dir, "query_operational_data_client_ss_owner_template.xml") query_operational_data_client_central_monitoring_template_filename = os.path.join( request_template_dir, "query_operational_data_client_central_monitoring_template.xml") query_operational_data_client_ss_owner_filtered_template_filename = os.path.join( request_template_dir, "query_operational_data_client_ss_owner_filtered_template.xml") query_operational_data_client_central_monitoring_filtered_template_filename = os.path.join( request_template_dir, "query_operational_data_client_central_monitoring_filtered_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_template.xml") query_data_client_filtered_template_filename = os.path.join( request_template_dir, "query_operational_data_client_filtered_template.xml") query_operational_data_client_ss0_owner_filtered_template_filename = os.path.join( request_template_dir, "query_operational_data_client_ss0_owner_filtered_template.xml") query_data_client_invalid_filter_template_filename = os.path.join( request_template_dir, "query_operational_data_client_invalid_filter_template.xml") query_data_client_unknown_member_template_filename = os.path.join( request_template_dir, "query_operational_data_client_unknown_member_template.xml") query_data_client_unknown_subsystem_template_filename = os.path.join( request_template_dir, "query_operational_data_client_unknown_subsystem_template.xml") client_timestamp_before_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) xroad_message_id = common.generate_message_id() print("\nGenerated message ID {} for X-Road request".format(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, query_parameters) 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) # Send an operational data request from SS1 client to the producer's # security server message_id = common.generate_message_id() message_id_producer = message_id print("\n---- Sending an operational data request from SS1 client" " to the producer's security server ----\n") request_contents = common.format_query_operational_data_request_template( query_operational_data_producer_ss1_client_template_filename, message_id, 1, 2, query_parameters) print("Generated the following operational data request for the producer'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) else: common.parse_and_check_soap_response(raw_response) # Send an operational data request from SS0 owner to the client's # security server message_id = common.generate_message_id() message_id_client = message_id print("\n---- Sending an operational data request from the SS0 owner" " to the client's security server ----\n") request_contents = common.format_query_operational_data_request_template( query_operational_data_client_ss0_owner_template_filename, message_id, 1, 2, query_parameters) print("Generated the following operational data request for the client'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) else: common.parse_and_check_soap_response(raw_response) common.wait_for_operational_data() client_timestamp_after_requests = common.get_remote_timestamp( client_security_server_address, ssh_user) # Now make operational data requests to client's security server as # security server owner, central monitoring client and regular # client and check the response payloads. print("\n---- Sending an operational data request from the security server " "owner to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_operational_data_client_ss_owner_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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]) # Security server owner is expected to receive all three query # records. # Check the presence of all the required fields in at least one # JSON structure. # The record describing the X-Road request at the client proxy # side in the client's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, client_security_server_address, "Client", query_parameters)) # 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_proxy_rec( message_id_producer, client_security_server_address, "Client", query_parameters)) # 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_server_proxy_rec( message_id_client, client_security_server_address, "Producer", query_parameters)) # 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---- Sending an operational data request from the central " "monitoring client to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_operational_data_client_central_monitoring_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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]) # Central monitoring client is expected to receive all three query # records. # Check the presence of all the required fields in at least one JSON structure. # The record describing the X-Road request at the client proxy side # in the client's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, client_security_server_address, "Client", query_parameters)) # 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_proxy_rec( message_id_producer, client_security_server_address, "Client", query_parameters)) # 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_server_proxy_rec( message_id_client, client_security_server_address, "Producer", query_parameters)) # 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---- Sending an operational data request from the security server " "owner with the member 'GOV:00000000' in search criteria " "to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_operational_data_client_ss_owner_filtered_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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]) # With the member 'GOV:00000000' in search criteria, # security server owner is expected to receive only the query # record where the member 'GOV:00000000' is the service provider. common.check_record_count(record_count, 1) # Check the presence of all the required fields in at least one JSON structure. # 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_proxy_rec( message_id_producer, client_security_server_address, "Client", query_parameters)) # 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---- Sending an operational data request from the central monitoring " "client with the subsystem 'GOV:00000000:Center' in search " "criteria to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_operational_data_client_central_monitoring_filtered_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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]) # With the subsystem 'GOV:00000000:Center' in search criteria, # central monitoring client is expected to receive only the query # record where the subsystem 'GOV:00000000:Center' is # the service provider. common.check_record_count(record_count, 1) # Check the presence of all the required fields in at least one JSON structure. # The record describing the X-Road request at the client proxy # side in the client's security server common.assert_present_in_json( json_payload, _expected_keys_and_values_of_simple_query_rec( xroad_message_id, client_security_server_address, "Client", query_parameters)) # 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---- Sending an operational data request from regular client " "'GOV:00000001:System1' to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(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, query_parameters) 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) # Remove the field 'securityServerInternalIp' from expected keys # and values lists expected_keys_and_values_of_simple_query_rec = ( _expected_keys_and_values_of_simple_query_rec( xroad_message_id, client_security_server_address, "Client", query_parameters)) expected_keys_and_values_of_query_data_client_proxy_rec = ( _expected_keys_and_values_of_query_data_client_proxy_rec( message_id_producer, client_security_server_address, "Client", query_parameters)) list_of_expected_keys_and_values = [ expected_keys_and_values_of_simple_query_rec, expected_keys_and_values_of_query_data_client_proxy_rec] common.remove_key_from_list( "securityServerInternalIp", list_of_expected_keys_and_values) 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]) # Regular client 'GOV:00000001:System1' is expected to receive # the two query records where the subsystem # 'GOV:00000001:System1' is the client. common.check_record_count(record_count, 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 the presence of all the required fields in at least one # JSON structure. # The record describing the X-Road request at the client proxy # side in the client's security server common.assert_present_in_json( json_payload, expected_keys_and_values_of_simple_query_rec) # 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_proxy_rec) # 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---- Sending an operational data request from regular client " "'GOV:00000000' to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_operational_data_client_ss0_owner_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) print("Generated the following query data request for the client'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) json_payload = common.get_multipart_json_payload(mime_parts[1]) # Regular client 'GOV:00000000' is expected to receive two records: the # query record where the member 'GOV:00000000' is the client and the # query record where the member 'GOV:00000000' is the service provider. common.check_record_count(record_count, 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") # Remove the field 'securityServerInternalIp' from expected keys # and values list expected_keys_and_values_of_query_data_server_proxy_rec = ( _expected_keys_and_values_of_query_data_server_proxy_rec( message_id_client, client_security_server_address, "Producer", query_parameters)) common.remove_key_from_list( "securityServerInternalIp", [expected_keys_and_values_of_query_data_server_proxy_rec]) # Check the presence of all the required fields in at least one # JSON structure. # 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_proxy_rec) # 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_server_proxy_rec) # 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---- Sending an operational data request from regular client " "'GOV:00000001:System1' with the member 'GOV:00000000' in " "search criteria to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_data_client_filtered_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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]) # With the member 'GOV:00000000' in search criteria, # regular client 'GOV:00000001:System1' is expected to receive # one query record where the subsystem 'GOV:00000001:System1' # is the client and the member 'GOV:00000000' is the service # provider. common.check_record_count(record_count, 1) # 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 the presence of all the required fields in at least one # JSON structure. # 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_proxy_rec) # 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---- Sending an operational data request from regular client " "'GOV:0000000' with the member 'GOV:00000000' in " "search criteria to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_operational_data_client_ss0_owner_filtered_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) print("Generated the following query data request for the client'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) json_payload = common.get_multipart_json_payload(mime_parts[1]) # With the member 'GOV:00000000' in search criteria, # regular client 'GOV:00000000' is expected to receive one # query record where the member 'GOV:00000000' is the service # provider. common.check_record_count(record_count, 1) # 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 the presence of all the required fields in at least one JSON structure. # 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_proxy_rec) # 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) message_id = common.generate_message_id() print("\n---- Sending an operational data request with invalid client" " in search criteria to the client's security server ----\n") request_contents = common.format_query_operational_data_request_template( query_data_client_invalid_filter_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) # Invalid client in search criteria of the operational monitoring request # must result in a SOAP fault common.assert_soap_fault(xml) print("\n---- Sending an operational data request with an unknown member " "in search criteria to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_data_client_unknown_member_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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) # Unknown member in search criteria must result in an empty response common.check_record_count(record_count, 0) else: common.parse_and_check_soap_response(raw_response) print("\n---- Sending an operational data request with an unknown " "subsystem in search criteria to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_data_client_unknown_subsystem_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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) # Unknown subsystem in search criteria must result in an empty # response common.check_record_count(record_count, 0) else: common.parse_and_check_soap_response(raw_response)
def run(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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 {} for X-Road request".format( 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, query_parameters) print("Generated the following X-Road request: \n") print(request_contents) request_xml = common.parse_and_clean_xml(request_contents) # Headers of the original request 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 {} for query data request".format(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, query_parameters) 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", query_parameters)) # 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 {} for operational data request".format( 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, query_parameters) 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", query_parameters)) # 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 {} for operational data request".format( 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, query_parameters) 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", query_parameters)) # 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", query_parameters)) # 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", query_parameters)) # Check if the value of "responseSize" is in the expected # range. common.assert_response_soap_size_in_range( json_payload, message_id_client, (QUERY_DATA_CLIENT_RESPONSE_SOAP_BASE_SIZE + _query_data_client_request_parameters_size(query_parameters)), 2) # Check if the value of "responseMimeSize" is in the expected # range. common.assert_response_mime_size_in_range( json_payload, message_id_client, (QUERY_DATA_CLIENT_RESPONSE_MIME_BASE_SIZE + _query_data_client_request_parameters_size(query_parameters)), 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 {} for operational data request".format( 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, query_parameters) 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", query_parameters)) # 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", query_parameters)) # 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", query_parameters)) # Check if the value of "responseSize" is in the expected # range. common.assert_response_soap_size_in_range( json_payload, message_id_producer, (QUERY_DATA_PRODUCER_RESPONSE_SOAP_BASE_SIZE + _query_data_producer_request_parameters_size(query_parameters)), 2) # Check if the value of "responseMimeSize" is in the expected # range. common.assert_response_mime_size_in_range( json_payload, message_id_producer, (QUERY_DATA_PRODUCER_RESPONSE_MIME_BASE_SIZE + _query_data_producer_request_parameters_size(query_parameters)), 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(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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 {} for X-Road request with one " "attachment".format(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, query_parameters) 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 {} for X-Road request with five " "attachments".format(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, query_parameters) # 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 {} for query data request".format(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, query_parameters) 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", query_parameters)) # 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", query_parameters)) # 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 {} for query data request".format(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, query_parameters) 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", query_parameters)) # 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", query_parameters)) # 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(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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) # 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 {} for query data request".format(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, query_parameters) 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={}&memberClass={}&memberCode={}&subsystemCode={}" "&serviceCode=mock&version=v1".format( query_parameters["producer_instance"], query_parameters["producer_class"], query_parameters["producer_code"], query_parameters["producer_system"])) 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 {} for query data request".format( 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, query_parameters) 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", query_parameters)) # 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 {} for query data request".format(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, query_parameters) 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", query_parameters)) # 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(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] listmethods_query_template_filename = os.path.join( request_template_dir, "listmethods_producer_query_template.xml") get_ss_metrics_query_template_filename = os.path.join( request_template_dir, "get_ss_metrics_query_template.xml") query_data_client_template_filename = os.path.join( request_template_dir, "query_operational_data_client_central_monitoring_template.xml") query_data_producer_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_central_monitoring_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_listmethods = common.generate_message_id() print("\nGenerated message ID {} for listMethods request".format(message_id_listmethods)) # Regular and operational data requests and the relevant checks print("\n---- Sending a listMethods request to the client's security server ----\n") request_contents = common.format_xroad_request_template( listmethods_query_template_filename, message_id_listmethods, query_parameters) print("Generated the following listMethods 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) message_id_get_ss_metrics = common.generate_message_id() print("\nGenerated message ID {} for getSecurityServerMetrics request".format( message_id_get_ss_metrics)) print("\n---- Sending a getSecurityServerMetrics request to " "the client's security server ----\n") request_contents = common.format_xroad_request_template( get_ss_metrics_query_template_filename, message_id_get_ss_metrics, query_parameters) print("Generated the following getSecurityServerMetrics 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]) # getSecurityServerMetrics response is large, print only headers common.print_multipart_soap_headers(soap_part) # Program should never get here unless getSecurityServerMetrics # will be changed to return data in attachments instead of # SOAP Body raise Exception("\nWARNING!!! getSecurityServerMetrics returned attachments\n") else: common.parse_and_check_soap_response(raw_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. print("\n---- Sending an operational data request to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(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, query_parameters) 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_listmethods_query_rec( message_id_listmethods, client_security_server_address, "Client", query_parameters)) common.assert_present_in_json( json_payload, _expected_keys_and_values_of_get_ss_metrics_query_rec( message_id_get_ss_metrics, client_security_server_address, "Client", query_parameters)) # 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) # Central monitoring client is used as a service client in # operational data request. As central monitoring client is # registered in client's security server, let's send the # operational data request to producer's security server via # client's security server. print("\n---- Sending an operational data request from central monitoring client " "to the producer's security server ----\n") message_id = common.generate_message_id() print("\nGenerated message ID {} for query data request".format(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, query_parameters) print("Generated the following query data request for the producer'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, 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_listmethods_query_rec( message_id_listmethods, producer_security_server_address, "Producer", query_parameters)) common.assert_present_in_json( json_payload, _expected_keys_and_values_of_get_ss_metrics_query_rec( message_id_get_ss_metrics, producer_security_server_address, "Producer", query_parameters)) # Check timestamp values common.assert_expected_timestamp_values( json_payload, producer_timestamp_before_requests, producer_timestamp_after_requests) common.assert_equal_timestamp_values(json_payload) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)
def run(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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 {} for X-Road request".format(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, query_parameters) 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 {} for query data request".format(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, query_parameters) 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 {} for operational data request".format(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, query_parameters) 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(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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 {}".format(message_id)) request_contents = common.format_xroad_request_template( xroad_request_template_filename, message_id, query_parameters) 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), query_parameters) 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), query_parameters, is_client=False)
def run(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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_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 {} for X-Road request".format( 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, query_parameters) 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 {} for health data request".format(message_id)) request_contents = common.format_query_health_data_request_template( query_data_producer_template_filename, message_id, query_parameters) 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 mock service in the response") event_data = _find_health_data_events_for_service( response, MOCK_SERVICE_XML_TEMPLATE.format(params=query_parameters)) if event_data is None: raise Exception("Health data about mock 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_MOCK_STATS.keys()) _assert_xml_tags_match_values(event_data, PREDICTABLE_FIELDS_MOCK, _get_producer_mock_stats(query_parameters)) # Send a listMethods request to the client. listmethods_message_id = common.generate_message_id() print("\nGenerated message ID {} for the listMethods request to the " "client".format(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, query_parameters) 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) # Send a health data request to the client. client_pre_health_data_timestamp = common.get_remote_timestamp( client_security_server_address, ssh_user) common.wait_for_operational_data() message_id = common.generate_message_id() print("Generated message ID {} for health data request".format(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, query_parameters) 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_TEMPLATE.format(params=query_parameters)) 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_LISTMETHODS, _get_client_listmethods_stats(query_parameters)) # 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 {} for health data request".format(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, query_parameters) 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 {} for health data request".format(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, query_parameters) 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, MOCK_SERVICE_XML_TEMPLATE.format(params=query_parameters)) if event_data is None: raise Exception( "Health data about mock service was not found in the response") event_data = _find_health_data_events_for_service( response, GET_HEALTH_DATA_SERVICE_XML_TEMPLATE.format(params=query_parameters)) 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 {} for health data request".format(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, query_parameters) 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, MOCK_SERVICE_XML_TEMPLATE.format(params=query_parameters)) if event_data is None: raise Exception( "Health data about mock service 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_TEMPLATE.format(params=query_parameters)) 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 unsuccessful 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 {} for an X-Road request that will cause " "a SOAP fault".format(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, query_parameters) 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 {} for health data request".format(message_id)) request_contents = common.format_query_health_data_request_template( query_data_producer_template_filename, message_id, query_parameters) 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 mock but the result was a fault. print("Looking for the mock service in the response") event_data = _find_health_data_events_for_service( response, MOCK_SERVICE_XML_TEMPLATE.format(params=query_parameters)) if event_data is None: raise Exception( "Health data about mock service 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(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] ssh_user = query_parameters["ssh_user"] 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 {} for X-Road request".format(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 {} ----\n".format( query_parameters["producer_server_address"])) request_contents = common.format_xroad_request_template( xroad_query_to_ss0_service_template_filename, message_id_ss0, query_parameters) 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 {} for X-Road request".format(message_id_ss2)) print("\n---- Sending an X-Road request to the service provider in " "security server {} ----\n".format( query_parameters["producer2_server_address"])) request_contents = common.format_xroad_request_template( xroad_query_to_ss2_service_template_filename, message_id_ss2, query_parameters) 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 {} for query data request".format(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, query_parameters) 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 'producer' common.assert_present_in_json( json_payload, _expected_keys_and_values_of_cluster_query_rec( message_id_ss0, query_parameters["producer_server_address"])) # The record describing the X-Road request to service provider # in security server 'producer2' common.assert_present_in_json( json_payload, _expected_keys_and_values_of_cluster_query_rec( message_id_ss2, query_parameters["producer2_server_address"])) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)
def run(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] 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 {} for X-Road request to unknown service". format(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, query_parameters) 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 {} for X-Road request from unknown member". format(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, query_parameters) 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 {} for X-Road request that will cause a SOAP fault" .format(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, query_parameters) 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() print("Generated message ID {} for query data request".format(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, query_parameters) 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", query_parameters)) # 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", query_parameters)) # 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", query_parameters)) # 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 {} for query data request".format(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, query_parameters) 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", query_parameters)) # 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", query_parameters)) # 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(request_template_dir, query_parameters): client_security_server_address = query_parameters["client_server_ip"] producer_security_server_address = query_parameters["producer_server_ip"] ssh_user = query_parameters["ssh_user"] xroad_request_template_filename = os.path.join( request_template_dir, "simple_xroad_query_template.xml") query_data_client_outputspec_template_filename = os.path.join( request_template_dir, "query_operational_data_client_outputspec_template.xml") query_data_client_faulty_outputspec_template_filename = os.path.join( request_template_dir, "query_operational_data_client_faulty_outputspec_template.xml") query_data_producer_empty_outputspec_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_empty_outputspec_template.xml") query_data_producer_outputspec_template_filename = os.path.join( request_template_dir, "query_operational_data_producer_outputspec_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 {} for X-Road requests".format( xroad_message_id)) # Regular and operational data requests and the relevant checks print( "\n---- Sending 3 X-Road requests to the client's security server ----\n" ) request_contents = common.format_xroad_request_template( xroad_request_template_filename, xroad_message_id, query_parameters) print("Generated the following X-Road request: \n") print(request_contents) # Send 3 X-Road requests for _ in range(3): 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 with correct outputspec " "to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_data_client_outputspec_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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]) common.print_multipart_query_data_response(json_payload) # Check the presence of all the required fields. # Check the number of fields in JSON records is consistent with # the number of parameters requested. common.assert_json_fields( json_payload, _expected_keys_and_values_of_limited_spec_query_rec( query_parameters)) else: common.parse_and_check_soap_response(raw_response) print("\n---- Sending an operational data request with faulty outputspec " "to the client's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for faulty query data request".format( message_id)) request_contents = common.format_query_operational_data_request_template( query_data_client_faulty_outputspec_template_filename, message_id, client_timestamp_before_requests, client_timestamp_after_requests, query_parameters) 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) print("\nReceived the following X-Road response: \n") xml = common.parse_and_clean_xml(response.text) print(xml.toprettyxml()) # Using an unknown parameter in outputspec must result in # a SOAP fault. common.assert_soap_fault(xml) print( "\n---- Sending an operational data request with an empty outputspec " "to the producer's security server ----\n") message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_data_producer_empty_outputspec_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests, query_parameters) 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]) # Empty outputspec element in the request must result in all # operational data parameters in the response. # 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", query_parameters)) # 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) print( "\n---- Sending an operational data request with an outputspec " "that contains only faultCode to the producer's security server ----\n" ) message_id = common.generate_message_id() print("Generated message ID {} for query data request".format(message_id)) request_contents = common.format_query_operational_data_request_template( query_data_producer_outputspec_template_filename, message_id, producer_timestamp_before_requests, producer_timestamp_after_requests, query_parameters) 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]) # Empty JSON records are expected as the response. common.assert_empty_json_records(json_payload) common.print_multipart_query_data_response(json_payload) else: common.parse_and_check_soap_response(raw_response)