Skip to content

Update multi tenancy_Integration.yml #17

Update multi tenancy_Integration.yml

Update multi tenancy_Integration.yml #17

name: Multi Tenancy Integration Test
on:
push:
branches:
- multiTenancy_IntegrationTest
workflow_dispatch:
inputs:
cf_space:
description: 'Specify the Cloud Foundry space to run integration tests on'
required: true
default: developcap
branch_name:
description: 'Specify the branch to use for integration tests'
required: true
default: develop
jobs:
integration-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch_name }}
- name: Set up Java 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Install Cloud Foundry CLI and jq
run: |
echo -e "\033[36m🔧 Installing Cloud Foundry CLI and jq...\033[0m"
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt-get update
sudo apt-get install -y cf8-cli jq
echo -e "\033[32m✔️ Installation complete!\033[0m"
- name: Determine Cloud Foundry Space
id: determine_space
run: |
if [ "${{ github.event.inputs.cf_space }}" == "developcap" ]; then
space="${{ secrets.CF_SPACE }}"
else
space="${{ github.event.inputs.cf_space }}"
fi
echo -e "\033[34m🌐 Space determined: \033[1m$space\033[22m\033[0m"
echo "::set-output name=space::$space"
- name: Login to Cloud Foundry
run: |
echo -e "\033[36m🔑 Logging in to Cloud Foundry...\033[0m"
cf login -a ${{ secrets.CF_API }} \
-u ${{ secrets.CF_USER }} \
-p ${{ secrets.CF_PASSWORD }} \
-o ${{ secrets.CF_ORG }} \
-s ${{ secrets.CF_SPACE }}
# -s ${{ steps.determine_space.outputs.space }}
echo -e "\033[32m✔️ Login successful!\033[0m"
- name: Fetch and Escape Client Details for single tenant
id: fetch_credentials
run: |
echo -e "\033[36m🚀 Fetching Client Details for Single Tenant...\033[0m"
service_instance_guid=$(cf service demoappjava-public-uaa --guid)
if [ -z "$service_instance_guid" ]; then
echo -e "\033[31m❌ Error: Unable to retrieve service instance GUID\033[0m"
exit 1
fi
bindings_response=$(cf curl "/v3/service_credential_bindings?service_instance_guids=${service_instance_guid}")
binding_guid=$(echo $bindings_response | jq -r '.resources[0].guid')
if [ -z "$binding_guid" ]; then
echo -e "\033[31m❌ Error: Unable to retrieve binding GUID\033[0m"
exit 1
fi
binding_details=$(cf curl "/v3/service_credential_bindings/${binding_guid}/details")
clientSecret=$(echo "$binding_details" | jq -r '.credentials.clientsecret')
if [ -z "$clientSecret" ] || [ "$clientSecret" == "null" ]; then
echo -e "\033[31m❌ Error: clientSecret is not set or is null\033[0m"
exit 1
fi
escapedClientSecret=$(echo "$clientSecret" | sed 's/\$/\\$/g')
clientID=$(echo "$binding_details" | jq -r '.credentials.clientid')
if [ -z "$clientID" ] || [ "$clientID" == "null" ]; then
echo -e "\033[31m❌ Error: clientID is not set or is null\033[0m"
exit 1
fi
echo "::set-output name=CLIENT_SECRET::$escapedClientSecret"
echo "::set-output name=CLIENT_ID::$clientID"
echo -e "\033[32m✔️ Client Details fetched successfully!\033[0m"
- name: Fetch and Escape Client Details for multi tenant
id: fetch_credentials_mt
run: |
echo -e "\033[36m🚀 Fetching Client Details for Multi Tenant...\033[0m"
service_instance_guid=$(cf service bookshop-mt-uaa --guid)
if [ -z "$service_instance_guid" ]; then
echo -e "\033[31m❌ Error: Unable to retrieve service instance GUID\033[0m"
exit 1
fi
bindings_response=$(cf curl "/v3/service_credential_bindings?service_instance_guids=${service_instance_guid}")
binding_guid=$(echo $bindings_response | jq -r '.resources[0].guid')
if [ -z "$binding_guid" ]; then
echo -e "\033[31m❌ Error: Unable to retrieve binding GUID\033[0m"
exit 1
fi
binding_details=$(cf curl "/v3/service_credential_bindings/${binding_guid}/details")
clientSecret_mt=$(echo "$binding_details" | jq -r '.credentials.clientsecret')
if [ -z "$clientSecret_mt" ] || [ "$clientSecret_mt" == "null" ]; then
echo -e "\033[31m❌ Error: clientSecret_mt is not set or is null\033[0m"
exit 1
fi
escapedClientSecret_mt=$(echo "$clientSecret_mt" | sed 's/\$/\\$/g')
clientID_mt=$(echo "$binding_details" | jq -r '.credentials.clientid')
if [ -z "$clientID_mt" ] || [ "$clientID_mt" == "null" ]; then
echo -e "\033[31m❌ Error: clientID_mt is not set or is null\033[0m"
exit 1
fi
echo "::set-output name=CLIENT_SECRET_MT::$escapedClientSecret_mt"
echo "::set-output name=CLIENT_ID_MT::$clientID_mt"
echo -e "\033[32m✔️ Multi Tenant Client Details fetched successfully!\033[0m"
- name: Run integration tests
env:
CLIENT_SECRET: ${{ steps.fetch_credentials.outputs.CLIENT_SECRET }}
CLIENT_ID: ${{ steps.fetch_credentials.outputs.CLIENT_ID }}
CLIENT_SECRET_MT: ${{ steps.fetch_credentials_mt.outputs.CLIENT_SECRET_MT }}
CLIENT_ID_MT: ${{ steps.fetch_credentials_mt.outputs.CLIENT_ID_MT }}
run: |
echo -e "\033[36m🧪 Running Integration Tests...\033[0m"
set -e
PROPERTIES_FILE="sdm/src/test/resources/credentials.properties"
appUrl="${{ secrets.CF_ORG }}-${{ secrets.CF_SPACE }}-demoappjava-srv.cfapps.eu12.hana.ondemand.com"
appUrlMT="${{ secrets.CF_ORG }}-${{ secrets.CF_SPACE }}-bookshop-mt-srv.cfapps.eu12.hana.ondemand.com"
authUrl="${{ secrets.CAPAUTH_URL }}"
authUrlMT1="${{ secrets.AUTHURLMT1 }}"
authUrlMT2="${{ secrets.AUTHURLMT2 }}"
clientID="<hidden>"
clientSecret="<hidden>"
clientIDMT="<hidden>"
clientSecretMT="<hidden>"
username="${{ secrets.CF_USER }}"
password="<hidden>"
noSDMRoleUsername="${{ secrets.NOSDMROLEUSERNAME }}"
noSDMRoleUserPassword="<hidden>"
# Check if variables are set before using them
for var in appUrl appUrlMT authUrl authUrlMT1 authUrlMT2 username password noSDMRoleUsername noSDMRoleUserPassword; do
if [ -z "${!var}" ]; then
echo -e "\033[31m❌ Error: ${var} is not set\033[0m"
exit 1
fi
done
cat > "$PROPERTIES_FILE" <<EOL
appUrl=$appUrl
appUrlMT=$appUrlMT
authUrl=$authUrl
authUrlMT1=$authUrlMT1
authUrlMT2=$authUrlMT2
clientID=$clientID
clientSecret=$clientSecret
clientIDMT=$clientIDMT
clientSecretMT=$clientSecretMT
username=$username
password=$password
noSDMRoleUsername=$noSDMRoleUsername
noSDMRoleUserPassword=$noSDMRoleUserPassword
EOL
# Display properties file without sensitive information
echo -e "\033[34m📜 Properties File:\033[0m"
cat "$PROPERTIES_FILE" | grep -v -e "clientID=" -e "clientSecret=" -e "password=" -e "clientIDMT=" -e "clientSecretMT=" -e "noSDMRoleUserPassword="
# Run Maven integration tests
echo -e "\033[34m🧪 Running Maven tests for Multi Tenancy...\033[0m"
mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=multi -Dtenant=TENANT1 -DskipUnitTests || { echo -e "\033[31m❌ Maven tests failed for Named User Flow (Multi Tenancy, Tenant 1)\033[0m"; exit 1; }
# mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=multi -Dtenant=TENANT1 -DskipUnitTests || { echo -e "\033[31m❌ Maven tests failed for Technical User Flow (Multi Tenancy, Tenant 1)\033[0m"; exit 1; }
# mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=multi -Dtenant=TENANT2 -DskipUnitTests || { echo -e "\033[31m❌ Maven tests failed for Named User Flow (Multi Tenancy, Tenant 2)\033[0m"; exit 1; }
# mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=multi -Dtenant=TENANT2 -DskipUnitTests || { echo -e "\033[31m❌ Maven tests failed for Technical User Flow (Multi Tenancy, Tenant 2)\033[0m"; exit 1; }
echo -e "\033[32m✔️ Integration tests completed successfully!\033[0m"