def _query_operational_data(
        request_template_filename, security_server_address,
        timestamp_before_requests, timestamp_after_requests, expected_message_ids,
        is_client=True):
    # Start with the initial timestamp we obtained before sending the regular requests.
    next_records_from = timestamp_before_requests
    found_message_ids = set()

    while next_records_from is not None:
        # Send one request per second. This means we should get all the records by
        # the end of this loop for sure even with 
        # records-available-timestamp-offset-seconds set to several seconds.
        time.sleep(1)

        print("\nUsing recordsFrom with the value ", next_records_from)
        message_id = common.generate_message_id()

        request_contents = common.format_query_operational_data_request_template(
                request_template_filename, message_id,
                next_records_from, timestamp_after_requests)
        print("Generated the following operational data request: \n")
        print(request_contents)

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

        if not mime_parts:
           common.parse_and_check_soap_response(raw_response)
           raise Exception("Expected a multipart response, received a plain SOAP response")

        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=is_client)

        json_payload = common.get_multipart_json_payload(mime_parts[1])
        records = json_payload.get("records")
        for record in records:
            rec_message_id = record.get("messageId")
            found_message_ids.add(rec_message_id)
            if rec_message_id and rec_message_id in expected_message_ids:
                # One of the messages has been found, remove it from the list of expected
                # ID-s. Note that some of the records received match the operational data
                # requests we are sending so we might not find matching ID-s in each
                # response.
                print("Found operational data matching message ID", rec_message_id)
                expected_message_ids.remove(rec_message_id)

        if not expected_message_ids:
            # We have received all the data we expected.
            print("Received all the expected records")
            break

        next_records_from = _get_next_records_from(soap_part)

    if expected_message_ids:
        raise Exception(
                "Operational data about some of the requests sent, was not received " \
                        "(remaining message ID-s: %s)" % (", ".join(expected_message_ids)))
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):
    xroad_request_template_filename = os.path.join(
            request_template_dir, "simple_xroad_query_template.xml")
    query_data_client_template_filename = os.path.join(
            request_template_dir, "query_operational_data_client_template.xml")
    query_data_producer_template_filename = os.path.join(
            request_template_dir, "query_operational_data_producer_template.xml")

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

    ### Repeat a regular X-Road request with a different message ID.

    print("\n---- Sending regular X-Road requests to the client's security server ----\n")
    for _ in range(30):
        message_id = common.generate_message_id()
        xroad_message_ids.append(message_id)

        print("Sending a request with message ID %s" % (message_id, ))
        request_contents = common.format_xroad_request_template(
                xroad_request_template_filename, message_id)
        response = common.post_xml_request(
            client_security_server_address, request_contents)

        common.check_soap_fault(minidom.parseString(response.text))

        time.sleep(1)

    common.wait_for_operational_data()

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

    ### Make operational data requests until all the records have been received or
    ### no more are offered.

    print("\n---- Sending operational data requests to the client ----\n")
    _query_operational_data(
            query_data_client_template_filename, client_security_server_address,
            client_timestamp_before_requests, client_timestamp_after_requests,
            copy.deepcopy(xroad_message_ids))

    print("\n---- Sending operational data requests to the producer ----\n")
    _query_operational_data(
            query_data_producer_template_filename, producer_security_server_address,
            producer_timestamp_before_requests, producer_timestamp_after_requests,
            copy.deepcopy(xroad_message_ids), is_client=False)
