diff --git a/scripts/runRobotTest.sh b/scripts/runRobotTest.sh index 017e25f9..700575fe 100755 --- a/scripts/runRobotTest.sh +++ b/scripts/runRobotTest.sh @@ -30,9 +30,11 @@ showHelp() name=0 path=0 tags=0 +env=0 suite='TEST' serverBase=${EHRBASE_BASE_URL:-http://ehrbase:8080} serverNodeName=${SERVER_NODENAME:-local.ehrbase.org} +keycloakBase=${KEYCLOAK_BASE_URL:-http://keycloak:8081} POSITIONAL_ARGS=() ############################################################ @@ -60,6 +62,11 @@ while [[ $# -gt 0 ]]; do shift # past argument shift # past value ;; + -e|--env) + env="$2" + shift # past argument + shift # past value + ;; -s|--suite) suite="$2" shift # past argument @@ -111,11 +118,47 @@ rm -Rf ${dirResults}/${name} # Run tests # ############################################################ +if [ "$env" == "NONE" ]; then + echo "Environment is set to NONE, changing env to BASIC" + env="BASIC" +fi + echo "---------------------------------------------------------------------------------------" -echo "Running Robot Test-Suite [name: ${name}, path: ${path}, tags: ${tags}, suite: ${suite}]" +echo "Running Robot Test-Suite [name: ${name}, path: ${path}, tags: ${tags}, env=${env}, suite: ${suite}]" echo "---------------------------------------------------------------------------------------" cd tests +echo "Robot Command:" +echo "robot --include ${tags} \ + --skip TODO \ + --skip future \ + --loglevel INFO \ + -e SECURITY \ + -e AQL_DEBUG_OPTS \ + --dotted \ + --console quiet \ + --skiponfailure not-ready -L TRACE \ + --flattenkeywords for \ + --flattenkeywords foritem \ + --flattenkeywords name:_resources.* \ + --flattenkeywords \"name:composition_keywords.Load Json File With Composition\" \ + --flattenkeywords \"name:template_opt1.4_keywords.upload OPT file\" \ + --removekeywords \"name:JSONLibrary.Load Json From File\" \ + --removekeywords \"name:Change Json KeyValue and Save Back To File\" \ + --removekeywords \"name:JSONLibrary.Update Value To Json\" \ + --removekeywords \"name:JSONLibrary.Convert JSON To String\" \ + --removekeywords \"name:JSONLibrary.Get Value From Json\" \ + --report NONE \ + --name ${name} \ + --outputdir ${dirResults}/${name} \ + -v SUT:${suite} \ + -v NODOCKER:False \ + -v AUTH_TYPE:${env} \ + -v NODENAME:${serverNodeName} \ + -v KEYCLOAK_URL:${keycloakBase}/auth \ + -v BASEURL:${serverBase}/ehrbase/rest/openehr/v1 \ + robot/${path}" + robot --include ${tags} \ --skip TODO \ --skip future \ @@ -139,7 +182,9 @@ robot --include ${tags} \ --name ${name} \ --outputdir ${dirResults}/${name} \ -v SUT:${suite} \ - -v nodocker \ + -v NODOCKER:False \ + -v AUTH_TYPE:${env} \ -v NODENAME:${serverNodeName} \ + -v KEYCLOAK_URL:${keycloakBase}/auth \ -v BASEURL:${serverBase}/ehrbase/rest/openehr/v1 \ robot/${path} diff --git a/tests/robot/AUTH_TYPE_TESTS/BASIC/__init__.robot b/tests/robot/AUTH_TYPE_TESTS/BASIC/__init__.robot new file mode 100644 index 00000000..335237a6 --- /dev/null +++ b/tests/robot/AUTH_TYPE_TESTS/BASIC/__init__.robot @@ -0,0 +1,13 @@ +*** Settings *** +Metadata Author *Vladislav Ploaia* + +Documentation AUTHENTICATION TYPE TESTS +... +... Based on requirements from https://vitagroup-ag.atlassian.net/browse/CDR-1401 +... \nDO NOT ENABLE THEM IF PIPELINE IS NOT SETTING FOR TESTS *AUTH_TYPE:BASIC* +... \nREQUIRES EHRBASE to be started with *security.authType=BASIC* + +Resource ${EXECDIR}/robot/_resources/suite_settings.robot + + +Force Tags AUTH_TYPE_TESTS_BASIC \ No newline at end of file diff --git a/tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_admin_user.robot b/tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_admin_user.robot new file mode 100644 index 00000000..cd296b2e --- /dev/null +++ b/tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_admin_user.robot @@ -0,0 +1,75 @@ +*** Settings *** +Documentation Authentication Type Tests +... \nRun with AUTH_TYPE=BASIC only +... \nSUT=ADMIN-TEST set by default to use ADMIN credentials for API calls. +... \nCheck sut_config.py file for ADMIN credentials. +... \nhttps://vitagroup-ag.atlassian.net/browse/CDR-1401 + +Resource ../../_resources/keywords/composition_keywords.robot +Resource ../../_resources/keywords/admin_keywords.robot +Resource ../../_resources/keywords/aql_query_keywords.robot +Resource ../../_resources/keywords/aql_keywords.robot + +Suite Setup Set Library Search Order For Tests + + +*** Variables *** +${SUT} ADMIN-TEST +&{ADMIN_BASIC_AUTH} Authorization=Basic ZWhyYmFzZS1hZG1pbjpFdmVuTW9yZVNlY3JldFBhc3N3b3Jk + + +*** Test Cases *** +Upload Template - Admin User Creds + Upload OPT nested/nested.opt + @{accepted_template_status_codes} Create List ${201} ${204} ${409} + List Should Contain Value ${accepted_template_status_codes} ${response_code} + +Create EHR - Admin User Creds + prepare new request session JSON Prefer=return=representation + create new EHR with ehr_status ${VALID EHR DATA SETS}/000_ehr_status_with_other_details.json + Should Be Equal ${resp.status_code} ${201} + Log ${ehr_id} + +Create Composition - Admin User Creds + prepare new request session JSON Prefer=return=representation + commit composition format=CANONICAL_JSON + ... composition=nested.en.v1__full_without_links.json + Should Be Equal ${response.status_code} ${201} + check the successful result of commit composition + @{compo_uid_splitted} Split String ${composition_uid} :: + Set Suite Variable ${compo_id} ${compo_uid_splitted}[0] + +Store Query - Admin User Creds + ${query} Catenate + ... SELECT c/uid/value AS COMPOSITION_UID_VALUE + ... FROM EHR e + ... CONTAINS COMPOSITION c + ... WHERE e/ehr_id/value = '${ehr_id}' + Set Suite Variable ${initial_query} ${query} + ${resp_qualified_query_name_version} PUT /definition/query/{qualified_query_name}/{version} + ... query_to_store=${query} format=text + Set Suite Variable ${resp_qualified_query_name_version} ${resp_qualified_query_name_version} + +GET Stored Query - Admin User Creds + ${resp_query} GET /definition/query/{qualified_query_name} / including {version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp['q']} ${initial_query} + +Execute Stored Query (POST) - Admin User Creds + ${resp_query} POST /query/{qualified_query_name}/{version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp_query['q']} ${initial_query} + +Execute Ad-Hoc Query - Admin User Creds + Set Test Variable ${test_data} {"q":"${initial_query}"} + Send Ad Hoc Request aql_body=${test_data} + +Admin Delete Composition - Admin User Creds + Set Test Variable ${authorization} ${ADMIN_BASIC_AUTH} + Set Test Variable ${versioned_object_uid} ${compo_id} + (admin) delete composition + +Admin Delete Stored Query - Admin User Creds + Set Test Variable ${authorization} ${ADMIN_BASIC_AUTH} + (admin) delete stored query ${resp_qualified_query_name_version} + [Teardown] (admin) delete ehr \ No newline at end of file diff --git a/tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_normal_user.robot b/tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_normal_user.robot new file mode 100644 index 00000000..ec0739cf --- /dev/null +++ b/tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_normal_user.robot @@ -0,0 +1,80 @@ +*** Settings *** +Documentation Authentication Type Tests +... \nRun with AUTH_TYPE=BASIC only +... \nSUT=TEST set by default to use normal user credentials for API calls. +... \nCheck sut_config.py file for normal user credentials. +... \nhttps://vitagroup-ag.atlassian.net/browse/CDR-1401 + +Resource ../../_resources/keywords/composition_keywords.robot +Resource ../../_resources/keywords/admin_keywords.robot +Resource ../../_resources/keywords/aql_query_keywords.robot +Resource ../../_resources/keywords/aql_keywords.robot + +Suite Setup Set Library Search Order For Tests + + +*** Variables *** +${SUT} TEST + + +*** Test Cases *** +Upload Template - Normal User Creds + Upload OPT nested/nested.opt + @{accepted_template_status_codes} Create List ${201} ${204} ${409} + List Should Contain Value ${accepted_template_status_codes} ${response_code} + +Create EHR - Normal User Creds + prepare new request session JSON Prefer=return=representation + create new EHR with ehr_status ${VALID EHR DATA SETS}/000_ehr_status_with_other_details.json + Should Be Equal ${resp.status_code} ${201} + Log ${ehr_id} + +Create Composition - Normal User Creds + prepare new request session JSON Prefer=return=representation + commit composition format=CANONICAL_JSON + ... composition=nested.en.v1__full_without_links.json + Should Be Equal ${response.status_code} ${201} + check the successful result of commit composition + @{compo_uid_splitted} Split String ${composition_uid} :: + Set Suite Variable ${compo_id} ${compo_uid_splitted}[0] + +Store Query - Normal User Creds + ${query} Catenate + ... SELECT c/uid/value AS COMPOSITION_UID_VALUE + ... FROM EHR e + ... CONTAINS COMPOSITION c + ... WHERE e/ehr_id/value = '${ehr_id}' + Set Suite Variable ${initial_query} ${query} + ${resp_qualified_query_name_version} PUT /definition/query/{qualified_query_name}/{version} + ... query_to_store=${query} format=text + Set Suite Variable ${resp_qualified_query_name_version} ${resp_qualified_query_name_version} + +GET Stored Query - Normal User Creds + ${resp_query} GET /definition/query/{qualified_query_name} / including {version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp['q']} ${initial_query} + +Execute Stored Query (POST) - Normal User Creds + ${resp_query} POST /query/{qualified_query_name}/{version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp_query['q']} ${initial_query} + +Execute Ad-Hoc Query - Normal User Creds + Set Test Variable ${test_data} {"q":"${initial_query}"} + Send Ad Hoc Request aql_body=${test_data} + +Admin Delete Composition - Normal User Creds + Set Test Variable ${versioned_object_uid} ${compo_id} + ${err_msg} Run Keyword And Expect Error * + ... (admin) delete composition + Should Contain ${err_msg} Expected status: 403 != 204 + +Admin Delete Stored Query - Normal User Creds + ${err_msg} Run Keyword And Expect Error * + ... (admin) delete stored query ${resp_qualified_query_name_version} + Should Contain ${err_msg} Expected status: 403 != 200 + ##Below lines are needed as with normal credentials user cannot delete ehr, only with admin creds user. + ##teardown is deleting ehr for cleanup + &{authorization} Create Dictionary Authorization=Basic ZWhyYmFzZS1hZG1pbjpFdmVuTW9yZVNlY3JldFBhc3N3b3Jk + Set Test Variable ${authorization} ${authorization} + [Teardown] (admin) delete ehr diff --git a/tests/robot/AUTH_TYPE_TESTS/OAUTH/__init__.robot b/tests/robot/AUTH_TYPE_TESTS/OAUTH/__init__.robot new file mode 100644 index 00000000..9f15ca29 --- /dev/null +++ b/tests/robot/AUTH_TYPE_TESTS/OAUTH/__init__.robot @@ -0,0 +1,13 @@ +*** Settings *** +Metadata Author *Vladislav Ploaia* + +Documentation AUTHENTICATION TYPE TESTS +... +... Based on requirements from https://vitagroup-ag.atlassian.net/browse/CDR-1401 +... \nDO NOT ENABLE THEM IF PIPELINE IS NOT SETTING FOR TESTS *AUTH_TYPE:OAUTH* +... \nREQUIRES EHRBASE to be started with *security.authType=OAUTH* + +Resource ${EXECDIR}/robot/_resources/suite_settings.robot + + +Force Tags AUTH_TYPE_TESTS_OAUTH \ No newline at end of file diff --git a/tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_admin_user.robot b/tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_admin_user.robot new file mode 100644 index 00000000..abea98f5 --- /dev/null +++ b/tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_admin_user.robot @@ -0,0 +1,109 @@ +*** Settings *** +Documentation Authentication Type Tests +... \nRun with AUTH_TYPE=OAUTH only +... \nhttps://vitagroup-ag.atlassian.net/browse/CDR-1401 + +Resource ../../_resources/keywords/composition_keywords.robot +Resource ../../_resources/keywords/admin_keywords.robot +Resource ../../_resources/keywords/aql_query_keywords.robot +Resource ../../_resources/keywords/aql_keywords.robot + +Suite Setup Set Library Search Order For Tests + + +*** Variables *** +${SUT} ADMIN-TEST +&{TEMP_OAUTH_ACCESS_GRANT} client_id=ehrbase +... grant_type=password client_secret=bT5T4oWn3xNdBytQsl2cfpBDi1pp15Va +... username=ehrbase-admin password=EvenMoreSecretPassword1! +## the same configuration as in sut_config.py, ADMIN_TEST_CONFIG + + +*** Test Cases *** +1. Keycloak OAuth server is online - OAUTH Admin User + [Documentation] Checks that Keycloak server is up and ready. + ${loggedvars} Log Variables + Create Session keycloak ${KEYCLOAK_URL} + ${resp} R.Get On Session keycloak / + Should Be Equal As Strings ${resp.status_code} 200 + Should Be Equal ${TEMP_OAUTH_ACCESS_GRANT['username']} ehrbase-admin + +2. ehrbase realm exists - OAUTH Admin User + ${resp} R.Get On Session keycloak /realms/ehrbase + Status Should Be 200 + Should Be Equal ${resp.json()["realm"]} ehrbase + Log Token service URL: ${resp.json()["token-service"]} console=yes + +3. Test Get Token - OAUTH Admin User + Request Access Token ${TEMP_OAUTH_ACCESS_GRANT} + Status Should Be 200 + +4. Upload Template - OAUTH Admin User Creds + &{authorization} Create Dictionary + ... Authorization=Bearer ${password_access_token} + Set Suite Variable ${authorization} ${authorization} + Upload OPT nested/nested.opt + @{accepted_template_status_codes} Create List ${201} ${204} ${409} + List Should Contain Value ${accepted_template_status_codes} ${response_code} + +5. Create EHR - OAUTH Admin User Creds + prepare new request session JSON Prefer=return=representation + create new EHR with ehr_status ${VALID EHR DATA SETS}/000_ehr_status_with_other_details.json + Should Be Equal ${resp.status_code} ${201} + Log ${ehr_id} + +6. Create Composition - OAUTH Admin User Creds + prepare new request session JSON Prefer=return=representation + commit composition format=CANONICAL_JSON + ... composition=nested.en.v1__full_without_links.json + Should Be Equal ${response.status_code} ${201} + check the successful result of commit composition + @{compo_uid_splitted} Split String ${composition_uid} :: + Set Suite Variable ${compo_id} ${compo_uid_splitted}[0] + +7. Store Query - OAUTH Admin User Creds + ${query} Catenate + ... SELECT c/uid/value AS COMPOSITION_UID_VALUE + ... FROM EHR e + ... CONTAINS COMPOSITION c + ... WHERE e/ehr_id/value = '${ehr_id}' + Set Suite Variable ${initial_query} ${query} + ${resp_qualified_query_name_version} PUT /definition/query/{qualified_query_name}/{version} + ... query_to_store=${query} format=text + Set Suite Variable ${resp_qualified_query_name_version} ${resp_qualified_query_name_version} + +8. GET Stored Query - OAUTH Admin User Creds + ${resp_query} GET /definition/query/{qualified_query_name} / including {version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp['q']} ${initial_query} + +9. Execute Stored Query (POST) - OAUTH Admin User Creds + ${resp_query} POST /query/{qualified_query_name}/{version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp_query['q']} ${initial_query} + +10. Execute Ad-Hoc Query - OAUTH Admin User Creds + Set Test Variable ${test_data} {"q":"${initial_query}"} + Send Ad Hoc Request aql_body=${test_data} + +11. Admin Delete Composition - OAUTH Admin User Creds + Set Test Variable ${versioned_object_uid} ${compo_id} + (admin) delete composition + +12. Admin Delete Stored Query - OAUTH Admin User Creds + (admin) delete stored query ${resp_qualified_query_name_version} + [Teardown] (admin) delete ehr + + +*** Keywords *** +Request Access Token + [Arguments] ${grant} + Create Session keycloak ${KEYCLOAK_URL} verify=${False} debug=3 + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded + ${resp}= R.POST On Session keycloak /realms/ehrbase/protocol/openid-connect/token + ... expected_status=anything + ... data=${grant} headers=${headers} + Set Test Variable ${resp} ${resp} + dictionary should contain key ${resp.json()} access_token + Set Suite Variable ${password_access_token} ${resp.json()['access_token']} + diff --git a/tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_normal_user.robot b/tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_normal_user.robot new file mode 100644 index 00000000..4049e84d --- /dev/null +++ b/tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_normal_user.robot @@ -0,0 +1,117 @@ +*** Settings *** +Documentation Authentication Type Tests +... \nRun with AUTH_TYPE=OAUTH only +... \nhttps://vitagroup-ag.atlassian.net/browse/CDR-1401 + +Resource ../../_resources/keywords/composition_keywords.robot +Resource ../../_resources/keywords/admin_keywords.robot +Resource ../../_resources/keywords/aql_query_keywords.robot +Resource ../../_resources/keywords/aql_keywords.robot + +Suite Setup Set Library Search Order For Tests + + +*** Variables *** +${SUT} TEST +&{TEMP_OAUTH_ACCESS_GRANT} client_id=ehrbase +... grant_type=password client_secret=bT5T4oWn3xNdBytQsl2cfpBDi1pp15Va +... username=ehrbase-admin password=EvenMoreSecretPassword1! +## the same configuration as in sut_config.py, ADMIN_TEST_CONFIG + + +*** Test Cases *** +1. Keycloak OAuth server is online - OAUTH Normal User + [Documentation] Checks that Keycloak server is up and ready. + ${loggedvars} Log Variables + Create Session keycloak ${KEYCLOAK_URL} + ${resp} R.Get On Session keycloak / + Should Be Equal As Strings ${resp.status_code} 200 + Should Be Equal ${OAUTH_ACCESS_GRANT['username']} ehrbase-user + +2. ehrbase realm exists - OAUTH Normal User + ${resp} R.Get On Session keycloak /realms/ehrbase + Status Should Be 200 + Should Be Equal ${resp.json()["realm"]} ehrbase + Log Token service URL: ${resp.json()["token-service"]} console=yes + +3. Test Get Token - OAUTH Normal User + Request Access Token ${OAUTH_ACCESS_GRANT} + Status Should Be 200 + +4. Upload Template - OAUTH Normal User Creds + &{authorization} Create Dictionary + ... Authorization=Bearer ${password_access_token} + Set Suite Variable ${authorization} ${authorization} + Upload OPT nested/nested.opt + @{accepted_template_status_codes} Create List ${201} ${204} ${409} + List Should Contain Value ${accepted_template_status_codes} ${response_code} + +5. Create EHR - OAUTH Normal User Creds + prepare new request session JSON Prefer=return=representation + create new EHR with ehr_status ${VALID EHR DATA SETS}/000_ehr_status_with_other_details.json + Should Be Equal ${resp.status_code} ${201} + Log ${ehr_id} + +6. Create Composition - OAUTH Normal User Creds + prepare new request session JSON Prefer=return=representation + commit composition format=CANONICAL_JSON + ... composition=nested.en.v1__full_without_links.json + Should Be Equal ${response.status_code} ${201} + check the successful result of commit composition + @{compo_uid_splitted} Split String ${composition_uid} :: + Set Suite Variable ${compo_id} ${compo_uid_splitted}[0] + +7. Store Query - OAUTH Normal User Creds + ${query} Catenate + ... SELECT c/uid/value AS COMPOSITION_UID_VALUE + ... FROM EHR e + ... CONTAINS COMPOSITION c + ... WHERE e/ehr_id/value = '${ehr_id}' + Set Suite Variable ${initial_query} ${query} + ${resp_qualified_query_name_version} PUT /definition/query/{qualified_query_name}/{version} + ... query_to_store=${query} format=text + Set Suite Variable ${resp_qualified_query_name_version} ${resp_qualified_query_name_version} + +8. GET Stored Query - OAUTH Normal User Creds + ${resp_query} GET /definition/query/{qualified_query_name} / including {version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp['q']} ${initial_query} + +9. Execute Stored Query (POST) - OAUTH Normal User Creds + ${resp_query} POST /query/{qualified_query_name}/{version} + ... qualif_name=${resp_qualified_query_name_version} + Should Be Equal As Strings ${resp_query['q']} ${initial_query} + +10. Execute Ad-Hoc Query - OAUTH Normal User Creds + Set Test Variable ${test_data} {"q":"${initial_query}"} + Send Ad Hoc Request aql_body=${test_data} + +11. Admin Delete Composition - OAUTH Normal User Creds + Set Test Variable ${versioned_object_uid} ${compo_id} + ${err_msg} Run Keyword And Expect Error * + ... (admin) delete composition + Should Contain ${err_msg} Expected status: 403 != 204 + +12. Admin Delete Stored Query - OAUTH Normal User Creds + ${err_msg} Run Keyword And Expect Error * + ... (admin) delete stored query ${resp_qualified_query_name_version} + Should Contain ${err_msg} Expected status: 403 != 200 + Request Access Token ${TEMP_OAUTH_ACCESS_GRANT} + Status Should Be 200 + &{authorization} Create Dictionary + ... Authorization=Bearer ${password_access_token} + Set Suite Variable ${authorization} ${authorization} + [Teardown] (admin) delete ehr + + +*** Keywords *** +Request Access Token + [Arguments] ${grant} + Create Session keycloak ${KEYCLOAK_URL} verify=${False} debug=3 + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded + ${resp}= R.POST On Session keycloak /realms/ehrbase/protocol/openid-connect/token + ... expected_status=anything + ... data=${grant} headers=${headers} + Set Test Variable ${resp} ${resp} + dictionary should contain key ${resp.json()} access_token + Set Suite Variable ${password_access_token} ${resp.json()['access_token']} diff --git a/tests/robot/_resources/keywords/admin_keywords.robot b/tests/robot/_resources/keywords/admin_keywords.robot index 35b47139..1bc5eadc 100644 --- a/tests/robot/_resources/keywords/admin_keywords.robot +++ b/tests/robot/_resources/keywords/admin_keywords.robot @@ -31,6 +31,9 @@ Resource template_opt1.4_keywords.robot IF '${multitenancy_token}' != '${None}' Set To Dictionary ${headers} Authorization=Bearer ${multitenancy_token} END + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${ADMIN_BASEURL} debug=2 ... verify=False #auth=${CREDENTIALS} ${resp} DELETE On session ${SUT} /ehr/${ehr_id} @@ -97,6 +100,9 @@ Resource template_opt1.4_keywords.robot IF '${multitenancy_token}' != '${None}' Set To Dictionary ${headers} Authorization=Bearer ${multitenancy_token} END + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${ADMIN_BASEURL} debug=2 ... verify=False ${resp} DELETE On Session ${SUT} /ehr/${ehr_id}/composition/${versioned_object_uid} @@ -104,6 +110,18 @@ Resource template_opt1.4_keywords.robot Status Should Be 204 Set Test Variable ${response} ${resp} +(admin) delete stored query + [Documentation] Admin delete of Stored Query (by qualified_verion or qualified_verion/id). + [Arguments] ${qualif_name} + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END + Create Session ${SUT} ${ADMIN_BASEURL} debug=2 + ... verify=False + ${resp} DELETE On Session ${SUT} /query/${qualif_name} + ... expected_status=anything headers=${headers} + Status Should Be 200 + Set Test Variable ${response} ${resp} Delete Composition Using API IF '${versioned_object_uid}' != '${None}' diff --git a/tests/robot/_resources/keywords/aql_keywords.robot b/tests/robot/_resources/keywords/aql_keywords.robot index bec20857..731312a6 100644 --- a/tests/robot/_resources/keywords/aql_keywords.robot +++ b/tests/robot/_resources/keywords/aql_keywords.robot @@ -100,6 +100,9 @@ Send Ad Hoc Request ELSE &{headers} Create Dictionary Content-Type=application/json END + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} ... debug=2 headers=${headers} verify=True ${resp} POST On Session ${SUT} /query/aql expected_status=anything diff --git a/tests/robot/_resources/keywords/aql_query_keywords.robot b/tests/robot/_resources/keywords/aql_query_keywords.robot index 4f7fc73c..7c9906ae 100644 --- a/tests/robot/_resources/keywords/aql_query_keywords.robot +++ b/tests/robot/_resources/keywords/aql_query_keywords.robot @@ -279,11 +279,15 @@ PUT /definition/query/{qualified_query_name} ... Returns combination of qualified_query_name and version, in format ... {random_query_qualified_name}/{random_query_version} [Arguments] ${query_to_store} ${format}=json ${multitenancy_token}=${None} + &{headers} Create Dictionary + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END IF '${format}' == 'json' - &{headers} Create Dictionary Content-Type=application/json + Set To Dictionary ${headers} Content-Type=application/json ${query} Set Variable {"q":"${query_to_store}"} ELSE IF '${format}' == 'text' - &{headers} Create Dictionary Content-Type=text/plain + Set To Dictionary ${headers} Content-Type=text/plain ${query} Set Variable ${query_to_store} END IF '${multitenancy_token}' != '${None}' @@ -316,11 +320,15 @@ PUT /definition/query/{qualified_query_name}/{version} ... Returns combination of qualified_query_name and version, in format ... {random_query_qualified_name}/{random_query_version} [Arguments] ${query_to_store} ${format}=json ${multitenancy_token}=${None} + &{headers} Create Dictionary + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END IF '${format}' == 'json' - &{headers} Create Dictionary Content-Type=application/json + Set To Dictionary ${headers} Content-Type=application/json ${query} Set Variable {"q":"${query_to_store}"} ELSE IF '${format}' == 'text' - &{headers} Create Dictionary Content-Type=text/plain + Set To Dictionary ${headers} Content-Type=text/plain ${query} Set Variable ${query_to_store} END IF '${multitenancy_token}' != '${None}' @@ -349,6 +357,9 @@ GET /definition/query/{qualified_query_name} / including {version} ... Returns {resp_query}, query from response. [Arguments] ${qualif_name} ${multitenancy_token}=${None} &{headers} Create Dictionary Content-Type=application/json + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 IF '${multitenancy_token}' != '${None}' Set To Dictionary ${headers} Authorization=Bearer ${multitenancy_token} @@ -370,6 +381,9 @@ GET /definition/query [Documentation] List all stored AQL from EHRBase. ... Expected status code 200. &{headers} Create Dictionary Content-Type=application/json + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 ${resp} GET On Session ${SUT} ... /definition/query @@ -384,6 +398,9 @@ DELETE /definition/query/{qualified_query_name}/{version} ... Expected status code 405 - endpoint available operations PUT, GET only. [Arguments] ${qualif_name} &{headers} Create Dictionary Content-Type=application/json + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 ${resp} DELETE On Session ${SUT} ... /definition/query/${qualif_name} @@ -514,6 +531,9 @@ GET /query/{qualified_query_name} ELSE &{headers} Create Dictionary Content-Type=application/json END + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 IF """${params}""" == """${FALSE}""" ${resp} GET On Session ${SUT} @@ -544,6 +564,9 @@ POST /query/{qualified_query_name} ELSE &{headers} Create Dictionary Content-Type=application/json END + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 ${resp} POST On Session ${SUT} ... /query/${qualif_name} @@ -572,6 +595,9 @@ GET /query/{qualified_query_name}/{version} ... Returns {resp}, with query and rows from response. [Arguments] ${qualif_name} &{params}=${FALSE} &{headers} Create Dictionary Content-Type=application/json + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 IF """${params}""" == """${FALSE}""" ${resp} GET On Session ${SUT} @@ -598,6 +624,9 @@ POST /query/{qualified_query_name}/{version} ... Returns {resp}, with query and rows from response. [Arguments] ${qualif_name} &{headers} Create Dictionary Content-Type=application/json + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${BASEURL} debug=2 ${resp} POST On Session ${SUT} ... /query/${qualif_name} @@ -614,6 +643,9 @@ DELETE /query/{qualified_query_name}/{version} ADMIN ... Expected status code . [Arguments] ${qualif_name} &{headers} Create Dictionary Content-Type=application/json + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END Create Session ${SUT} ${ADMIN_BASEURL} debug=2 ${resp} DELETE On Session ${SUT} ... /query/${qualif_name} diff --git a/tests/robot/_resources/keywords/composition_keywords.robot b/tests/robot/_resources/keywords/composition_keywords.robot index 3fe05322..52c17c1c 100644 --- a/tests/robot/_resources/keywords/composition_keywords.robot +++ b/tests/robot/_resources/keywords/composition_keywords.robot @@ -310,6 +310,9 @@ commit composition &{headers}= Create Dictionary Prefer=return=${prefer} ... openEHR-VERSION.lifecycle_state=${lifecycle} + IF '${AUTH_TYPE}' == 'BASIC' or '${AUTH_TYPE}' == 'OAUTH' + Set To Dictionary ${headers} &{authorization} + END IF '${multitenancy_token}' != '${None}' Set To Dictionary ${headers} @@ -589,6 +592,9 @@ update composition (FLAT) &{headers}= Create Dictionary Content-Type=application/json ... Accept=application/json ... Prefer=return=representation + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END &{params}= Create Dictionary format=FLAT ehrId=${ehr_id} templateId=${template_id} @@ -815,6 +821,9 @@ Get Web Template By Template Id (ECIS) Create Session ${SUT} ${ECISURL} debug=2 ... verify=False #auth=${CREDENTIALS} &{headers} Create Dictionary + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END IF '${multitenancy_token}' != '${None}' Set To Dictionary ${headers} Authorization=Bearer ${multitenancy_token} END @@ -847,6 +856,9 @@ Get Example Of Web Template By Template Id (ECIS) ${headers} Create Dictionary Accept=application/json ... Content-Type=application/xml ... Prefer=return=representation + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END IF '${responseFormat}' != 'FLAT' ${resp} GET On Session ${SUT} ... template/${template_id}/example expected_status=anything headers=${headers} @@ -868,14 +880,18 @@ Get Example Of Web Template By Template Id (OPENEHR) ${headers} Create Dictionary Accept=application/json ... Content-Type=application/xml ... Prefer=return=representation + IF '${AUTH_TYPE}' == 'BASIC' + Set To Dictionary ${headers} &{authorization} + END IF '${responseFormat}' == 'JSON' ${resp} GET On Session ${SUT} ... definition/template/adl1.4/${template_id}/example expected_status=anything ... headers=${headers} params=${params} ELSE IF '${responseFormat}' == 'XML' - ${headers} Create Dictionary Accept=application/xml - ... Content-Type=application/xml - ... Prefer=return=representation + Set To Dictionary ${headers} + ... Accept=application/xml + ... Content-Type=application/xml + ... Prefer=return=representation ${resp} GET On Session ${SUT} ... definition/template/adl1.4/${template_id}/example ... expected_status=anything headers=${headers} diff --git a/tests/robot/_resources/variables/get_global_configs.py b/tests/robot/_resources/variables/get_global_configs.py index c3a4f057..96245d52 100644 --- a/tests/robot/_resources/variables/get_global_configs.py +++ b/tests/robot/_resources/variables/get_global_configs.py @@ -7,6 +7,7 @@ def get_variables(): yaml_content = yaml.safe_load(file) port = yaml_content['GLOBAL_PORT'] ehrbase_baseurl = os.environ.get('EHRBASE_BASE_URL', f'http://localhost:{port}') + keycloak_baseurl = os.environ.get('KEYCLOAK_BASE_URL', f'http://localhost:8081') json_obj = \ { "GLOBAL_PORT": port, @@ -16,6 +17,7 @@ def get_variables(): "HEARTBEAT_URL": os.environ.get('HEARTBEAT_URL', f'{ehrbase_baseurl}/ehrbase/rest/status'), "PLUGIN_URL": os.environ.get('PLUGIN_URL', f'{ehrbase_baseurl}/ehrbase/plugin'), "RABBITMQ_URL": os.environ.get('RABBITMQ_URL', "http://127.0.0.1:15672/api"), - "KAFKA_URL": os.environ.get('KAFKA_URL', "http://127.0.0.1:8082") + "KAFKA_URL": os.environ.get('KAFKA_URL', "http://127.0.0.1:8082"), + "KEYCLOAK_URL": os.environ.get('KEYCLOAK_URL', f'{keycloak_baseurl}/auth') } return json_obj \ No newline at end of file diff --git a/tests/robot/_resources/variables/sut_config.py b/tests/robot/_resources/variables/sut_config.py index 4cbe0dae..c13d7868 100644 --- a/tests/robot/_resources/variables/sut_config.py +++ b/tests/robot/_resources/variables/sut_config.py @@ -26,11 +26,12 @@ PLUGIN_URL_FROM_YAML = GLOBAL_VARS_FROM_YAML_FUNC["PLUGIN_URL"] RABBITMQ_URL_FROM_YAML = GLOBAL_VARS_FROM_YAML_FUNC["RABBITMQ_URL"] KAFKA_URL_FROM_YAML = GLOBAL_VARS_FROM_YAML_FUNC["KAFKA_URL"] +KEYCLOAK_URL_FROM_YAML = GLOBAL_VARS_FROM_YAML_FUNC["KEYCLOAK_URL"] # KEYCLOAK SETTINGS HEADER = {"Content-Type": "application/x-www-form-urlencoded"} -KEYCLOAK_URL = "http://localhost:8081/auth" +KEYCLOAK_URL = KEYCLOAK_URL_FROM_YAML KC_AUTH_URL = KEYCLOAK_URL + "/realms/ehrbase/protocol/openid-connect/auth" KC_ACCESS_TOKEN_URL = KEYCLOAK_URL + "/realms/ehrbase/protocol/openid-connect/token" KC_JWT_ISSUERURI = KEYCLOAK_URL + "/realms/ehrbase" @@ -145,11 +146,11 @@ "NODENAME": "local.ehrbase.org", # alias CREATING_SYSTEM_ID "CONTROL_MODE": "docker", "OAUTH_ACCESS_GRANT": { - "client_id": "ehrbase-robot", - "scope": "openid", - "username": "robot", - "password": "robot", + "client_id": "ehrbase", "grant_type": "password", + "client_secret": "bT5T4oWn3xNdBytQsl2cfpBDi1pp15Va", + "username": "ehrbase-user", + "password": "SuperSecretPassword1!" }, "JWT_ISSUERURI": KC_JWT_ISSUERURI, "OAUTH_NAME": "Robot Framework", @@ -180,11 +181,11 @@ "NODENAME": "local.ehrbase.org", # alias CREATING_SYSTEM_ID "CONTROL_MODE": "docker", "OAUTH_ACCESS_GRANT": { - "client_id": "ehrbase-robot", - "scope": "openid", - "username": "admin-robot", # TODO: recreate exported-keycloak-config to have this user! - "password": "admin-robot", # check README.md in SECURITY_TESTS folder for how to + "client_id": "ehrbase", "grant_type": "password", + "client_secret": "bT5T4oWn3xNdBytQsl2cfpBDi1pp15Va", + "username": "ehrbase-admin", + "password": "EvenMoreSecretPassword1!" }, "JWT_ISSUERURI": KC_JWT_ISSUERURI, "OAUTH_NAME": "Admin Robot Framework",