Commit 1b9c107c authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed on simulated adapter TC

parent 1cfe3321
Loading
Loading
Loading
Loading
+37 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,43 @@ namespace LibCise__Functions {
    return 0;
    return 0;
  }
  }


  BITSTRING fx__enc__PullResponse__1(const http__www__cise__eu__servicemodel__v1__message::PullResponse& p) { // FIXME Use enc/dec TITAN function external function f_enc_value(in Value x) return bitstring with { extension "prototype(convert) encode(abc)" }
    loggers::get_instance().log(">>> fx__enc__PullResponse");

    LibHttp__XmlMessageBodyTypes::XmlBody msg;
    msg.msg().pull__response() = p;
    msg.raw().set_to_omit();
    xml_codec c;
    OCTETSTRING os;
    int result = c.encode(msg, os);
    loggers::get_instance().log_msg("fx__enc__PullResponse: os: ", os);

    // Remove XML header added by the XML codec.
    OCTETSTRING h = char2oct("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n");
    os = OCTETSTRING(os.lengthof() - h.lengthof(), static_cast<const unsigned char*>(os) + h.lengthof());
    loggers::get_instance().log_msg("fx__enc__PullResponse: os: ", os);

    return oct2bit(os);
  }

  INTEGER fx__dec__PullResponse__1(BITSTRING &b, http__www__cise__eu__servicemodel__v1__message::PullResponse& p) { // FIXME Use enc/dec TITAN function external function f_enc_value(in Value x) return bitstring with { extension "prototype(convert) encode(abc)" }
    loggers::get_instance().log(">>> fx__dec__PullResponse");

    LibHttp__XmlMessageBodyTypes::XmlBody msg;
    xml_codec c;
    OCTETSTRING is = bit2oct(b);
    params parms;
    parms["decode_str"] = std::string(static_cast<const unsigned char *>(is), is.lengthof() + static_cast<const unsigned char *>(is));
    if (c.decode(is, msg, &parms) == -1) {
      loggers::get_instance().warning("fx__dec__PullResponse: -1 result code was returned");
      return -1;
    }

    p = msg.msg().pull__response();

    return 0;
  }

  BITSTRING fx__enc__Feedback__1(const http__www__cise__eu__servicemodel__v1__message::Feedback& p) { // FIXME Use enc/dec TITAN function external function f_enc_value(in Value x) return bitstring with { extension "prototype(convert) encode(abc)" }
  BITSTRING fx__enc__Feedback__1(const http__www__cise__eu__servicemodel__v1__message::Feedback& p) { // FIXME Use enc/dec TITAN function external function f_enc_value(in Value x) return bitstring with { extension "prototype(convert) encode(abc)" }
    loggers::get_instance().log(">>> fx__enc__Feedback");
    loggers::get_instance().log(">>> fx__enc__Feedback");


+149 −0
Original line number Original line Diff line number Diff line
[MODULE_PARAMETERS]
# This section shall contain the values of all parameters that are defined in your TTCN-3 modules.

# IUT roles
LibCise_Pics.PICS_IUT_CDM_NODE_EI_NA := true
LibCise_Pics.PICS_IUT_CDM_NODE_EI_NN := false
LibCise_Pics.PICS_IUT_CDM_ADAPTOR    := false

LibCise_Pics.PICS_IUT_CDM_CISE_SIMU_EI_NA := true

# Communication messages
LibCise_Pics.PICS_CDM_PULL            := true
LibCise_Pics.PICS_CDM_PUSH            := true
LibCise_Pics.PICS_CDM_SUBSCRIBE       := true
LibCise_Pics.PICS_CDM_ACKNOWLEDGEMENT := true
LibCise_Pics.PICS_CDM_FEEDBACK        := true

# Services
LibCise_Pics.PICS_CDM_VESSEL_SERVICE                       := true
LibCise_Pics.PICS_CDM_ACTION_SERVICE                       := true
LibCise_Pics.PICS_CDM_ANOMALY_SERVICE                      := true
LibCise_Pics.PICS_CDM_CERTIFICATE_DOCUMENT_SERVICE         := true
LibCise_Pics.PICS_CDM_INCIDENT_SERVICE                     := true
LibCise_Pics.PICS_CDM_IRREGULAR_MIGRATION_INCIDENT_SERVICE := true
LibCise_Pics.PICS_CDM_LAW_INFRINGEMENT_INCIDENT_SERVICE    := true
LibCise_Pics.PICS_CDM_METEO_SERVICE                        := true
LibCise_Pics.PICS_CDM_ORGANIZATION_SERVICE                 := true
LibCise_Pics.PICS_CDM_RISK_SERVICE                         := true
LibCise_Pics.PICS_CDM_CARGO_SERVICE                        := true

# LibCise
LibCise_Pics.PICS_CISE_CERTIFICATES_DB_PATH           := "/home/y.garcia/dev/cise-data-model/keystore"
LibCise_Pics.PICS_CISE_TS_CERTIFICATE                 := "signing.de.cnit.test2.cer"
LibCise_Pics.PICS_CISE_TS_SIGNING_PRIVATE_KEY         := "signing.de.cnit.test2.privkey.pem"
LibCise_Pics.PICS_CISE_TS_CERTIFICATE_PAST            := "cise_expired.crt"
LibCise_Pics.PICS_CISE_TS_SIGNING_PRIVATE_KEY_PAST    := "cise_expired.key"
LibCise_Pics.PICS_CISE_TS_CERTIFICATE_FUTURE          := "cert_future.crt"
LibCise_Pics.PICS_CISE_TS_SIGNING_PRIVATE_KEY_FUTURE  := "cert_future.key"
LibCise_Pics.PICS_CISE_TS_SIGNING_PRIVATE_PASSWD      := ""
LibCise_Pics.PICS_HEADER_HOST_UT                      := "172.25.1.58" # Adaptor

# LibHttp
LibHttp_Pics.PICS_HEADER_HOST         := "10.50.1.122"
LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/xml"
LibHttp_Pics.PICS_USE_TOKEN_HEADER    := true
#LibHttp_Pics.PICS_TOKEN_HEADER       := "Basic WrongToken"

LibCise_Pics.PICS_CISE_PULL_REQUEST_URI := "messages" #"api/messages"
LibCise_Pics.PICS_PULL_RESPONSE_URI     := "messages"
LibCise_Pics.PICS_CISE_ADAPTOR_URI      := "/cise-adapter/api/v1/messages"

# LibCise test parameters
# Asynchronous Ack
LibCise_Pixits.PX_CISE_REQUEST_ACK := false
# Services
LibCise_Pixits.PX_CISE_SENDER_SERVICE_ID    := "de.cnit.test2.vessel.pull.consumer"
LibCise_Pixits.PX_CISE_RECIPIENT_SERVICE_ID := "de.cnit.test1.vessel.pull.provider"
# Discovery
LibCise_Pixits.PX_CISE_DISCOVERY_PROFILE_SERVICE_ID := "cx.simlsa3-nodecx.vessel.push.consumer"
LibCise_Pixits.PX_CISE_SEA_BASSIN                   := mediterranean
LibCise_Pixits.PX_DATA_FRESHNESS_TYPE               := unknown
# Vessel infornmation
LibCise_Pixits.PX_VESSEL_IMO_NUMBER    := 7710525
LibCise_Pixits.PX_VESSEL_POS_LATITUDE  := "43.561062"
LibCise_Pixits.PX_VESSEL_POS_LONGITUDE := "10.264149"
LibCise_Pixits.PX_VESSEL_TYPE          := fishingVessel
LibCise_Pixits.PX_COUNTRY_TYPE         := fR
LibCise_Pixits.PX_VESSEL_NET_TONNAGE   := 30000.0

# Organization
LibCise_Pixits.PX_ORGANIZATION_LEGAL_NAME := "A1"
LibCise_Pixits.PX_ORGANIZATION_UUID       := "787aa3e9b91b-5bc2-0cf5-80a8-183a716b8d59"
# Period
LibCise_Pixits.PX_PERIOD_START_DATE := "2024-02-01+01:00"
LibCise_Pixits.PX_PERIOD_END_DATE   := "2024-09-01+01:00"

# Incident
LibCise_Pixits.PX_IRREGULAR_MIGRATION_INCIDENT_TYPE := irregularBorderEntry
LibCise_Pixits.PX_LAW_INFRINGEMENT_INCIDENT_TYPE    := lawInfringementByVessels

[LOGGING]
# In this section you can specify the name of the log file and the classes of events
# you want to log into the file or display on console (standard error).

LogFile := "../logs/AtsCise/%e.%h-%r.%s"
FileMask := LOG_ALL | USER | DEBUG | MATCHING
ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING
#FileMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | PORTEVENT | TIMEROP | TESTCASE
#ConsoleMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | PORTEVENT | TIMEROP | TESTCASE
LogSourceInfo := Stack
LogEntityName:= Yes
LogEventTypes:= Yes
#TimeStampFormat := DateTime

[TESTPORT_PARAMETERS]
# In this section you can specify parameters that are passed to Test Ports.
# I1 interface
## Unsecured
system.httpPort.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server=10.50.1.25)"
system.httpPort_notif.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server_mode=1,local_port=8888)"
#### For multiple component 
CISEAdapter1.httpPort.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server=172.25.1.54,port=8200)"
CISEAdapter1.httpPort_notif.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server_mode=1,local_port=8310)"
CISEAdapter2.httpPort.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server=172.25.1.54,port=8200)"
CISEAdapter2.httpPort_notif.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server_mode=1,local_port=8311)"
## TLS
#system.httpPort.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server=172.25.1.54,port=443,use_ssl=1,trusted_ca_list=/home/y.garcia/var/ssl/archive/yanngarcia.ddns.net/fullchain1.pem,privkey=/home/y.garcia/var/ssl/archive/yanngarcia.ddns.net/privkey1.pem,certificate=/home/y.garcia/var/ssl/archive/yanngarcia.ddns.net/fullchain1.pem)"
#system.httpPort_notif.params := "HTTP(codecs=xml:xml_codec;json:json_codec)/TCP(debug=1,server_mode=1,local_port=443,use_ssl=1,mutual_auth=1,mutual_tls=1,trusted_ca_list=/home/y.garcia/var/ssl/archive/yanngarcia.ddns.net/fullchain1.pem,privkey=/home/y.garcia/var/ssl/archive/yanngarcia.ddns.net/privkey1.pem,certificate=/home/y.garcia/var/ssl/archive/yanngarcia.ddns.net/fullchain1.pem)"