Esempio n. 3
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)
Esempio n. 4
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")
    listmethods_query_template_filename = os.path.join(
        request_template_dir, "listmethods_client_query_template.xml")
    soap_fault_query_template_filename = os.path.join(
        request_template_dir, "soap_fault_query_template.xml")

    query_data_client_template_filename = os.path.join(
        request_template_dir, "query_health_data_client_template.xml")
    query_data_producer_template_filename = os.path.join(
        request_template_dir, "query_health_data_producer_template.xml")
    query_data_invalid_client_template_filename = os.path.join(
        request_template_dir, "query_health_data_invalid_client_template.xml")
    query_data_unknown_client_template_filename = os.path.join(
        request_template_dir, "query_health_data_unknown_client_template.xml")
    query_data_without_client_template_filename = os.path.join(
        request_template_dir, "query_health_data_without_client.xml")

    producer_health_data_request = None
    client_health_data_request = None

    producer_initial_timestamp = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)
    producer_opmonitor_restart_timestamp = common.get_opmonitor_restart_timestamp(
        producer_security_server_address, ssh_user)
    client_opmonitor_restart_timestamp = common.get_opmonitor_restart_timestamp(
        client_security_server_address, ssh_user)

    ### First, send a regular X-Road request.

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

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

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)
    print("Received the following X-Road response: \n")

    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    common.wait_for_operational_data()

    ### Make a health check request to the producer.

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

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

    request_contents = common.format_query_health_data_request_template(
        query_data_producer_template_filename, message_id)
    producer_health_data_request = request_contents

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

    response = common.post_xml_request(producer_security_server_address,
                                       request_contents)

    xml = common.parse_and_clean_xml(response.text)
    print("Received the following health data response:\n")
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    _assert_monitoring_daemon_start_timestamp_in_range(
        response, producer_opmonitor_restart_timestamp)
    _assert_stats_period(response, STATISTICS_PERIOD_SECONDS)

    print("Looking for the xroadGetRandom service in the response")

    event_data = _find_health_data_events_for_service(response,
                                                      GET_RANDOM_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about xroadGetRandom was not found in the response")

    _assert_last_successful_event_timestamp_in_range(
        event_data, producer_initial_timestamp)
    _assert_successful_events_count(event_data, 1)
    _assert_unsuccessful_events_count(event_data, 0)

    _assert_xml_tags_present(event_data,
                             SAMPLE_PRODUCER_GET_RANDOM_STATS.keys())

    _assert_xml_tags_match_values(event_data, PREDICTABLE_FIELDS,
                                  SAMPLE_PRODUCER_GET_RANDOM_STATS)

    ### Send a listMethods request to the client.

    listmethods_message_id = common.generate_message_id()
    print(
        "\nGenerated message ID %s for the listMethods request to the client" %
        (listmethods_message_id, ))

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

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

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

    if mime_parts:
        soap_part = common.get_multipart_soap(mime_parts[0])
        common.print_multipart_soap(soap_part)

    else:
        common.parse_and_check_soap_response(raw_response)

    common.wait_for_operational_data()

    ### Send a health data request to the client.

    client_pre_health_data_timestamp = common.get_remote_timestamp(
        client_security_server_address, ssh_user)

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

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

    request_contents = common.format_query_health_data_request_template(
        query_data_client_template_filename, message_id)
    client_health_data_request = request_contents

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    xml = common.parse_and_clean_xml(response.text)
    print("Received the following health data response:\n")
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    _assert_monitoring_daemon_start_timestamp_in_range(
        response, client_opmonitor_restart_timestamp)
    _assert_stats_period(response, STATISTICS_PERIOD_SECONDS)

    print("Looking for the listMethods service in the response")

    event_data = _find_health_data_events_for_service(response,
                                                      LISTMETHODS_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about listMethods was not found in the response")

    _assert_last_successful_event_timestamp_in_range(
        event_data, client_pre_health_data_timestamp)
    _assert_successful_events_count(event_data, 1)
    _assert_unsuccessful_events_count(event_data, 0)

    _assert_xml_tags_present(event_data,
                             SAMPLE_CLIENT_LISTMETHODS_STATS.keys())

    _assert_xml_tags_match_values(event_data, PREDICTABLE_FIELDS,
                                  SAMPLE_CLIENT_LISTMETHODS_STATS)

    ### Send a health data request to the client, using an invalid client ID in the
    ### query criteria.

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

    print("\n---- Sending a health data request to the client's " \
            "security server, using an invalid client in the filter criteria ----\n")

    request_contents = common.format_query_health_data_request_template(
        query_data_invalid_client_template_filename, message_id)

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    xml = common.parse_and_clean_xml(response.text)
    print("Received the following health data response:\n")
    print(xml.toprettyxml())

    # Using an invalid client ID must result in a SOAP fault.
    common.assert_soap_fault(xml)

    ### Send an unfiltered health data request to the client, using the producer
    ### as the service provider.

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

    print("\n---- Sending an unfiltered health data request to the client's " \
            "security server, using the producer as the service provider ----\n")

    request_contents = common.format_query_health_data_request_template(
        query_data_without_client_template_filename, message_id)

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

    xml = common.parse_and_clean_xml(response.text)
    print("Received the following health data response:\n")
    print(xml.toprettyxml())

    # This response must contain several serviceEvents elements (for all the
    # requests that were made to the producer above, including the initial health
    # data request).
    _assert_service_events_min_count(response, 2)

    event_data = _find_health_data_events_for_service(response,
                                                      GET_RANDOM_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about xroadGetRandom was not found in the response")

    event_data = _find_health_data_events_for_service(
        response, GET_HEALTH_DATA_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about getSecurityServerHealthData was not found in the response"
        )

    ### Send a request using an unknown client ID in the filter. Expect an empty response
    ### is returned.

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

    print("\n---- Sending a health data request with an unknown client ID to the client's " \
            "security server ----\n")

    request_contents = common.format_query_health_data_request_template(
        query_data_unknown_client_template_filename, message_id)

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)
    xml = common.parse_and_clean_xml(response.text)
    print("Received the following health data response:\n")
    print(xml.toprettyxml())

    common.check_soap_fault(xml)
    _assert_no_events(response)

    ### Sleep and expect that the health data will be reset.

    print("Waiting for the health metrics to be reset\n")
    time.sleep(STATISTICS_PERIOD_SECONDS)

    ### Repeat the health data requests and check if the health data has been reset.

    print("Repeating the health data request to the producer\n")
    response = common.post_xml_request(producer_security_server_address,
                                       producer_health_data_request)

    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    _assert_monitoring_daemon_start_timestamp_in_range(
        response, producer_opmonitor_restart_timestamp)
    _assert_stats_period(response, STATISTICS_PERIOD_SECONDS)

    event_data = _find_health_data_events_for_service(response,
                                                      GET_RANDOM_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about xroadGetRandom was not found in the response")

    _assert_successful_events_count(event_data, 0)
    _assert_unsuccessful_events_count(event_data, 0)
    _assert_xml_tags_missing(event_data, STATISTICS_FIELDS)

    print("Repeating the health data request to the client\n")
    response = common.post_xml_request(client_security_server_address,
                                       client_health_data_request)

    xml = common.parse_and_clean_xml(response.text)
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    _assert_monitoring_daemon_start_timestamp_in_range(
        response, client_opmonitor_restart_timestamp)
    _assert_stats_period(response, STATISTICS_PERIOD_SECONDS)

    event_data = _find_health_data_events_for_service(response,
                                                      LISTMETHODS_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about listMethods was not found in the response")

    _assert_successful_events_count(event_data, 0)
    _assert_unsuccessful_events_count(event_data, 0)
    _assert_xml_tags_missing(event_data, STATISTICS_FIELDS)

    ### Now make an unusuccessful request and check the relevant health data.

    producer_pre_unsuccessful_timestamp = common.get_remote_timestamp(
        producer_security_server_address, ssh_user)

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

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

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

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

    common.assert_soap_fault(xml)

    common.wait_for_operational_data()

    # Send a health check request to the producer.

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

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

    request_contents = common.format_query_health_data_request_template(
        query_data_producer_template_filename, message_id)

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

    response = common.post_xml_request(producer_security_server_address,
                                       request_contents)

    xml = common.parse_and_clean_xml(response.text)
    print("Received the following health data response:\n")
    print(xml.toprettyxml())

    common.check_soap_fault(xml)

    # The service is xRoadGetRandom but the result was a fault.
    print("Looking for the xroadGetRandom service in the response")

    event_data = _find_health_data_events_for_service(response,
                                                      GET_RANDOM_SERVICE_XML)
    if event_data is None:
        raise Exception(
            "Health data about xroadGetRandom was not found in the response")

    _assert_successful_events_count(event_data, 0)
    _assert_unsuccessful_events_count(event_data, 1)
    _assert_last_unsuccessful_event_timestamp_in_range(
        event_data, producer_pre_unsuccessful_timestamp)
Esempio n. 5
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)
Esempio n. 6
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_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)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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, ))

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

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

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

    response = common.post_xml_request(client_security_server_address,
                                       request_contents)

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

    common.check_soap_fault(xml)

    common.wait_for_operational_data()

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

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

    print(
        "\n---- Sending an operational data request to the client's security server ----\n"
    )
    message_id = common.generate_message_id()
    print("Generated message ID %s for query data request" % (message_id, ))

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

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

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

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

        # op-monitor-buffer.size=0 must result in an empty response
        common.check_record_count(record_count, 0)

    else:
        common.parse_and_check_soap_response(raw_response)

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

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

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

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

        # op-monitor-buffer.size=0 must result in an empty response
        common.check_record_count(record_count, 0)

    else:
        common.parse_and_check_soap_response(raw_response)
