Commit 8067cc3c authored by Pelayo Torres's avatar Pelayo Torres
Browse files

OpenDiscover tests

parent 2c56a28b
Loading
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -464,14 +464,33 @@ class OpenDiscoverOperations(Resource):

                if param == "api_supported_features":
                    if isinstance(query_params[param], dict):
                        for api_name, api_supp_feat in query_params[param].items():
                            my_params.append({"$and": [{"api_name": api_name}, {"api_supp_feats": api_supp_feat}]})
                        # Each (api_name, api_supp_feat) pair is an independent
                        # alternative match, not a joint requirement on a single
                        # document - combine with $or, not $and.
                        feature_conditions = [
                            {"$and": [{"api_name": api_name}, {"api_supp_feats": api_supp_feat}]}
                            for api_name, api_supp_feat in query_params[param].items()
                        ]
                        if len(feature_conditions) == 1:
                            my_params.append(feature_conditions[0])
                        elif feature_conditions:
                            my_params.append({"$or": feature_conditions})
                    else:
                        my_params.append({query_params_name[param]: query_params[param]})
                    continue

                for entry in self._ensure_list(query_params[param]):
                    my_params.append({query_params_name[param]: entry})
                # api_names, api_ids, api_cats, api_prov_names: scalar fields.
                # A single document cannot equal more than one value at once,
                # so multiple requested values must be combined with $in
                # (any of these), not one $and clause per value (impossible
                # to satisfy, always zero results).
                values = self._split_form_values(query_params[param])
                if not values:
                    continue
                if len(values) == 1:
                    my_params.append({query_params_name[param]: values[0]})
                else:
                    my_params.append({query_params_name[param]: {"$in": values}})

            if my_params:
                my_query = {"$and": my_params}
+1 −1
Original line number Diff line number Diff line
map "$service:$endpoint:$method:$has_token:$has_cert:$role" $auth_error {
    default '{"status":401,"title":"Unauthorized","detail":"Operation not allowed","cause":"Access denied by policy"}';
    ~^open-discover-service:.*:.*:0:0:.*$  '{"status":401, "title":"Unauthorized" ,"detail":"Access token not present", "cause":"Bearer token is required for this API route"}';
    default '{"status":401,"title":"Unauthorized","detail":"Operation not allowed","cause":"Access denied by policy"}';
    ~^.*:.*:.*:0:0:.*$  '{"status":401, "title":"Unauthorized" ,"detail":"Certifcate not present", "cause":"Certificate is required for this API route"}';
    ~^helper:.*:.*:0:1:(invoker|apf|aef)$  '{"status":401, "title":"Unauthorized" ,"detail":"Role not authorized for this API route", "cause":"User role must be superadmin"}';
    ~^invoker-management:.*:.*:0:1:(amf|apf|aef|ccf)$  '{"status":401, "title":"Unauthorized" ,"detail":"Role not authorized for this API route", "cause":"User role must be invoker"}';
+1 −1
Original line number Diff line number Diff line
map "$endpoint:$method" $open_discover_token_policy {
    default DENY;
    open_discover_exact:GET ALLOW;
    ~^open_discover_exact:GET ALLOW;
}
+203 −0
Original line number Diff line number Diff line
@@ -40,7 +40,210 @@ Open Discover Published service APIs by Authorised Entity
    # Check Results
    Dictionary Should Contain Key    ${resp.json()}    discApis
    Should Not Be Empty    ${resp.json()['discApis']}
    #Length Should Be    ${resp.json()['discApis']}    1
    # Convert Service API Description to Open API Details
    ${open_api_details}=   Create Open API Details From Service API Description    ${service_api_description_published}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details}


Open Discover Published service APIs by Non Authorised Entity
    [Tags]    capif_api_open_discover_service-2

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

    # Register user for invoker
    ${register_user_info}=    Register User At Jwt Auth
    ...    username=${INVOKER_USERNAME}    role=${INVOKER_ROLE}

    # Test
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt


    Check Response Variable Type And Values    ${resp}    401    ProblemDetails
    ...    title=Unauthorized
    ...    status=401
    ...    detail=Access token not present
    ...    cause=Bearer token is required for this API route

Open Discover Published service APIs when no APIs are published
    [Tags]    capif_api_open_discover_service-3

    # Register APF
    ${register_user_info}=    Provider Default Registration

    # Register user for invoker
    ${register_user_info}=    Register User At Jwt Auth
    ...    username=${INVOKER_USERNAME}    role=${INVOKER_ROLE}

    # Test
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    access_token=${register_user_info['access_token']}

    # Check Results
    Check Response Variable Type And Values    ${resp}    404    ProblemDetails
    ...    title=Not Found
    ...    status=404
    ...    detail=No API Published accomplish filter conditions
    ...    cause=No API Published accomplish filter conditions