[DEFINE]
# In this section you can create macro definitions,
# that can be used in other configuration file sections except [INCLUDE] and [ORDERED_INCLUDE].

[INCLUDE]
# To use configuration settings given in other configuration files,
# the configuration files just need to be listed in this section, with their full or relative pathnames.

[ORDERED_INCLUDE]
# To use configuration settings given in other configuration files,
# the configuration files just need to be listed in this section, with their full or relative pathnames.

[EXTERNAL_COMMANDS]
# This section can define external commands (shell scripts) to be executed by the ETS
# whenever a control part or test case is started or terminated.

#BeginTestCase := ""
#EndTestCase := ""
#BeginControlPart := ""
#EndControlPart := ""

[EXECUTE]
# In this section you can specify what parts of your test suite you want to execute.

# Simulate peer adapter of CISE node IUT
AtsCise_TestCases.TC_CDM_CISE_SIMU_EI_NA_PULL_BV_01

[GROUPS]
# In this section you can specify groups of hosts. These groups can be used inside the
# [COMPONENTS] section to restrict the creation of certain PTCs to a given set of hosts.

[COMPONENTS]
# This section consists of rules restricting the location of created PTCs.

[MAIN_CONTROLLER]
# The options herein control the behavior of MC.
KillTimer := 10.0
LocalAddress := 127.0.0.1
TCPPort := 12000
NumHCs := 1
+71 −21
Original line number Original line Diff line number Diff line
@@ -17811,6 +17811,10 @@ module AtsCise_TestCases {
        var charstring v_expected_date_time := substr(v_created_date_time, 0, lengthof(v_created_date_time) - 5);
        var charstring v_expected_date_time := substr(v_created_date_time, 0, lengthof(v_created_date_time) - 5);
        var charstring v_message_id := f_generate_uuid();
        var charstring v_message_id := f_generate_uuid();
        var charstring v_correlation_id := f_generate_uuid();
        var charstring v_correlation_id := f_generate_uuid();
        var PullResponse_1 v_pull_response;
        var octetstring v_pull_response_signed;
        var charstring v_pull_response_canonicalized;
        var charstring v_pull_response_signed_str;
        var integer v_result;
        var integer v_result;
        // Test control
        // Test control
@@ -17862,29 +17866,55 @@ module AtsCise_TestCases {
            // Message processing
            // Message processing
            f_sleep(PX_MESSAGE_PROCESSING_INTERVAL);
            f_sleep(PX_MESSAGE_PROCESSING_INTERVAL);
            var XmlEntityPayload v_payload;
            if (ischosen(v_request.request.body.xml_body.msg.pull_request)) {
              v_payload := valueof(
                                   m_entity_payload_vessel(
                                                           -, -, -,-, -, -, -,
                                                           m_vessel(
                                                                    v_request.request.body.xml_body.msg.pull_request.payload.xmlEntityPayload.vessel.iMONumber // TODO Add more info
                                   )));
            }
            // Send PullResponse
            // Send PullResponse
            f_init_default_headers_list(-, -, v_headers);
            f_init_default_headers_list(-, -, v_headers);
            httpPort_notif.send(
            v_pull_response := valueof(
                                m_http_request(
                                               m_http_request_post(
                                                                   "/messages?messageId=" & v_message_id,
                                                                   v_headers,
                                                                   m_http_message_body_xml(
                                                                                           m_xml_body_pull_response(
                                       m_pull_response(
                                       m_pull_response(
                                                       v_created_date_time,
                                                       v_created_date_time,
                                                       v_message_id,
                                                       v_message_id,
                                                       v_request.request.body.xml_body.msg.pull_request.priority,
                                                       v_request.request.body.xml_body.msg.pull_request.priority,
                                                                                                                                   v_request.request.body.xml_body.msg.pull_request.sender_,
                                                       v_request.request.body.xml_body.msg.pull_request.recipient,
                                                       {},
                                                       {},
                                                       success,
                                                       success,
                                                       -,
                                                       -,
                                                       -,
                                                       -,
                                                       v_request.request.body.xml_body.msg.pull_request.contextID,
                                                       v_request.request.body.xml_body.msg.pull_request.contextID,
                                                       v_request.request.body.xml_body.msg.pull_request.correlationID,
                                                       v_request.request.body.xml_body.msg.pull_request.correlationID,
                                                                                                                                   false
                                                       false,
                                ))))));
                                                       v_request.request.body.xml_body.msg.pull_request.sender_,
                                                       m_core_entity_payload_derivations_payload(
                                                                                                 v_payload
                                       )));
            v_result := f_sign_pull_response(v_pull_response, PX_SECURITY_SIGN_HASH_ALG, PICS_CISE_TS_CERTIFICATE, PICS_CISE_TS_SIGNING_PRIVATE_KEY, PICS_CISE_TS_SIGNING_PRIVATE_PASSWD, v_pull_response_signed, v_pull_response_canonicalized);
            if (v_result != 0) {
              log("*** " & testcasename() & ": ERROR: Signature processing failed ***");
              tc_wait.start;
              repeat;
            }
            v_pull_response_signed_str := oct2char(v_pull_response_signed);
            log("v_pull_response_signed_str: ", v_pull_response_signed_str);
            httpPort.send(
                          m_http_request(
                                         m_http_request_post(
                                                             "/messages?messageId=" & v_message_id,
                                                             v_headers,
                                                             m_http_message_body_xml(
                                                                                     m_xml_body_pull_response( // As the message was signed, we need to send as raw XML to prevent codec call
                                                                                                              v_pull_response,
                                                                                                              v_pull_response_signed_str // If raw is specified, the codec does not encode the message
                          )))));
            log("*** " & testcasename() & ": INFO: Sent PullResponse to the IUT ***");
            log("*** " & testcasename() & ": INFO: Sent PullResponse to the IUT ***");
            tc_wait.start;
            tc_wait.start;
@@ -17900,11 +17930,31 @@ module AtsCise_TestCases {
                                                                                                                                                 success
                                                                                                                                                 success
                                    )))))) {
                                    )))))) {
            tc_wait.start;
            tc_wait.start;
            log("*** " & testcasename() & ": INFO: Received PullResponse 200 OK Ack from IUT ***");
            repeat;
          }
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ok(
                                                                   mw_http_message_body_xml(
                                                                                             mw_xml_body_acknowledgement(
                                                                                                                         mw_acknowledgement(
                                                                                                                                           -, -, -, -, 
                                                                                                                                           success
                              )))))) {
            tc_wait.start;
            log("*** " & testcasename() & ": INFO: Received PullResponse 202 Accepted Ack from IUT ***");
            repeat;
          }
          [] httpPort.receive {
            tc_wait.stop;
            log("*** " & testcasename() & ": DNG: Unexpected message received on httpPort ***");
            tc_wait.start;
            repeat;
            repeat;
          }
          }
          [] httpPort_notif.receive {
          [] httpPort_notif.receive {
            tc_wait.stop;
            tc_wait.stop;
            log("*** " & testcasename() & ": DNG: Unexpected message received ***");
            log("*** " & testcasename() & ": DNG: Unexpected message received on httpPort_notif ***");
            tc_wait.start;
            tc_wait.start;
            repeat;
            repeat;
          }
          }
