Skip to content

Commit

Permalink
CDR-1401 Add Robot tests to check BASIC and OAUTH auth types (#22)
Browse files Browse the repository at this point in the history
* feat: CDR-1401 include env var to send the AUTH_TYPE to robot cmd

* fix: CDR-1401 send AUTH_TYPE value through env var

* fix: CDR-1401 pass correctly the env var value to AUTH_TYPE

* fix: CDR-1401 test pipeline with AUTH_TYPE

* fix: CDR-1401 wrong positional arg fix

* fix: CDR-1401 display robot cmd for debug

* feat: CDR-1401 add Robot tests to check cases with BASIC AUTH_TYPE and normal,admin user creds

* feat: CDR-1401 add Robot tests for OAUTH cases

* fix: CDR-1401 set ADMIN creds to last 2 cases as when running with SUT=TEST, these are failing

* fix: CDR-1401 rename test suites

* fix: CDR-1401 add KEYCLOAK_URL to robot command

* fix: CDR-1401 add NODOCKER:false to Robot command

* fix: CDR-1401 adjust value for NODOCKER var

* fix: CDR-1401 remove BASEURL and KEYCLOAK_URL from robot command

* fix: CDR-1401 restore KEYCLOAK_URL and BASEURL

* fix: CDR-1401 provide default keycloakBase

* fix: CDR-1401 provide default keycloakBase

* fix: CDR-1401 replace localhost with keycloak in KEYCLOAK_URL

* fix: CDR-1401 change keycloak port to 8080

* fix: CDR-1401 adjust tests for OAUTH

* fix: CDR-1401 change keycloak_url to http://localhost:8081/auth

* fix: CDR-1401 fix KEYCLOAK_URL

* fix: CDR-1401 adjust runRobotTest keycloak port

* fix: change KEYCLOAK_BASE_URL

* fix: CDR-1401 change KEYCLOAK_BASE_URL

* fix: CDR-1401 change KEYCLOAK_BASE_URL

* fix: CDR-1401 change KEYCLOAK_BASE_URL

* fix: adjust port for KEYCLOAK_BASE_URL

* fix: change KEYCLOAK_BASE_URL:-http://keycloak:8081

* fix: CDR-1401 set env to BASIC if arg is set to NONE

* fix: CDR-1401 set env to BASIC if arg is set to NONE - prior to echo vars

* fix: CDR-1401 rename Keycloak realm and client
  • Loading branch information
vladislavploaia authored Jun 6, 2024
1 parent b2f4dc0 commit fd21e8e
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 19 deletions.
49 changes: 47 additions & 2 deletions scripts/runRobotTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=()

############################################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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}
13 changes: 13 additions & 0 deletions tests/robot/AUTH_TYPE_TESTS/BASIC/__init__.robot
Original file line number Diff line number Diff line change
@@ -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
75 changes: 75 additions & 0 deletions tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_admin_user.robot
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions tests/robot/AUTH_TYPE_TESTS/BASIC/suite_with_normal_user.robot
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/robot/AUTH_TYPE_TESTS/OAUTH/__init__.robot
Original file line number Diff line number Diff line change
@@ -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
109 changes: 109 additions & 0 deletions tests/robot/AUTH_TYPE_TESTS/OAUTH/suite_with_oauth_admin_user.robot
Original file line number Diff line number Diff line change
@@ -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']}

Loading

0 comments on commit fd21e8e

Please sign in to comment.