Example #1
0
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):
    query_data_client_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_client_ss_owner_template.xml")
    query_data_producer_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_producer_ss_owner_template.xml")

    ### Metadata and operational data requests and the relevant checks

    client_timestamp_before_requests = common.get_remote_timestamp(
        client_security_server_address, ssh_user)

    print(
        "\n---- Sending a verificationconf request to the client's security server ----\n"
    )

    response = common.make_get_request(client_security_server_address +
                                       "/verificationconf")

    common.check_status(response)

    print("Received the following status code and response headers: \n")
    common.print_response_status_and_headers(response)

    print(
        "\n---- Sending a listClients request to the client's security server ----\n"
    )

    response = common.make_get_request(client_security_server_address +
                                       "/listClients")

    common.check_status(response)

    print("Received the following response: \n")
    common.print_response_status_and_headers(response)

    common.wait_for_operational_data()

    client_timestamp_after_requests = common.get_remote_timestamp(
        client_security_server_address, ssh_user)
    producer_timestamp_after_requests = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

    # Now make an operational data request to the client's security server and check the
    # response payload.
    # We expect that neither of the requests sent above have been stored in the
    # operational monitoring database.

    print(
        "\n---- Sending an operational data request to the client's security server ----\n"
    )

    message_id = common.generate_message_id()

    print("Generated message ID %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id,
        client_timestamp_before_requests, client_timestamp_after_requests)

    print(
        "Generated the following query data request for the client's security server: \n"
    )
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents,
                                       get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(
            mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)
        common.check_record_count(record_count, 0)

    else:
        common.parse_and_check_soap_response(raw_response)

    # Wait a second to ensure that the previous operational data request is not included
    # in the operational data that we request below.
    time.sleep(1)

    print(
        "\n---- Sending a wsdl request to the client's security server ----\n")

    client_timestamp_before_requests = common.get_remote_timestamp(
        client_security_server_address, ssh_user)
    producer_timestamp_before_requests = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

    response = common.make_get_request(
            client_security_server_address + "/wsdl?xRoadInstance=" \
            "XTEE-CI-XM&memberClass=GOV&memberCode=00000000&subsystemCode=" \
            "Center&serviceCode=xroadGetRandom&version=v1")

    common.check_status(response)

    print("Received the following response: \n")
    common.print_response_status_and_headers(response)

    common.wait_for_operational_data()

    client_timestamp_after_requests = common.get_remote_timestamp(
        client_security_server_address, ssh_user)
    producer_timestamp_after_requests = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

    # Now make operational data requests to both security servers and check the
    # response payloads. We expect that the wsdl request has been stored in the
    # operational monitoring database.

    print(
        "\n---- Sending an operational data request to the client's security server ----\n"
    )

    message_id = common.generate_message_id()
    print("Generated message ID %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id,
        client_timestamp_before_requests, client_timestamp_after_requests)

    print(
        "Generated the following query data request for the client's security server: \n"
    )
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents,
                                       get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(
            mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_wsdl_query_rec(
                client_security_server_address, "Client"))

        # Check if the timestamps in the response are in the expected range.
        common.assert_expected_timestamp_values(
            json_payload, client_timestamp_before_requests,
            client_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)

    print("\n---- Sending an operational data request to the producer's " \
                "security server ----\n")

    message_id = common.generate_message_id()
    print("\nGenerated message ID %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
        query_data_producer_template_filename, message_id,
        producer_timestamp_before_requests, producer_timestamp_after_requests)
    print("Generated the following query data request for the producer's " \
            "security server: \n")
    print(request_contents)

    response = common.post_xml_request(producer_security_server_address,
                                       request_contents,
                                       get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(
            mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part,
                                                     record_count,
                                                     is_client=False)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_wsdl_query_rec(
                producer_security_server_address, "Producer"))

        # Check timestamp values
        common.assert_expected_timestamp_values(
            json_payload, producer_timestamp_before_requests,
            producer_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):

    xroad_request_template_filename = os.path.join(
        request_template_dir, "simple_xroad_query_template.xml")
    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)
    producer_timestamp_before_requests = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

    xroad_message_id = common.generate_message_id()
    print("\nGenerated message ID %s for X-Road request" %
          (xroad_message_id, ))

    ### Regular and operational data requests and the relevant checks
    print(
        "\n---- Sending an X-Road request to the client's security server ----\n"
    )

    request_contents = common.format_xroad_request_template(
        xroad_request_template_filename, xroad_message_id)
    print("Generated the following X-Road request: \n")
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    print("Received the following X-Road response: \n")
    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    # 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)
    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)
    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)

    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 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 %s for query data request" % (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)

    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"))

        # 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"))

        # 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"))

        # 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 %s for query data request" % (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)

    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"))

        # 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"))

        # 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"))

        # 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 %s for query data request" % (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)

    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"))

        # 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 %s for query data request" % (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)

    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"))

        # 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 %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id,
        client_timestamp_before_requests, client_timestamp_after_requests)

    print(
        "Generated the following query data request for the client's security server: \n"
    )
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents,
                                       get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(
            mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # 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")

        # Remove the field 'securityServerInternalIp' from expected keys
        # and values lists
        expected_keys_and_valuesof_simple_query_rec = _expected_keys_and_values_of_simple_query_rec(
            xroad_message_id, client_security_server_address, "Client")
        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")
        list_of_expected_keys_and_values = [
            expected_keys_and_valuesof_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)

        # 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_valuesof_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 %s for query data request" % (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)

    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")
        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 %s for query data request" % (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)

    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 %s for query data request" % (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)

    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)
    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 %s for query data request" % (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)

    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 %s for query data request" % (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)

    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)
