diff --git a/tests/features/CAPIF Security Api/capif_security_api.robot b/tests/features/CAPIF Security Api/capif_security_api.robot index 2a41e80d3d49131d970826e9f48f1609b20ba2e2..c920d01629f2f4bd7b7124421a210f911a6fd0b2 100644 --- a/tests/features/CAPIF Security Api/capif_security_api.robot +++ b/tests/features/CAPIF Security Api/capif_security_api.robot @@ -670,7 +670,7 @@ Retrieve access token # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -729,7 +729,7 @@ Retrieve access token by Provider # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -787,7 +787,7 @@ Retrieve access token by Provider with invalid apiInvokerId # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -846,7 +846,7 @@ Retrieve access token with invalid apiInvokerId # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -907,7 +907,7 @@ Retrieve access token with invalid client_id # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -966,7 +966,7 @@ Retrieve access token with unsupported grant_type # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -1032,7 +1032,7 @@ Retrieve access token with invalid scope # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -1093,7 +1093,7 @@ Retrieve access token with invalid aefid at scope # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} @@ -1154,7 +1154,7 @@ Retrieve access token with invalid apiName at scope # Test ${discover_response}= Get Request Capif - ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']} + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&api-name=${api_name} ... server=${CAPIF_HTTPS_URL} ... verify=ca.crt ... username=${INVOKER_USERNAME} diff --git a/tests/libraries/helpers.py b/tests/libraries/helpers.py index ec1abe0d8b49c00971a013faff814416e68dfead..94c850fbe537b37d449ec355dd7779ea52ba3bf5 100644 --- a/tests/libraries/helpers.py +++ b/tests/libraries/helpers.py @@ -7,6 +7,8 @@ from OpenSSL.crypto import (dump_certificate_request, dump_privatekey, from OpenSSL.SSL import FILETYPE_PEM import socket import copy +import json +import pickle def parse_url(input): @@ -139,3 +141,14 @@ def create_scope(aef_id, api_name): data = "3gpp#" + aef_id + ":" + api_name return data + +def read_dictionary(file_path): + with open(file_path, 'rb') as fp: + data = pickle.load(fp) + print('Dictionary loaded') + return data + +def write_dictionary(file_path, data): + with open(file_path, 'wb') as fp: + pickle.dump(data, fp) + print('dictionary saved successfully to file ' + file_path) diff --git a/tests/requirements.txt b/tests/requirements.txt index 71b55e2329efca2577a402b24133de42a318d187..c6d90325ac78628f7de12acc34a01497039f57f3 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -4,4 +4,5 @@ requests==2.28.1 configparser==5.3.0 redis==4.3.4 rfc3987==1.3.8 -robotframework-httpctrl \ No newline at end of file +robotframework-httpctrl +robotframework-archivelibrary == 0.4.2 \ No newline at end of file diff --git a/tests/resources/common/basicRequests.robot b/tests/resources/common/basicRequests.robot index 1d8d69553cd9e905b95463627e0e1c8a72c20973..580c7d0d049a1318fcf42f90511d873d5ecaf651 100644 --- a/tests/resources/common/basicRequests.robot +++ b/tests/resources/common/basicRequests.robot @@ -332,12 +332,6 @@ Get Auth For User RETURN ${resp.json()} -# Clean Test Information By HTTP Requests -# Create Session jwtsession ${CAPIF_HTTP_URL} verify=True - -# ${resp}= DELETE On Session jwtsession /testdata -# Should Be Equal As Strings ${resp.status_code} 200 - Clean Test Information ${capif_users_dict}= Call Method ${CAPIF_USERS} get_capif_users_dict @@ -413,17 +407,38 @@ Remove entity Log Dictionary ${capif_users_dict} Log List ${register_users} +Remove Resource + [Arguments] ${resource_url} ${management_cert} ${username} + + ${resp}= Delete Request Capif + ... ${resource_url} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${management_cert} + + Status Should Be 204 ${resp} + + &{body}= Create Dictionary + ... password=password + ... username=${username} + + Create Session jwtsession ${CAPIF_HTTPS_REGISTER_URL} verify=False disable_warnings=1 + + ${resp}= DELETE On Session jwtsession /remove json=${body} + + Should Be Equal As Strings ${resp.status_code} 204 + Invoker Default Onboarding [Arguments] ${invoker_username}=${INVOKER_USERNAME} ${register_user_info}= Register User At Jwt Auth - ... username=${INVOKER_USERNAME} role=${INVOKER_ROLE} + ... username=${invoker_username} role=${INVOKER_ROLE} # Send Onboarding Request ${request_body}= Create Onboarding Notification Body ... http://${CAPIF_CALLBACK_IP}:${CAPIF_CALLBACK_PORT}/netapp_callback ... ${register_user_info['csr_request']} - ... ${INVOKER_USERNAME} + ... ${invoker_username} ${resp}= Post Request Capif ... ${register_user_info['ccf_onboarding_url']} ... json=${request_body} @@ -437,12 +452,15 @@ Invoker Default Onboarding # Assertions Status Should Be 201 ${resp} Check Variable ${resp.json()} APIInvokerEnrolmentDetails - Check Location Header ${resp} ${LOCATION_INVOKER_RESOURCE_REGEX} + ${resource_url}= Check Location Header ${resp} ${LOCATION_INVOKER_RESOURCE_REGEX} # Store dummy signede certificate - Store In File ${INVOKER_USERNAME}.crt ${resp.json()['onboardingInformation']['apiInvokerCertificate']} + Store In File ${invoker_username}.crt ${resp.json()['onboardingInformation']['apiInvokerCertificate']} ${url}= Parse Url ${resp.headers['Location']} + Set To Dictionary ${register_user_info} resource_url=${resource_url} + Set To Dictionary ${register_user_info} management_cert=${invoker_username} + RETURN ${register_user_info} ${url} ${request_body} Provider Registration @@ -500,13 +518,15 @@ Provider Registration ... provider_enrollment_details=${request_body} ... resource_url=${resource_url} ... provider_register_response=${resp} + ... management_cert=${register_user_info['amf_username']} RETURN ${register_user_info} Provider Default Registration + [Arguments] ${provider_username}=${PROVIDER_USERNAME} # Register Provider ${register_user_info}= Register User At Jwt Auth Provider - ... username=${PROVIDER_USERNAME} role=${PROVIDER_ROLE} + ... username=${provider_username} role=${PROVIDER_ROLE} ${register_user_info}= Provider Registration ${register_user_info} @@ -591,3 +611,29 @@ Basic ACL registration END RETURN ${register_user_info_invoker} ${register_user_info_provider} ${service_api_description_published} + +Create Security Context Between invoker and provider + [Arguments] ${register_user_info_invoker} ${register_user_info_provider} + + ${discover_response}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${register_user_info_provider['aef_id']} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${register_user_info_invoker['management_cert']} + + Check Response Variable Type And Values ${discover_response} 200 DiscoveredAPIs + + # create Security Context + ${request_body}= Create Service Security From Discover Response + ... http://${CAPIF_HOSTNAME}:${CAPIF_HTTP_PORT}/test + ... ${discover_response} + + ${resp}= Put Request Capif + ... /capif-security/v1/trustedInvokers/${register_user_info_invoker['api_invoker_id']} + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${register_user_info_invoker['management_cert']} + + Check Response Variable Type And Values ${resp} 201 ServiceSecurity + diff --git a/tests/tasks/Dummy Info/__init__.robot b/tests/tasks/Dummy Info/__init__.robot new file mode 100644 index 0000000000000000000000000000000000000000..f6bbb181671c4e30588946237ed7050ff619613e --- /dev/null +++ b/tests/tasks/Dummy Info/__init__.robot @@ -0,0 +1,2 @@ +*** Settings *** +Force Tags populate \ No newline at end of file diff --git a/tests/tasks/Dummy Info/populate.robot b/tests/tasks/Dummy Info/populate.robot new file mode 100644 index 0000000000000000000000000000000000000000..9a61a4075a5085bb4d0a8a56a283f96ecb4113b1 --- /dev/null +++ b/tests/tasks/Dummy Info/populate.robot @@ -0,0 +1,126 @@ +*** Settings *** +Resource /opt/robot-tests/tests/resources/common.resource +Resource /opt/robot-tests/tests/resources/api_invoker_management_requests/apiInvokerManagementRequests.robot +Resource ../../resources/common.resource +Resource ../../resources/common/basicRequests.robot +Library /opt/robot-tests/tests/libraries/bodyRequests.py +Library Process +Library Collections +Library ArchiveLibrary +Library OperatingSystem +Library DateTime + +Suite Teardown Reset Testing Environment +Test Setup Reset Testing Environment + + +*** Variables *** +${API_INVOKER_NOT_REGISTERED} not-valid +${TOTAL_INVOKERS} 10 +${TOTAL_PROVIDERS} 10 + +${BACKUP_DIRECTORY} backup +${RESULT_FOLDER} /opt/robot-tests/results +${OUTPUT_ZIP_FILE} entities_loaded.zip + +${INVOKER_USERNAME_POPULATE} ${INVOKER_USERNAME}_POPULATE +${PROVIDER_USERNAME_POPULATE} ${PROVIDER_USERNAME}_POPULATE + + +*** Test Cases *** +Create Dummy Invokers and Providers + [Tags] populate-create + ${entities_dictionary}= Create Dictionary + Create Directory ${BACKUP_DIRECTORY} + + FOR ${counter} IN RANGE ${TOTAL_PROVIDERS} + ${USERNAME}= Set Variable ${PROVIDER_USERNAME_POPULATE}_${counter} + ${register_user_info}= Run Keyword And Continue On Failure Provider Default Registration ${USERNAME} + + Set To Dictionary ${entities_dictionary} ${USERNAME}=${register_user_info} + Copy Files *${USERNAME}* ${BACKUP_DIRECTORY}/ + + ${service_api_description_published} + ... ${resource_url} + ... ${request_body}= + ... Run Keyword And Continue On Failure + ... Publish Service Api + ... ${register_user_info} + ... ROBOT_SERVICE_${counter} + END + + ${last_provider_used}= Evaluate -1 + FOR ${counter} IN RANGE ${TOTAL_INVOKERS} + ${USERNAME}= Set Variable ${INVOKER_USERNAME_POPULATE}_${counter} + ${register_user_info} ${url} ${request_body}= Run Keyword And Continue On Failure + ... Invoker Default Onboarding + ... ${USERNAME} + + IF ${TOTAL_PROVIDERS} > 0 + ${last_provider_used} ${register_user_info_provider}= Get Provider + ... ${last_provider_used} + ... ${entities_dictionary} + Log Dictionary ${register_user_info_provider} + + Run Keyword And Continue On Failure + ... Create Security Context Between invoker and provider + ... ${register_user_info} + ... ${register_user_info_provider} + END + + Set To Dictionary ${entities_dictionary} ${USERNAME}=${register_user_info} + Copy Files ${USERNAME}* ${BACKUP_DIRECTORY}/ + END + + Write Dictionary ${BACKUP_DIRECTORY}/registers.json ${entities_dictionary} + ${date}= Get Current Date result_format=%Y_%m_%d_%H_%M_%S + Create Zip From Files In Directory ${BACKUP_DIRECTORY} ${RESULT_FOLDER}/${date}_${OUTPUT_ZIP_FILE} + + ${result}= Run Process ls -l + + Log Many ${result.stdout} + +Remove Dummy Invokers and Providers + [Tags] populate-remove + ${files}= List Files In Directory ${RESULT_FOLDER} *${OUTPUT_ZIP_FILE} + ${sorted_list}= Copy List ${files} + + Sort List ${sorted_list} + ${last_backup}= Get From List ${sorted_list} -1 + + Copy File ${RESULT_FOLDER}/${last_backup} ./ + Extract Zip File ${last_backup} + + ${entities_dictionary}= Read Dictionary registers.json + + Log Dictionary ${entities_dictionary} + + FOR ${username} IN @{entities_dictionary} + Log ${username}=${entities_dictionary}[${username}] + ${resource_url}= Set Variable ${entities_dictionary}[${username}][resource_url] + ${management_cert}= Set Variable ${entities_dictionary}[${username}][management_cert] + Run Keyword And Ignore Error Remove Resource ${resource_url.path} ${management_cert} ${username} + END + + ${result}= Run Process ls -l + + Log Many ${result.stdout} + + +*** Keywords *** +Get Provider + [Arguments] ${index} ${entities_dictionary} + ${index}= Evaluate ${index} + 1 + IF ${index} == ${TOTAL_PROVIDERS} + ${index}= Evaluate 0 + END + + ${username}= Set Variable ${PROVIDER_USERNAME_POPULATE}_${index} + ${usernames}= Get Dictionary Keys ${entities_dictionary} + IF '${username}' in ${usernames} + log ${username} is in the list + ELSE + Log Dictionary not contain ${username}, no provider returned + END + + RETURN ${index} ${entities_dictionary}[${username}] diff --git a/tests/tasks/__init__.robot b/tests/tasks/__init__.robot new file mode 100644 index 0000000000000000000000000000000000000000..a65a0e734aefe8abbd5786c5f14af684576f2b36 --- /dev/null +++ b/tests/tasks/__init__.robot @@ -0,0 +1,56 @@ +*** Settings *** +Resource /opt/robot-tests/tests/resources/common.resource +Resource ../resources/common.resource + +Suite Setup Prepare environment +# Suite Teardown Reset Testing Environment + +Force Tags tasks + + +*** Keywords *** +Prepare environment + Log ${CAPIF_HOSTNAME} + Log "${CAPIF_HTTP_PORT}" + Log "${CAPIF_HTTPS_PORT}" + + Set Global Variable ${CAPIF_HTTP_VAULT_URL} http://${CAPIF_VAULT}/ + IF "${CAPIF_VAULT_PORT}" != "" + Set Global Variable ${CAPIF_HTTP_VAULT_URL} http://${CAPIF_VAULT}:${CAPIF_VAULT_PORT}/ + END + + Set Global Variable ${CAPIF_HTTPS_REGISTER_URL} https://${CAPIF_REGISTER}/ + IF "${CAPIF_REGISTER_PORT}" != "" + Set Global Variable ${CAPIF_HTTPS_REGISTER_URL} https://${CAPIF_REGISTER}:${CAPIF_REGISTER_PORT}/ + END + + Set Global Variable ${CAPIF_HTTP_URL} http://${CAPIF_HOSTNAME}/ + IF "${CAPIF_HTTP_PORT}" != "" + Set Global Variable ${CAPIF_HTTP_URL} http://${CAPIF_HOSTNAME}:${CAPIF_HTTP_PORT}/ + END + + Set Global Variable ${CAPIF_HTTPS_URL} https://${CAPIF_HOSTNAME}/ + IF "${CAPIF_HTTPS_PORT}" != "" + Set Global Variable ${CAPIF_HTTPS_URL} https://${CAPIF_HOSTNAME}:${CAPIF_HTTPS_PORT}/ + END + + ${status} ${CAPIF_IP}= Run Keyword And Ignore Error Get Ip From Hostname ${CAPIF_HOSTNAME} + + IF "${status}" == "PASS" + Log We will use a remote deployment + Log ${CAPIF_IP} + ELSE + Log We will use a local deployment + Add Dns To Hosts 127.0.0.1 ${CAPIF_HOSTNAME} + END + # Obtain ca root certificate + Retrieve Ca Root + + Reset Testing Environment + +Retrieve Ca Root + [Documentation] This keyword retrieve ca.root from CAPIF and store it at ca.crt in order to use at TLS communications + ${resp}= Get CA Vault /v1/secret/data/ca ${CAPIF_HTTP_VAULT_URL} + Status Should Be 200 ${resp} + Log ${resp.json()['data']['data']['ca']} + Store In File ca.crt ${resp.json()['data']['data']['ca']}