laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/42438?usp=email )
Change subject: s1gw: f_REST_*(): use tr_HTTP_RespBody(decmatch T:?) ......................................................................
s1gw: f_REST_*(): use tr_HTTP_RespBody(decmatch T:?)
Pass `exp := tr_HTTP_RespBody(decmatch T:?)` to f_http_transact() in every REST helper that decodes the response body. This ensures both a 2xx status code and a decodable body are required before any decode attempt is made, producing an informative "Unexpected HTTP response" verdict (rather than a confusing DTE) when e.g. an older osmo-s1gw returns HTTP 404 with an empty body for an unsupported endpoint.
Change-Id: I6997dae5314d4a4588386183832426ab5b8d0843 --- M library/HTTP_Adapter.ttcn M s1gw/S1GW_REST_Functions.ttcn 2 files changed, 32 insertions(+), 12 deletions(-)
Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved
diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn index bd34a5f..2b2e2b7 100644 --- a/library/HTTP_Adapter.ttcn +++ b/library/HTTP_Adapter.ttcn @@ -181,6 +181,14 @@
template (present) HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299));
+template (present) HTTPMessage +tr_HTTP_RespBody(template (present) charstring body := ?) +modifies tr_HTTP_Resp2xx := { + response := { + body := body + } +}; + function f_http_tx_request(charstring url, charstring method := "GET", template (omit) charstring body := omit, template (omit) octetstring binary_body := omit, diff --git a/s1gw/S1GW_REST_Functions.ttcn b/s1gw/S1GW_REST_Functions.ttcn index 454d77e..6f4b42b 100644 --- a/s1gw/S1GW_REST_Functions.ttcn +++ b/s1gw/S1GW_REST_Functions.ttcn @@ -21,42 +21,48 @@ function f_REST_MetricsList(charstring metric_type := "all", charstring path := "") runs on http_CT return MetricsList { - var HTTPMessage rsp := f_http_transact("/metrics-list?type=" & metric_type & "&path=" & path); + var HTTPMessage rsp := f_http_transact("/metrics-list?type=" & metric_type & "&path=" & path, + exp := tr_HTTP_RespBody(decmatch MetricsList:?)); return dec_MetricsList(char2oct(rsp.response.body)); }
/* Get the PFCP association state */ function f_REST_PfcpAssocState() runs on http_CT return PfcpAssocInfo { - var HTTPMessage rsp := f_http_transact("/pfcp/assoc", method := "GET"); + var HTTPMessage rsp := f_http_transact("/pfcp/assoc", method := "GET", + exp := tr_HTTP_RespBody(decmatch PfcpAssocInfo:?)); return dec_PfcpAssocInfo(char2oct(rsp.response.body)); }
/* Initiate the PFCP Association Setup procedure */ function f_REST_PfcpAssocSetup() runs on http_CT return OperationResult { - var HTTPMessage rsp := f_http_transact("/pfcp/assoc", method := "POST"); + var HTTPMessage rsp := f_http_transact("/pfcp/assoc", method := "POST", + exp := tr_HTTP_RespBody(decmatch OperationResult:?)); return dec_OperationResult(char2oct(rsp.response.body)); }
/* Initiate the PFCP Association Release procedure */ function f_REST_PfcpAssocRelease() runs on http_CT return OperationResult { - var HTTPMessage rsp := f_http_transact("/pfcp/assoc", method := "DELETE"); + var HTTPMessage rsp := f_http_transact("/pfcp/assoc", method := "DELETE", + exp := tr_HTTP_RespBody(decmatch OperationResult:?)); return dec_OperationResult(char2oct(rsp.response.body)); }
/* Send a PFCP Heartbeat Request to the peer */ function f_REST_PfcpHeartbeat() runs on http_CT return OperationResult { - var HTTPMessage rsp := f_http_transact("/pfcp/heartbeat", method := "POST"); + var HTTPMessage rsp := f_http_transact("/pfcp/heartbeat", method := "POST", + exp := tr_HTTP_RespBody(decmatch OperationResult:?)); return dec_OperationResult(char2oct(rsp.response.body)); }
/* Get a list of MMEs in the pool */ function f_REST_MmeList() runs on http_CT return MmeList { - var HTTPMessage rsp := f_http_transact("/mme-list", method := "GET"); + var HTTPMessage rsp := f_http_transact("/mme-list", method := "GET", + exp := tr_HTTP_RespBody(decmatch MmeList:?)); return dec_MmeList(char2oct(rsp.response.body)); }
@@ -72,7 +78,8 @@ function f_REST_MmeInfo(ParamMmeId mme_id) runs on http_CT return MmeItem { var charstring p_mme_id := enc_ParamMmeId(mme_id); - var HTTPMessage rsp := f_http_transact("/mme/" & p_mme_id, method := "GET"); + var HTTPMessage rsp := f_http_transact("/mme/" & p_mme_id, method := "GET", + exp := tr_HTTP_RespBody(decmatch MmeItem:?)); return dec_MmeItem(char2oct(rsp.response.body)); }
@@ -87,7 +94,8 @@ /* Get a list of eNB connections */ function f_REST_EnbList() runs on http_CT return EnbList { - var HTTPMessage rsp := f_http_transact("/enb-list", method := "GET"); + var HTTPMessage rsp := f_http_transact("/enb-list", method := "GET", + exp := tr_HTTP_RespBody(decmatch EnbList:?)); return dec_EnbList(char2oct(rsp.response.body)); }
@@ -95,7 +103,8 @@ function f_REST_EnbInfo(ParamEnbId enb_id) runs on http_CT return EnbItem { var charstring p_enb_id := enc_ParamEnbId(enb_id); - var HTTPMessage rsp := f_http_transact("/enb/" & p_enb_id, method := "GET"); + var HTTPMessage rsp := f_http_transact("/enb/" & p_enb_id, method := "GET", + exp := tr_HTTP_RespBody(decmatch EnbItem:?)); return dec_EnbItem(char2oct(rsp.response.body)); }
@@ -103,14 +112,16 @@ function f_REST_EnbErabList(ParamEnbId enb_id) runs on http_CT return ErabList { var charstring p_enb_id := enc_ParamEnbId(enb_id); - var HTTPMessage rsp := f_http_transact("/enb/" & p_enb_id & "/erab-list", method := "GET"); + var HTTPMessage rsp := f_http_transact("/enb/" & p_enb_id & "/erab-list", method := "GET", + exp := tr_HTTP_RespBody(decmatch ErabList:?)); return dec_ErabList(char2oct(rsp.response.body)); }
/* Get E-RAB list for all eNBs */ function f_REST_ErabList() runs on http_CT return ErabList { - var HTTPMessage rsp := f_http_transact("/erab-list", method := "GET"); + var HTTPMessage rsp := f_http_transact("/erab-list", method := "GET", + exp := tr_HTTP_RespBody(decmatch ErabList:?)); return dec_ErabList(char2oct(rsp.response.body)); }
@@ -118,7 +129,8 @@ function f_REST_ErabInfo(ParamErabId erab_id) runs on http_CT return ErabItem { var charstring p_erab_id := enc_ParamErabId(erab_id); - var HTTPMessage rsp := f_http_transact("/erab/" & p_erab_id, method := "GET"); + var HTTPMessage rsp := f_http_transact("/erab/" & p_erab_id, method := "GET", + exp := tr_HTTP_RespBody(decmatch ErabItem:?)); return dec_ErabItem(char2oct(rsp.response.body)); }