Example #3
0
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):

    xroad_request_template_filename = os.path.join(
            request_template_dir, "simple_xroad_query_template.xml")
    query_data_client_template_filename = os.path.join(
            request_template_dir, "query_operational_data_client_template.xml")
    query_data_producer_template_filename = os.path.join(
            request_template_dir, "query_operational_data_producer_template.xml")

    client_timestamp_before_requests = common.get_remote_timestamp(
            client_security_server_address, ssh_user)
    producer_timestamp_before_requests = common.get_remote_timestamp(
            producer_security_server_address, ssh_user)

    xroad_message_id = common.generate_message_id()
    print("\nGenerated message ID %s for X-Road request" % (xroad_message_id, ))

    # The headers will be extracted after the request template has been
    # formatted.
    xroad_request_headers = None

    ### Regular and operational data requests and the relevant checks

    print("\n---- Sending an X-Road request to the client's security server ----\n")

    request_contents = common.format_xroad_request_template(
            xroad_request_template_filename, xroad_message_id)
    print("Generated the following X-Road request: \n")
    print(request_contents)

    request_xml = common.parse_and_clean_xml(request_contents)
    xroad_request_headers = request_xml.getElementsByTagName(
            "SOAP-ENV:Header")[0].toprettyxml()

    response = common.post_xml_request(
            client_security_server_address, request_contents)

    print("Received the following X-Road response: \n")
    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    common.wait_for_operational_data()

    client_timestamp_after_requests = common.get_remote_timestamp(
            client_security_server_address, ssh_user)
    producer_timestamp_after_requests = common.get_remote_timestamp(
            producer_security_server_address, ssh_user)

    # Now make operational data requests to both security servers and check the
    # response payloads.

    print("\n---- Sending an operational data request to the client's security server ----\n")

    message_id = common.generate_message_id()
    message_id_client = message_id
    print("Generated message ID %s for query data request" % (message_id, ))
 
    request_contents = common.format_query_operational_data_request_template(
            query_data_client_template_filename, message_id,
            client_timestamp_before_requests, client_timestamp_after_requests)

    print("Generated the following query data request for the client's security server: \n")
    print(request_contents)

    response = common.post_xml_request(
            client_security_server_address, request_contents,
            get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_simple_query_rec(
                    xroad_message_id, "Client"))

        # As operational data is queried by regular client, the field
        # 'securityServerInternalIp' is not expected to be included 
        # in the response payload.
        common.assert_missing_in_json(json_payload, "securityServerInternalIp")

        # Check if the timestamps in the response are in the expected range.
        common.assert_expected_timestamp_values(
                json_payload,
                client_timestamp_before_requests, client_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload, xroad_message_id)

    else:
        common.parse_and_check_soap_response(raw_response)
 
    print("\nThe headers of the original request were: \n")
    print(xroad_request_headers)

    print("\n---- Sending an operational data request to the producer's " \
                "security server ----\n")

    message_id = common.generate_message_id()
    message_id_producer = message_id
    print("\nGenerated message ID %s for operational data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
            query_data_producer_template_filename, message_id,
            producer_timestamp_before_requests, producer_timestamp_after_requests)
    print("Generated the following operational data request for the producer's " \
            "security server: \n")
    print(request_contents)

    response = common.post_xml_request(
            producer_security_server_address, request_contents,
            get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_simple_query_rec(
                    xroad_message_id, "Producer"))

        # As operational data is queried by regular client, the field
        # 'securityServerInternalIp' is not expected to be included 
        # in the response payload.
        common.assert_missing_in_json(json_payload, "securityServerInternalIp")

        # Check timestamp values
        common.assert_expected_timestamp_values(
                json_payload,
                producer_timestamp_before_requests, producer_timestamp_after_requests)

        common.print_multipart_query_data_response(
                json_payload, xroad_message_id)

    else:
        common.parse_and_check_soap_response(raw_response)

    print("\nThe headers of the original request were: \n")
    print(xroad_request_headers)
 
    # Repeat both query_data requests after a second, to ensure the initial attempts
    # were also stored in the operational_data table.
    time.sleep(1)

    print("\n---- Repeating the query_data request to the client's security server ----\n")

    client_timestamp_after_requests = common.get_remote_timestamp(
            client_security_server_address, ssh_user)
    producer_timestamp_after_requests = common.get_remote_timestamp(
            producer_security_server_address, ssh_user)

    message_id = common.generate_message_id()
    print("\nGenerated message ID %s for operational data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
            query_data_client_template_filename, message_id,
            client_timestamp_before_requests, client_timestamp_after_requests)
    print("Generated the following operational data request for the client's " \
            "security server: \n")
    print(request_contents)

    response = common.post_xml_request(
            client_security_server_address, request_contents, get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of the required fields in the JSON structures.

        # The record describing the original X-Road request
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_simple_query_rec(
                    xroad_message_id, "Client"))

        # The record describing the query data request at the client proxy side in the
        # client's security server
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_query_data_client_rec(
                    message_id_client, "Client"))

        # The record describing the query data request at the server proxy side in the
        # client's security server
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_query_data_client_rec(
                    message_id_client, "Producer"))

        # Check if the value of "responseSoapSize" is in the expected range.
        common.assert_response_soap_size_in_range(
                json_payload, message_id_client, 1837, 2)

        # Check if the value of "responseMimeSize" is in the expected range.
        common.assert_response_mime_size_in_range(
                json_payload, message_id_client, 2274, 2)

        # As operational data is queried by regular client, the field
        # 'securityServerInternalIp' is not expected to be included 
        # in the response payload.
        common.assert_missing_in_json(json_payload, "securityServerInternalIp")

        # Check timestamp values
        common.assert_expected_timestamp_values(
                json_payload,
                client_timestamp_before_requests, client_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)

    print("\n----- Repeating the query_data request to the producer's security server ----\n")

    message_id = common.generate_message_id()
    print("\nGenerated message ID %s for operational data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
            query_data_producer_template_filename, message_id,
            producer_timestamp_before_requests, producer_timestamp_after_requests)
    print("Generated the following operational data request for the producer's " \
            "security server: \n")
    print(request_contents)

    response = common.post_xml_request(
            producer_security_server_address, request_contents, get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of the required fields in the JSON structures.
 
        # The record describing the original X-Road request
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_simple_query_rec(
                    xroad_message_id, "Producer"))

        # The record describing the query data request at the client proxy side in the
        # producer's security server
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_query_data_producer_rec(
                    message_id_producer, "Client"))

        # The record describing the query data request at the server proxy side in the
        # producer's security server
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_query_data_producer_rec(
                    message_id_producer, "Producer"))

        # Check if the value of "responseSoapSize" is in the expected range.
        common.assert_response_soap_size_in_range(
                json_payload, message_id_producer, 1872, 2)

        # Check if the value of "responseMimeSize" is in the expected range.
        common.assert_response_mime_size_in_range(
                json_payload, message_id_producer, 2311, 2)

        # As operational data is queried by regular client, the field
        # 'securityServerInternalIp' is not expected to be included 
        # in the response payload.
        common.assert_missing_in_json(json_payload, "securityServerInternalIp")

        # Check timestamp values
        common.assert_expected_timestamp_values(
                json_payload,
                producer_timestamp_before_requests, producer_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)