Open Discover Published service APIs filtered by api-names with 1 result
    [Tags]    capif_api_open_discover_service-4

    # Register APF
    ${register_user_info}=    Provider Default Registration

    ${api_name_1}=    Set Variable    service_1
    ${api_name_2}=    Set Variable    service_2

    # Publish 2 apis
    ${service_api_description_published}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}
    ...    ${api_name_1}
    ${service_api_description_published_2}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}
    ...    ${api_name_2}

    # Register user for invoker
    ${register_user_info}=    Register User At Jwt Auth
    ...    username=${INVOKER_USERNAME}    role=${INVOKER_ROLE}

    # Request all the APis
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    access_token=${register_user_info['access_token']}

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

    # Check Results
    Dictionary Should Contain Key    ${resp.json()}    discApis
    Should Not Be Empty    ${resp.json()['discApis']}
    # Convert Service API Description to Open API Details
    ${open_api_details}=   Create Open API Details From Service API Description    ${service_api_description_published}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details}
    ${open_api_details_2}=   Create Open API Details From Service API Description    ${service_api_description_published_2}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details_2}

    # Request api 1
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}?api-names=${api_name_1}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    access_token=${register_user_info['access_token']}
    
     Check Response Variable Type And Values    ${resp}    200    OpenDiscoveryResp

     # Check Results
    Dictionary Should Contain Key    ${resp.json()}    discApis
    Should Not Be Empty    ${resp.json()['discApis']}
    Length Should Be    ${resp.json()['discApis']}    1
    # Convert Service API Description to Open API Details
    ${open_api_details}=   Create Open API Details From Service API Description    ${service_api_description_published}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details}

Open Discover Published service APIs filtered by api-names with no match
    [Tags]    capif_api_open_discover_service-5

    # Register APF
    ${register_user_info}=    Provider Default Registration

    ${api_name_1}=    Set Variable    service_1
    ${api_name_2}=    Set Variable    service_2

    # Publish 2 apis
    ${service_api_description_published}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}
    ...    ${api_name_1}
    ${service_api_description_published_2}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}
    ...    ${api_name_2}

    # Register user for invoker
    ${register_user_info}=    Register User At Jwt Auth
    ...    username=${INVOKER_USERNAME}    role=${INVOKER_ROLE}

    # Request all the APis
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    access_token=${register_user_info['access_token']}

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

    # Check Results
    Dictionary Should Contain Key    ${resp.json()}    discApis
    Should Not Be Empty    ${resp.json()['discApis']}
    # Convert Service API Description to Open API Details
    ${open_api_details}=   Create Open API Details From Service API Description    ${service_api_description_published}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details}
    ${open_api_details_2}=   Create Open API Details From Service API Description    ${service_api_description_published_2}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details_2}

    ${api_name_x}=    Set Variable    service_x

    # Request other api
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}?api-names=${api_name_x},
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    access_token=${register_user_info['access_token']}
    
     Check Response Variable Type And Values    ${resp}    404    ProblemDetails
    ...    title=Not Found
    ...    status=404
    ...    detail=No API Published accomplish filter conditions
    ...    cause=No API Published accomplish filter conditions

Open Discover Published service APIs not filtered
    [Tags]    capif_api_open_discover_service-6

    # Register APF
    ${register_user_info}=    Provider Default Registration

    ${api_name_1}=    Set Variable    service_1
    ${api_name_2}=    Set Variable    service_2

    # Publish 2 apis
    ${service_api_description_published}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}
    ...    ${api_name_1}
    ${service_api_description_published_2}    ${resource_url}    ${request_body}=    Publish Service Api
    ...    ${register_user_info}
    ...    ${api_name_2}

    # Register user for invoker
    ${register_user_info}=    Register User At Jwt Auth
    ...    username=${INVOKER_USERNAME}    role=${INVOKER_ROLE}

    # Request all the APis
    ${resp}=    Get Request Capif
    ...    ${OPEN_DISCOVER_URL}
    ...    server=${CAPIF_HTTPS_URL}
    ...    verify=ca.crt
    ...    access_token=${register_user_info['access_token']}

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

    # Check Results
    Dictionary Should Contain Key    ${resp.json()}    discApis
    Should Not Be Empty    ${resp.json()['discApis']}
    # Convert Service API Description to Open API Details
    ${open_api_details}=   Create Open API Details From Service API Description    ${service_api_description_published}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details}
    ${open_api_details_2}=   Create Open API Details From Service API Description    ${service_api_description_published_2}
    List Should Contain Value    ${resp.json()['discApis']}    ${open_api_details_2}