Commit 2e9c316d authored by Claudia Carballo Gonzalez's avatar Claudia Carballo Gonzalez
Browse files

feat: implement discovery request model and update visibility control tests

parent 82a1ec2f
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
class DiscoveryRequest:
    def __init__(self, *args, **kwargs):
        pass
+65 −0
Original line number Diff line number Diff line
@@ -297,6 +297,7 @@ Discover Published service APIs by Authorised API Invoker Visibility Control

    # Default Invoker Registration and Onboarding
    ${register_user_info_invoker}    ${url}    ${request_body}=    Invoker Default Onboarding
    ${invoker_id}=    Set Variable    ${register_user_info_invoker['api_invoker_id']}
    
    # Test
    ${resp}=    Get Request Capif
@@ -314,6 +315,70 @@ Discover Published service APIs by Authorised API Invoker Visibility Control
    List Should Contain Value    ${resp.json()['serviceAPIDescriptions']}    ${service_api_description_published}



Discover Published service APIs by Unauthorised API Invoker Visibility Control
    [Tags]    visibility_control-11
    # Register APF
    ${register_user_info}=    Provider Default Registration

    # Publish one api
    ${service_api_description_published}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}

    # Default Invoker Registration and Onboarding
    ${register_user_info_invoker}    ${url}    ${request_body}=    Invoker Default Onboarding
    ${invoker_id}=    Set Variable    ${register_user_info_invoker['api_invoker_id']}
    
    # Test
    ${resp}=    Get Request Capif
    ...    ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${register_user_info['aef_id']}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${INVOKER_USERNAME}

    Check Response Variable Type And Values    ${resp}    200    DiscoveredAPIs

    # Check Results
    Dictionary Should Contain Key    ${resp.json()}    serviceAPIDescriptions
    Should Not Be Empty    ${resp.json()['serviceAPIDescriptions']}
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    1
    List Should Contain Value    ${resp.json()['serviceAPIDescriptions']}    ${service_api_description_published}

    # Build provider selector from published API and provider registration
    ${aef_list}=    Create List    ${register_user_info['aef_id']}
    ${apiId_list}=    Create List    ${service_api_description_published['apiId']}
    ${apiName_list}=    Create List    ${service_api_description_published['apiName']}
    ${apiProv_list}=    Create List    ${service_api_description_published['apiProvName']}
    ${provider_selector}=    Create Dictionary    aefId=${aef_list}    apiId=${apiId_list}    apiName=${apiName_list}    apiProviderId=${apiProv_list}    userName=${register_user_info['apf_username']}

    # Prepare the request body
    ${body}=    Create Visibility Control Rule Body 3    ${invoker_id}    ${provider_selector}
    
    # Create a new rule using superadmin
    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/rules
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}
    ...    json=${body}

    # Verify creation was successful (201 Created)
    Status Should Be    201    ${resp}
    ${rule_id}=    Set Variable    ${resp.json()['ruleId']}
    Dictionary Should Contain Key    ${resp.json()}    providerSelector
    Should Not Be Empty    ${resp.json()['providerSelector']}

    # Test
    ${resp}=    Get Request Capif
    ...    ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${register_user_info['aef_id']}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${INVOKER_USERNAME}

    Check Response Variable Type And Values    ${resp}    200    DiscoveredAPIs
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    0
    

    #Configurar visibility control (añadir una regla), volver a copiar a partir de # Test y check results length 0


+24 −0
Original line number Diff line number Diff line
@@ -43,6 +43,30 @@ def create_visibility_control_rule_body_2():
        }
    }

def create_visibility_control_rule_body_3(invoker_ids=None, provider_selector=None):
    if invoker_ids is None:
        invoker_ids = []
    elif isinstance(invoker_ids, str):
        invoker_ids = [invoker_ids]

    if provider_selector is None:
        provider_selector = {
            "aefId": ["aef-002"],
            "apiId": ["apiId-999"],
            "apiName": ["api-test-cli"],
            "apiProviderId": ["capif-prov-01"],
            "userName": "AMF_ROBOT_TESTING_PROVIDER"
        }

    return {
        "default_access": "ALLOW",
        "enabled": True,
        "invokerExceptions": {
            "apiInvokerId": invoker_ids
        },
        "providerSelector": provider_selector or {}
    }

# def create_test_api_description(api_id="test-api-001", api_name="test-api", provider_name="capif-prov-01", aef_id="aef-001"):
#     """Create a test API description for filtering tests"""
#     return {
+8 −3
Original line number Diff line number Diff line
@@ -55,9 +55,14 @@ RUN apt-get install -y --no-install-recommends \
    nodejs \
    npm

RUN add-apt-repository -y ppa:deadsnakes/ppa
RUN apt-get update
RUN apt-get install -y --fix-missing python3.10 python3.10-venv python3.10-dev
#RUN add-apt-repository -y ppa:deadsnakes/ppa
#RUN apt-get update
#RUN apt-get install -y --fix-missing python3.10 python3.10-venv python3.10-dev
RUN apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository -y ppa:deadsnakes/ppa && \
    apt-get update && \
    apt-get install -y --fix-missing python3.10 python3.10-venv python3.10-dev

RUN mkdir /opt/venv
RUN python3.10 -m venv /opt/venv