Example #4
0
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):
    unknown_member_query_template_filename = os.path.join(
        request_template_dir, "unknown_member_query_template.xml")
    unknown_service_query_template_filename = os.path.join(
        request_template_dir, "unknown_service_query_template.xml")
    soap_fault_query_template_filename = os.path.join(
        request_template_dir, "soap_fault_query_template.xml")
    query_data_client_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_client_ss_owner_template.xml")
    query_data_producer_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_producer_ss_owner_template.xml")

    client_timestamp_before_requests = common.get_remote_timestamp(
        client_security_server_address, ssh_user)
    producer_timestamp_before_requests = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

    message_id_serverproxy = common.generate_message_id()
    print("\nGenerated message ID %s for X-Road request to unknown service" %
          (message_id_serverproxy, ))

    ### Regular and operational data requests and the relevant checks

    print("\n---- Sending an X-Road request to an unknown service to the client's " \
            "security server ----\n")

    request_contents = common.format_xroad_request_template(
        unknown_service_query_template_filename, message_id_serverproxy)
    print("Generated the following X-Road request: \n")
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    print("\nReceived the following X-Road response: \n")
    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.assert_soap_fault(xml)

    message_id_clientproxy = common.generate_message_id()
    print("\nGenerated message ID %s for X-Road request from unknown member" %
          (message_id_clientproxy, ))

    print("\n---- Sending an X-Road request from an unknown member to the " \
            "client's security server ----\n")

    request_contents = common.format_xroad_request_template(
        unknown_member_query_template_filename, message_id_clientproxy)
    print("Generated the following X-Road request: \n")
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    print("\nReceived the following X-Road response: \n")
    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.assert_soap_fault(xml)

    message_id_service = common.generate_message_id()
    print(
        "\nGenerated message ID %s for X-Road request that will cause a SOAP fault"
        % (message_id_service, ))

    print("\n---- Sending an X-Road request that will cause a SOAP fault to the " \
            "client's security server ----\n")

    request_contents = common.format_xroad_request_template(
        soap_fault_query_template_filename, message_id_service)
    print("Generated the following X-Road request: \n")
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    print("\nReceived the following X-Road response: \n")
    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.assert_soap_fault(xml)

    common.wait_for_operational_data()

    client_timestamp_after_requests = common.get_remote_timestamp(
        client_security_server_address, ssh_user)
    producer_timestamp_after_requests = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

    # Now make operational data requests to both security servers and check the
    # response payloads.

    print(
        "\n---- Sending an operational data request to the client's security server ----\n"
    )

    message_id = common.generate_message_id()
    message_id_client = message_id
    print("Generated message ID %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id,
        client_timestamp_before_requests, client_timestamp_after_requests)

    print(
        "Generated the following query data request for the client's security server: \n"
    )
    print(request_contents)

    response = common.post_xml_request(client_security_server_address,
                                       request_contents,
                                       get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(
            mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.

        # The record describing the X-Road request that caused a fault in server proxy
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_unknown_service_query_rec(
                message_id_serverproxy, client_security_server_address,
                "Client"))

        # The record describing the X-Road request that caused a fault in client proxy
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_unknown_member_query_rec(
                message_id_clientproxy, client_security_server_address,
                "Client"))

        # The record describing the X-Road request that caused a fault in test service
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_soap_fault_query_rec(
                message_id_service, client_security_server_address, "Client"))

        # Check if the timestamps in the response are in the expected range.
        common.assert_expected_timestamp_values(
            json_payload, client_timestamp_before_requests,
            client_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)

    print("\n---- Sending an operational data request to the producer's " \
                "security server ----\n")

    message_id = common.generate_message_id()
    message_id_producer = message_id
    print("\nGenerated message ID %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
        query_data_producer_template_filename, message_id,
        producer_timestamp_before_requests, producer_timestamp_after_requests)
    print("Generated the following query data request for the producer's " \
            "security server: \n")
    print(request_contents)

    response = common.post_xml_request(producer_security_server_address,
                                       request_contents,
                                       get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(
            mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part,
                                                     record_count,
                                                     is_client=False)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.

        # The record describing the X-Road request that caused a fault in server proxy
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_unknown_service_query_rec(
                message_id_serverproxy, producer_security_server_address,
                "Producer"))

        # The record describing the X-Road request that caused a fault in test service
        common.assert_present_in_json(
            json_payload,
            _expected_keys_and_values_of_soap_fault_query_rec(
                message_id_service, producer_security_server_address,
                "Producer"))

        # Check timestamp values
        common.assert_expected_timestamp_values(
            json_payload, producer_timestamp_before_requests,
            producer_timestamp_after_requests)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)