Esempio n. 10
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_template.xml")
    query_data_client_missing_recordsfrom_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_client_missing_recordsfrom_template.xml")
    query_data_client_missing_recordsto_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_client_missing_recordsto_template.xml")
    query_data_client_empty_search_criteria_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_client_empty_search_criteria_template.xml")
    query_data_client_missing_search_criteria_template_filename = os.path.join(
        request_template_dir,
        "query_operational_data_client_missing_search_criteria_template.xml")

    ### Operational data requests and the relevant checks

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request where 'recordsTo' is " \
            "earlier than 'recordsFrom' to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id, 1479823179,
        1479823175)
    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())

    # Earlier recordsTo than recordsFrom in operational monitoring request must
    # result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request where " \
            "'recordsFrom' is in the future to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id, 2479823179,
        2479823185)
    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())

    # recordsFrom >= (now - records-available-timestamp-offset-seconds) in operational
    # monitoring request must result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request without " \
            "'recordsFrom' element to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_missing_recordsfrom_template_filename, message_id,
        None, 1479823185)
    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())

    # Missing recordsFrom element in operational monitoring request must
    # result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request without " \
            "'recordsTo' element to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_missing_recordsto_template_filename, message_id,
        1479823185, None)
    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())

    # Missing recordsTo element in operational monitoring request must
    # result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request without 'recordsFrom'" \
            " and 'recordsTo' elements to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_empty_search_criteria_template_filename, message_id,
        None, None)
    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())

    # Missing recordsFrom and recordsTo elements in operational monitoring
    # request must result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request without 'searchCriteria'" \
            " element to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_missing_search_criteria_template_filename,
        message_id, None, None)
    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())

    # Missing searchCriteria element in operational monitoring
    # request must result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request with non-numeric 'recordsFrom'" \
            " value to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id, "abc", 1479823185)
    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())

    # Non-numeric recordsFrom value in operational monitoring request must
    # result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request with too large 'recordsTo'" \
             " value to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id, 1479823185,
        888888888888888888888)
    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())

    # Too large recordsTo value in operational monitoring request must
    # result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    print("\n---- Sending an operational data request with negative 'recordsFrom'" \
             " and 'recordsTo' values to the client's security server ----\n")

    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id, -1479823185,
        -1479823183)
    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())

    # Negative recordsFrom and recordsTo values in operational monitoring
    # request must result in a SOAP fault
    common.assert_soap_fault(xml)

    message_id = common.generate_message_id()
    timestamp_before_request = common.get_remote_timestamp(
        client_security_server_address, ssh_user)
    print("\n---- Sending an operational data request where " \
            "'recordsTo' is in the future to the client's security server ----\n")

    # Let's craft a request where recordsFrom is in the past
    # and recordsTo is in the future
    request_contents = common.format_query_operational_data_request_template(
        query_data_client_template_filename, message_id,
        timestamp_before_request - 5, timestamp_before_request + 10)
    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)
        # In case 'recordsTo' value is in the future, the element
        # 'nextRecordsFrom' is expected in operational
        # monitoring response. 'nextRecordsFrom' value is expected to be
        # (now - records-available-timestamp-offset-seconds).
        # records-available-timestamp-offset-seconds value is expected to be set to 0
        # before the test in run_tests.py.
        common.assert_get_next_records_from_in_range(soap_part,
                                                     timestamp_before_request)

    else:
        common.parse_and_check_soap_response(raw_response)
