Commit dc567f89 authored by Benedetta Arena's avatar Benedetta Arena
Browse files

fix: enhance loop detection tests and add Via header validation for all endpoints

parent a4e14f7d
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -30,15 +30,9 @@ D018_01 Loop Detection With Via Header
    ${payload}=    Convert To Dictionary    ${response}
    ${expected_via_header}=    Get From Dictionary    ${payload}    Via

    ${response}=    Delete Entity    ${entity_id}
    ${response}=    Delete Entity    ${entity_id}    check_via=${expected_via_header}
    Check Response Status Code    508    ${response.status_code}

    Wait For Request
    ${response}=    Get Request Headers
    ${payload}=    Convert To Dictionary    ${response}
    ${actual_via_header}=    Get From Dictionary    ${payload}    Via
    Should Be Equal    ${actual_via_header}    ${expected_via_header}

*** Keywords ***
Create Entity And Registration On The Context Broker And Start Context Source Mock Server
    ${entity_id}=    Generate Random Vehicle Entity Id
+65 −4
Original line number Diff line number Diff line
*** Settings ***
Documentation       Verify that the request contains the Via header when forwarding operations to the Context Broker
Documentation       Check Via Header Forwarding To Context Source across multiple NGSI-LD endpoints

Resource            ${EXECDIR}/resources/ApiUtils/Common.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
@@ -14,11 +14,42 @@ Test Setup Create Entity And Registration On The Context Broker And Sta
Test Teardown       Delete Registrations And Stop Context Source Mock Server

*** Variables ***
${entity_payload_filename}           vehicle-simple-attributes.jsonld
${first_entity_payload_filename}     vehicle-simple-attributes.jsonld
${second_entity_payload_filename}    vehicle-simple-attributes-second-different.jsonld
${brandname_payload_filename}        vehicle-brandname-fragment.jsonld
${registration_payload_file_path}    csourceRegistrations/context-source-registration-vehicle-redirection-ops.jsonld

*** Test Cases ***
D018_02 Check Via Header Forwarding To Context Source
D018_02_01 Check Post Via Header Forwarding To Context Source
    [Documentation]    Verify that the request contains the Via header when forwarding operations to the Context Source
    [Tags]    since_v1.8.1    dist-ops    4_3_3    cf_06    additive-inclusive    5_6_6    6_3_18

    Set Stub Reply    POST    /broker1/ngsi-ld/v1/entities    201
    ${response}=    Create Entity    ${second_entity_payload_filename}    ${entity_id}
    Check Response Status Code    201    ${response.status_code}

    Wait For Request
    ${response}=    Get Request Headers
    ${payload}=    Convert To Dictionary    ${response}
    Dictionary Should Contain Key    ${payload}    Via

D018_02_02 Check Update Via Header Forwarding To Context Source
    [Documentation]    Verify that the request contains the Via header when forwarding operations to the Context Source
    [Tags]    since_v1.8.1    dist-ops    4_3_3    cf_06    additive-inclusive    5_6_6    6_3_18

    Set Stub Reply    PATCH    /broker1/ngsi-ld/v1/entities/${entity_id}    204
    ${response}=    Update Entity Attributes
    ...    ${entity_id}
    ...    ${brandname_payload_filename}
    ...    content_type=${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    204    ${response.status_code}

    Wait For Request
    ${response}=    Get Request Headers
    ${payload}=    Convert To Dictionary    ${response}
    Dictionary Should Contain Key    ${payload}    Via

D018_02_03 Check Delete Via Header Forwarding To Context Source
    [Documentation]    Verify that the request contains the Via header when forwarding operations to the Context Source
    [Tags]    since_v1.8.1    dist-ops    4_3_3    cf_06    additive-inclusive    5_6_6    6_3_18

@@ -31,11 +62,40 @@ D018_02 Check Via Header Forwarding To Context Source
    ${payload}=    Convert To Dictionary    ${response}
    Dictionary Should Contain Key    ${payload}    Via

D018_02_04 Check Put Via Header Forwarding To Context Source
    [Documentation]    Verify that the request contains the Via header when forwarding operations to the Context Source
    [Tags]    since_v1.8.1    dist-ops    4_3_3    cf_06    additive-inclusive    5_6_6    6_3_18

    Set Stub Reply    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}    204
    ${response}=    Replace Entity
    ...    ${entity_id}
    ...    ${second_entity_payload_filename}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    204    ${response.status_code}

    Wait For Request
    ${response}=    Get Request Headers
    ${payload}=    Convert To Dictionary    ${response}
    Dictionary Should Contain Key    ${payload}    Via

D018_02_05 Check Get Via Header Forwarding To Context Source
    [Documentation]    Verify that the request contains the Via header when forwarding operations to the Context Source
    [Tags]    since_v1.8.1    dist-ops    4_3_3    cf_06    additive-inclusive    5_6_6    6_3_18

    Set Stub Reply    GET    /broker1/ngsi-ld/v1/entities/${entity_id}    200
    ${response}=    Retrieve Entity    ${entity_id}
    Check Response Status Code    200    ${response.status_code}

    Wait For Request
    ${response}=    Get Request Headers
    ${payload}=    Convert To Dictionary    ${response}
    Dictionary Should Contain Key    ${payload}    Via

*** Keywords ***
Create Entity And Registration On The Context Broker And Start Context Source Mock Server
    ${entity_id}=    Generate Random Vehicle Entity Id
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}
    ${response}=    Create Entity    ${first_entity_payload_filename}    ${entity_id}
    Check Response Status Code    201    ${response.status_code}

    ${registration_id}=    Generate Random CSR Id
@@ -52,5 +112,6 @@ Create Entity And Registration On The Context Broker And Start Context Source Mo
    Start Context Source Mock Server

Delete Registrations And Stop Context Source Mock Server
    Delete Entity    ${entity_id}
    Delete Context Source Registration    ${registration_id}
    Stop Context Source Mock Server
+10 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ Library RequestsLibrary
Library         OperatingSystem
Library         Collections
Library         JSONLibrary
Library    HttpCtrl.Server
Resource        ${EXECDIR}/resources/ApiUtils/Common.resource
Resource        ${EXECDIR}/resources/ApiUtils/TemporalContextInformationProvision.resource
Resource        ${EXECDIR}/resources/JsonUtils.resource
@@ -271,7 +272,7 @@ Delete Entity Attributes

Delete Entity
    [Tags]    actor_context-producer
    [Arguments]    ${id}    ${local}=${EMPTY}    ${broker_url}=${EMPTY}
    [Arguments]    ${id}    ${local}=${EMPTY}    ${broker_url}=${EMPTY}    ${check_via}=${EMPTY}
    &{params}=    Create Dictionary
    IF    '${local}'!=''    Set To Dictionary    ${params}    local=${local}
    ${final_url}=    Set Variable If    '${broker_url}' != ''    ${broker_url}    ${url}
@@ -279,6 +280,14 @@ Delete Entity
    ...    url=${final_url}/${ENTITIES_ENDPOINT_PATH}${id}
    ...    params=${params}
    ...    expected_status=any
    IF    '${check_via}' != '${EMPTY}'
        Wait For Request
        ${request_headers}=    Get Request Headers
        ${payload}=    Convert To Dictionary    ${request_headers}
        ${actual_via}=    Get From Dictionary    ${payload}    Via
        Should Be Equal    ${check_via}    ${actual_via}
        Output    ${response}    Delete Entity
    END
    IF    ${delete_temporal_on_core_delete}
        Delete Temporal Representation Of Entity    ${id}
    END