+50 −0
Original line number Original line Diff line number Diff line
@@ -40,6 +40,10 @@ module LibCise_Functions {


    external function fx_dec_PullRequest_1(inout bitstring b, out PullRequest p) return integer with {extension "prototype(sliding) decode(XML)"};
    external function fx_dec_PullRequest_1(inout bitstring b, out PullRequest p) return integer with {extension "prototype(sliding) decode(XML)"};


    external function fx_enc_PullResponse_1(in PullResponse_1 p) return bitstring with {extension "prototype(convert) encode(XML)"};

    external function fx_dec_PullResponse_1(inout bitstring b, out PullResponse p) return integer with {extension "prototype(sliding) decode(XML)"};

    external function fx_enc_Feedback_1(in Feedback_1 p) return bitstring with {extension "prototype(convert) encode(XML)"};
    external function fx_enc_Feedback_1(in Feedback_1 p) return bitstring with {extension "prototype(convert) encode(XML)"};


    external function fx_dec_Feedback_1(inout bitstring b, out Feedback p) return integer with {extension "prototype(sliding) decode(XML)"};
    external function fx_dec_Feedback_1(inout bitstring b, out Feedback p) return integer with {extension "prototype(sliding) decode(XML)"};
@@ -846,6 +850,52 @@ module LibCise_Functions {
      return 0;
      return 0;
    } // End of function f_sign_pull_request
    } // End of function f_sign_pull_request


    function f_sign_pull_response(
                                  in PullResponse_1 p_pull_response,
                                  in HashAlgorithm p_hash_algorithm,
                                  in charstring p_certificate_name,
                                  in charstring p_private_key_name,
                                  in charstring p_private_key_passwd,
                                  out octetstring p_signed_pull_response,
                                  out charstring p_pull_response_canonicalized
                                  ) return integer {
      var octetstring v_encoded_pull_response;
      var octetstring v_empty_signature;
      var octetstring v_digest;
      var octetstring v_signature;
      var charstring v_x509_certificate_subject;
      var charstring v_x509_certificate_pem;
      var octetstring v_h := char2oct("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n");

      // Encode the pull response
      v_encoded_pull_response := bit2oct(encvalue(p_pull_response));
      log("f_sign_pull_response: v_encoded_pull_response: ", v_encoded_pull_response);

      // Encode empty signature
      log("f_sign_pull_response: m_to_be_signed: ", m_to_be_signed);
      v_empty_signature := bit2oct(encvalue(valueof(m_to_be_signed)));
      log("f_sign_pull_response: Empty signature: ", v_empty_signature);

      // Sign the XML document (envelopped signature)
      if (f_sign(v_encoded_pull_response, v_empty_signature, p_certificate_name, p_private_key_name, p_private_key_passwd, v_signature, v_digest, v_x509_certificate_subject, v_x509_certificate_pem, p_pull_response_canonicalized) == -1) {
        log("f_sign_pull_response: failed to sign PullResponse");
        return -1;
      }
      log("f_sign_pull_response: Signature: ", v_signature);

      // Create the XML envelopped signature
      if (f_xml_build_envolopped_signature(v_encoded_pull_response, v_signature, v_digest, v_x509_certificate_subject, "<ResultCode", v_x509_certificate_pem, p_signed_pull_response) == -1) {
        log("f_sign_pull_response: failed to sign PullResponse");
        return -1;
      }
      log("f_sign_pull_response: p_signed_pull_response: ", p_signed_pull_response);

      // Add XML header, not part of the sugnature
      p_signed_pull_response := v_h & p_signed_pull_response;

      return 0;
    } // End of function f_sign_pull_response

    function f_sign_feedback(
    function f_sign_feedback(
                             in Feedback_1 p_feedback,
                             in Feedback_1 p_feedback,
                             in HashAlgorithm p_hash_algorithm,
                             in HashAlgorithm p_hash_algorithm,
+3 −2
Original line number Original line Diff line number Diff line
@@ -163,10 +163,11 @@ module LibHttp_XmlTemplates {
  group pull_response {
  group pull_response {


    template (value) XmlBody m_xml_body_pull_response(
    template (value) XmlBody m_xml_body_pull_response(
                                                     in template (value) PullResponse p_pull_response
                                                     in template (value) PullResponse p_pull_response,
                                                     in template (omit) charstring p_raw := omit
    ) := {
    ) := {
      msg := { pull_response := p_pull_response },
      msg := { pull_response := p_pull_response },
      raw := omit
      raw := p_raw
    } // End of template m_xml_body_pull_response
    } // End of template m_xml_body_pull_response


    template (present) XmlBody mw_xml_body_pull_response(
    template (present) XmlBody mw_xml_body_pull_response(