Example #5
0
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):
    xroad_request_template_filename = os.path.join(
            request_template_dir, "simple_xroad_query_template.xml")
    xroad_request_attachments_template_filename = os.path.join(
            request_template_dir, "xroad_query_for_attachments_template.xml")
    query_data_client_template_filename = os.path.join(
            request_template_dir, "query_operational_data_client_template.xml")
    query_data_producer_template_filename = os.path.join(
            request_template_dir, "query_operational_data_producer_template.xml")

    client_timestamp_before_requests = common.get_remote_timestamp(
            client_security_server_address, ssh_user)
    producer_timestamp_before_requests = common.get_remote_timestamp(
            producer_security_server_address, ssh_user)

    message_id_one_attachment = common.generate_message_id()
    print("\nGenerated message ID %s for X-Road request with one " \
          "attachment" % (message_id_one_attachment, ))

    ### Regular and operational data requests and the relevant checks

    print("\n---- Sending an X-Road request with one attachment to the " \
          "service that will respond with three attachments ----\n")

    request_contents = common.format_xroad_request_template(
            xroad_request_attachments_template_filename, message_id_one_attachment)

    response = common.post_multipart_request(
        client_security_server_address, request_contents,
        attachment_count=1, get_raw_stream=True)

    # Expecting a multipart response with attachments.
    mime_parts, raw_response = common.parse_multipart_response(response)

    print("Received the following X-Road response: \n")
    print(raw_response.decode("utf-8"))

    if not mime_parts:
        common.parse_and_check_soap_response(raw_response)

    message_id_five_attachments = common.generate_message_id()
    print("\nGenerated message ID %s for X-Road request with five " \
          "attachments" % (message_id_five_attachments, ))

    print("\n---- Sending an X-Road request with five attachments to the " \
          "client's security server ----\n")

    request_contents = common.format_xroad_request_template(
            xroad_request_template_filename, message_id_five_attachments)

    # Expecting a simple SOAP response.
    response = common.post_multipart_request(
            client_security_server_address, request_contents, attachment_count=5)

    print("Received the following X-Road response: \n")
    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    common.wait_for_operational_data()

    client_timestamp_after_request = common.get_remote_timestamp(
            client_security_server_address, ssh_user)
    producer_timestamp_after_request = common.get_remote_timestamp(
            producer_security_server_address, ssh_user)

    # Now make operational data requests to both security servers and check the
    # response payloads.

    print("\n---- Sending an operational data request to the client's security server ----\n")

    message_id = common.generate_message_id()
    print("Generated message ID %s for query data request" % (message_id, ))
 
    request_contents = common.format_query_operational_data_request_template(
            query_data_client_template_filename, message_id,
            client_timestamp_before_requests, client_timestamp_after_request)

    print("Generated the following query data request for the client's security server: \n")
    print(request_contents)

    response = common.post_xml_request(
            client_security_server_address, request_contents,
            get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.

        # The record describing the query with one attachment
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_one_attachment_query_rec(
                    message_id_one_attachment, "Client"))

        # The record describing the query with five attachments
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_five_attachments_query_rec(
                    message_id_five_attachments, "Client"))

        # As operational data is queried by regular client, the field
        # 'securityServerInternalIp' is not expected to be included 
        # in the response payload.
        common.assert_missing_in_json(json_payload, "securityServerInternalIp")

        # Check if the timestamps in the response are in the expected range.
        common.assert_expected_timestamp_values(
                json_payload, client_timestamp_before_requests, client_timestamp_after_request)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)

    print("\n---- Sending an operational data request to the producer's " \
                "security server ----\n")

    message_id = common.generate_message_id()
    print("\nGenerated message ID %s for query data request" % (message_id, ))

    request_contents = common.format_query_operational_data_request_template(
            query_data_producer_template_filename, message_id,
            producer_timestamp_before_requests, producer_timestamp_after_request)
    print("Generated the following query data request for the producer's " \
            "security server: \n")
    print(request_contents)

    response = common.post_xml_request(
            producer_security_server_address, request_contents,
            get_raw_stream=True)
    mime_parts, raw_response = common.parse_multipart_response(response)

    if mime_parts:
        soap_part, record_count = common.get_multipart_soap_and_record_count(mime_parts[0])
        common.print_multipart_soap_and_record_count(soap_part, record_count, is_client=False)

        json_payload = common.get_multipart_json_payload(mime_parts[1])

        # Check the presence of all the required fields in at least one JSON structure.

        # The record describing the query with one attachment
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_one_attachment_query_rec(
                    message_id_one_attachment, "Producer"))

        # The record describing the query with five attachments
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_five_attachments_query_rec(
                    message_id_five_attachments, "Producer"))
        # As operational data is queried by regular client, the field
        # 'securityServerInternalIp' is not expected to be included 
        # in the response payload.
        common.assert_missing_in_json(json_payload, "securityServerInternalIp")

        # Check if the timestamps in the response are in the expected range.
        common.assert_expected_timestamp_values(
                json_payload,
                producer_timestamp_before_requests, producer_timestamp_after_request)

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)