Commit 85c07be1 authored by Cesar Cajas's avatar Cesar Cajas
Browse files

OCF176: test patching rule to enabled equal false

parent 0b0b66ec
Loading
Loading
Loading
Loading
Loading
+60 −170
Original line number Diff line number Diff line
@@ -286,38 +286,8 @@ Create and Get Specific Visibility Control Rule


# ==================== DECISION ENDPOINT TESTS ====================
Discover Published service APIs by Authorised API Invoker Visibility Control
    [Tags]    visibility_control-100
    # 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}


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

@@ -398,7 +368,7 @@ Discover Published service APIs by Unauthorised API Invoker Visibility Control

# ==========
Discover Published service APIs by Unauthorised API Invoker Visibility Control (two APIs)
    [Tags]    visibility_control-102
    [Tags]    visibility_control-10

    # Register APF
    ${register_user_info}=    Provider Default Registration
@@ -480,7 +450,7 @@ Discover Published service APIs by Unauthorised API Invoker Visibility Control (

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

@@ -580,172 +550,92 @@ Discover Published service APIs by Unauthorised API Invoker Visibility Control (
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    1
    List Should Contain Value    ${resp.json()['serviceAPIDescriptions']}    ${service_api_description_published}

# ==========
Discover Published service APIs by Unauthorised API Invoker Visibility Control (update the rule and see changes in the discovery process)
    [Tags]    visibility_control-12

    # 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']}




# ==========OLD TESTS!
Decision Endpoint Without Active Rules Returns All APIs
    [Tags]    visibility_control-9
    [Documentation]    Test that without any active rules, the decision endpoint returns ALL APIs (default ALLOW)
    
    # 1. Create a request with test API
    ${test_api}=    Create Test Api Description    api_id=api-001    api_name=test-api
    @{apis}=    Create List    ${test_api}
    ${body}=    Create Discovery Decision Request    apis=${apis}
    
    # 2. Call decision endpoint (no rules exist)
    # Note: Endpoint is called by internal services (Discovery Service), using superadmin credentials for testing
    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/decision/invokers/test-invoker-001/discoverable-apis
    # Before rules, the API is discoverable
    ${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=${SUPERADMIN_USERNAME}
    ...    json=${body}
    ...    username=${INVOKER_USERNAME}

    # 3. Verify response: should return all APIs (default ALLOW)
    Status Should Be    200    ${resp}
    Check Response Variable Type And Values    ${resp}    200    DiscoveredAPIs
    Dictionary Should Contain Key    ${resp.json()}    serviceAPIDescriptions
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    1
    Should Be Equal As Strings    ${resp.json()['serviceAPIDescriptions'][0]['apiId']}    api-001


Decision Endpoint With Empty API List
    [Tags]    visibility_control-10
    [Documentation]    Test decision endpoint with empty API list
    
    # 1. Create request with empty APIs
    @{apis}=    Create List
    ${body}=    Create Discovery Decision Request    apis=${apis}
    
    # 2. Call decision endpoint
    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/decision/invokers/test-invoker-002/discoverable-apis
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}
    ...    json=${body}
    
    # 3. Verify response: should return empty list
    Status Should Be    200    ${resp}
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    0


Decision Endpoint With Multiple APIs Without Rules
    [Tags]    visibility_control-11
    [Documentation]    Test that multiple APIs are returned when no rules exist (default ALLOW)
    
    # 1. Create multiple test APIs
    ${api_1}=    Create Test Api Description    api_id=api-001    api_name=api-alpha
    ${api_2}=    Create Test Api Description    api_id=api-002    api_name=api-beta    provider_name=capif-prov-02
    ${api_3}=    Create Test Api Description    api_id=api-003    api_name=api-gamma    provider_name=capif-prov-03
    @{apis}=    Create List    ${api_1}    ${api_2}    ${api_3}
    ${body}=    Create Discovery Decision Request    apis=${apis}
    
    # 2. Call decision endpoint
    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/decision/invokers/test-invoker-003/discoverable-apis
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}
    ...    json=${body}
    
    # 3. Verify all APIs returned (default ALLOW without rules)
    Status Should Be    200    ${resp}
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    3


Decision Endpoint With DENY Rule Filtering APIs
    [Tags]    visibility_control-12
    [Documentation]    Test that DENY rules filter out specific APIs
    List Should Contain Value    ${resp.json()['serviceAPIDescriptions']}    ${service_api_description_published}

    # 1. Use a test invoker ID
    ${invoker_id}=    Set Variable    test-invoker-allow-rule
    # 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']}
    ${provider_selector}=    Create Dictionary    aefId=${aef_list}    apiId=${apiId_list}    apiName=${apiName_list}    userName=${register_user_info['apf_username']}

    # 2. Create a DENY rule for specific API
    ${rule_body}=    Create Visibility Control Rule Deny Specific Api
    # Create a rule that hides the API for the invoker while enabled
    ${body}=    Create Visibility Control Rule Body 3    ${invoker_id}    ${provider_selector}

    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/rules
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}
    ...    json=${rule_body}
    ...    json=${body}

    Status Should Be    201    ${resp}
    ${rule_id}=    Set Variable    ${resp.json()['ruleId']}

    # 3. Create test APIs: one that should be denied, others allowed
    ${api_test}=    Create Test Api Description    api_id=test-api-001    api_name=test-api    provider_name=capif-prov-01
    ${api_other}=    Create Test Api Description    api_id=other-api-001    api_name=other-api    provider_name=capif-prov-02
    @{apis}=    Create List    ${api_test}    ${api_other}
    ${decision_body}=    Create Discovery Decision Request    apis=${apis}
    
    # 4. Call decision endpoint
    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/decision/invokers/${invoker_id}/discoverable-apis
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}
    ...    json=${decision_body}
    
    # 5. Verify: test-api should be filtered out (DENY), other-api should be returned
    Status Should Be    200    ${resp}
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    1
    Should Be Equal As Strings    ${resp.json()['serviceAPIDescriptions'][0]['apiName']}    other-api
    
    # 6. Cleanup
    ${resp}=    Delete Request Capif
    ...    /helper/visibility-control/rules/${rule_id}
    # With the rule enabled, the API should not be discoverable
    ${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=${SUPERADMIN_USERNAME}


Decision Endpoint With ALLOW Rule And Provider Selector
    [Tags]    visibility_control-13
    [Documentation]    Test that ALLOW rules correctly filter APIs based on provider selectors
    ...    username=${INVOKER_USERNAME}

    # 1. Use a test invoker ID
    ${invoker_id}=    Set Variable    test-invoker-provider-filter
    Check Response Variable Type And Values    ${resp}    404    ProblemDetails
    Dictionary Should Contain Key    ${resp.json()}    detail
    Should Be Equal As Strings    ${resp.json()['detail']}    API Invoker ${invoker_id} has no visible APIs after applying visibility rules

    # 2. Create an ALLOW rule specific to a provider
    ${rule_body}=    Create Visibility Control Rule Allow Specific Api
    # Disable the rule so the API becomes visible again
    ${enabled_value}=    Evaluate    False
    ${body}=    Create Dictionary    enabled=${enabled_value}

    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/rules
    ${resp}=    Patch Request Capif
    ...    /helper/visibility-control/rules/${rule_id}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}
    ...    json=${rule_body}
    
    Status Should Be    201    ${resp}
    ${rule_id}=    Set Variable    ${resp.json()['ruleId']}
    ...    json=${body}

    # 3. Create test APIs: matching and non-matching provider/api
    ${api_allowed}=    Create Test Api Description    api_id=test-api-001    api_name=test-api    provider_name=capif-prov-01
    ${api_blocked}=    Create Test Api Description    api_id=other-api-001    api_name=other-api    provider_name=capif-prov-02
    @{apis}=    Create List    ${api_allowed}    ${api_blocked}
    ${decision_body}=    Create Discovery Decision Request    apis=${apis}
    Status Should Be    200    ${resp}

    # 4. Call decision endpoint
    ${resp}=    Post Request Capif
    ...    /helper/visibility-control/decision/invokers/${invoker_id}/discoverable-apis
    # After disabling the rule, the API should be discoverable again
    ${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=${SUPERADMIN_USERNAME}
    ...    json=${decision_body}
    ...    username=${INVOKER_USERNAME}

    # 5. Verify: only test-api (capif-prov-01) should be returned, other-api filtered out
    Status Should Be    200    ${resp}
    Check Response Variable Type And Values    ${resp}    200    DiscoveredAPIs
    Dictionary Should Contain Key    ${resp.json()}    serviceAPIDescriptions
    Length Should Be    ${resp.json()['serviceAPIDescriptions']}    1
    Should Be Equal As Strings    ${resp.json()['serviceAPIDescriptions'][0]['apiId']}    test-api-001
    List Should Contain Value    ${resp.json()['serviceAPIDescriptions']}    ${service_api_description_published}

    # 6. Cleanup
    ${resp}=    Delete Request Capif
    ...    /helper/visibility-control/rules/${rule_id}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    username=${SUPERADMIN_USERNAME}

    Status Should Be    204    ${resp}