Esempio n. 11
0
def run(client_security_server_address, producer_security_server_address,
        ssh_user, request_template_dir):
    xroad_query_to_ss0_service_template_filename = os.path.join(
            request_template_dir, "xroad_query_to_ss0_service_template.xml")
    xroad_query_to_ss2_service_template_filename = os.path.join(
            request_template_dir, "xroad_query_to_ss2_service_template.xml")
    query_data_client_template_filename = os.path.join(
            request_template_dir, "query_operational_data_client_template.xml")

    client_timestamp_before_requests = common.get_remote_timestamp(
            client_security_server_address, ssh_user)

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

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

    print("\n---- Sending an X-Road request to the service provider in " \
          "security server 00000000_1 ----\n")

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

    response = common.post_xml_request(
            client_security_server_address, request_contents)

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

    common.check_soap_fault(xml)

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

    print("\n---- Sending an X-Road request to the service provider in " \
          "security server 00000002_1 ----\n")

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

    response = common.post_xml_request(
            client_security_server_address, request_contents)

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

    common.check_soap_fault(xml)

    common.wait_for_operational_data()

    client_timestamp_after_requests = common.get_remote_timestamp(
            client_security_server_address, ssh_user)

    # Now make an operational data request to the client's security server 
    # and check the response payload.

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

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

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

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

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

        json_payload = common.get_multipart_json_payload(mime_parts[1])

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

        # The record describing the X-Road request to service provider in 
        # security server 00000000_1
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_cluster_query_rec(
                    message_id_ss0, "xtee8.ci.kit"))

        # The record describing the X-Road request to service provider in 
        # security server 00000002_1
        common.assert_present_in_json(
                json_payload, _expected_keys_and_values_of_cluster_query_rec(
                    message_id_ss2, "xtee10.ci.kit"))

        common.print_multipart_query_data_response(json_payload)

    else:
        common.parse_and_check_soap_response(raw_response)