Skip to content

Commit 4fb9cba

Browse files
Update multiTenancyDeploy.yml
1 parent 68947d1 commit 4fb9cba

1 file changed

Lines changed: 155 additions & 1 deletion

File tree

.github/workflows/multiTenancyDeploy.yml

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
default: 'developcap'
1010

1111
jobs:
12-
build:
12+
deploy:
1313
runs-on: ubuntu-latest
1414

1515
steps:
@@ -71,3 +71,157 @@ jobs:
7171
ls -lrth
7272
echo "Running cf deploy"
7373
cf deploy mta_archives/bookshop-mt_1.0.0.mtar -f
74+
75+
integration-test:
76+
needs: deploy
77+
runs-on: ubuntu-latest
78+
79+
steps:
80+
- name: Checkout repository
81+
uses: actions/checkout@v2
82+
83+
- name: Set up Java 17
84+
uses: actions/setup-java@v3
85+
with:
86+
java-version: 17
87+
distribution: 'temurin'
88+
89+
- name: Install Cloud Foundry CLI and jq
90+
run: |
91+
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
92+
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
93+
sudo apt-get update
94+
sudo apt-get install cf8-cli jq
95+
96+
- name: Login to Cloud Foundry
97+
run: |
98+
cf login -a ${{ secrets.CF_API }} \
99+
-u ${{ secrets.CF_USER }} \
100+
-p ${{ secrets.CF_PASSWORD }} \
101+
-o ${{ secrets.CF_ORG }} \
102+
-s ${{ secrets.CF_SPACE }}
103+
- name: Fetch and Escape Client Details for single tenant
104+
id: fetch_credentials
105+
run: |
106+
service_instance_guid=$(cf service demoappjava-public-uaa --guid)
107+
if [ -z "$service_instance_guid" ]; then
108+
echo "Error: Unable to retrieve service instance GUID"; exit 1;
109+
fi
110+
111+
bindings_response=$(cf curl "/v3/service_credential_bindings?service_instance_guids=${service_instance_guid}")
112+
binding_guid=$(echo $bindings_response | jq -r '.resources[0].guid')
113+
if [ -z "$binding_guid" ]; then
114+
echo "Error: Unable to retrieve binding GUID"; exit 1;
115+
fi
116+
117+
binding_details=$(cf curl "/v3/service_credential_bindings/${binding_guid}/details")
118+
119+
clientSecret=$(echo "$binding_details" | jq -r '.credentials.clientsecret')
120+
if [ -z "$clientSecret" ] || [ "$clientSecret" == "null" ]; then
121+
echo "Error: clientSecret is not set or is null"; exit 1;
122+
fi
123+
escapedClientSecret=$(echo "$clientSecret" | sed 's/\$/\\$/g')
124+
125+
clientID=$(echo "$binding_details" | jq -r '.credentials.clientid')
126+
if [ -z "$clientID" ] || [ "$clientID" == "null" ]; then
127+
echo "Error: clientID is not set or is null"; exit 1;
128+
fi
129+
130+
echo "::set-output name=CLIENT_SECRET::$escapedClientSecret"
131+
echo "::set-output name=CLIENT_ID::$clientID"
132+
- name: Fetch and Escape Client Details for multi tenant
133+
id: fetch_credentials_mt
134+
run: |
135+
service_instance_guid=$(cf service bookshop-mt-uaa --guid)
136+
if [ -z "$service_instance_guid" ]; then
137+
echo "Error: Unable to retrieve service instance GUID"; exit 1;
138+
fi
139+
140+
bindings_response=$(cf curl "/v3/service_credential_bindings?service_instance_guids=${service_instance_guid}")
141+
binding_guid=$(echo $bindings_response | jq -r '.resources[0].guid')
142+
if [ -z "$binding_guid" ]; then
143+
echo "Error: Unable to retrieve binding GUID"; exit 1;
144+
fi
145+
146+
binding_details=$(cf curl "/v3/service_credential_bindings/${binding_guid}/details")
147+
148+
clientSecret_mt=$(echo "$binding_details" | jq -r '.credentials.clientsecret')
149+
if [ -z "$clientSecret_mt" ] || [ "$clientSecret_mt" == "null" ]; then
150+
echo "Error: clientSecret_mt is not set or is null"; exit 1;
151+
fi
152+
escapedClientSecret_mt=$(echo "$clientSecret_mt" | sed 's/\$/\\$/g')
153+
154+
clientID_mt=$(echo "$binding_details" | jq -r '.credentials.clientid')
155+
if [ -z "$clientID_mt" ] || [ "$clientID_mt" == "null" ]; then
156+
echo "Error: clientID_mt is not set or is null"; exit 1;
157+
fi
158+
159+
echo "::set-output name=CLIENT_SECRET_MT::$escapedClientSecret_mt"
160+
echo "::set-output name=CLIENT_ID_MT::$clientID_mt"
161+
162+
163+
- name: Run integration tests
164+
env:
165+
CLIENT_SECRET: ${{ steps.fetch_credentials.outputs.CLIENT_SECRET }}
166+
CLIENT_ID: ${{ steps.fetch_credentials.outputs.CLIENT_ID }}
167+
CLIENT_SECRET_MT: ${{ steps.fetch_credentials_mt.outputs.CLIENT_SECRET_MT }}
168+
CLIENT_ID_MT: ${{ steps.fetch_credentials_mt.outputs.CLIENT_ID_MT }}
169+
run: |
170+
set -e
171+
PROPERTIES_FILE="sdm/src/test/resources/credentials.properties"
172+
appUrl="${{ secrets.CF_ORG }}-${{ secrets.CF_SPACE }}-demoappjava-srv.cfapps.eu12.hana.ondemand.com"
173+
appUrlMT="${{ secrets.CF_ORG }}-${{ secrets.CF_SPACE }}-bookshop-mt-srv.cfapps.eu12.hana.ondemand.com"
174+
authUrl="${{ secrets.CAPAUTH_URL }}"
175+
authUrlMT1="${{ secrets.AUTHURLMT1 }}"
176+
authUrlMT2="${{ secrets.AUTHURLMT2 }}"
177+
clientID="${{ env.CLIENT_ID }}"
178+
clientSecret="${{ env.CLIENT_SECRET }}"
179+
clientIDMT="${{ env.CLIENT_ID_MT }}"
180+
clientSecretMT="${{ env.CLIENT_SECRET_MT }}"
181+
username="${{ secrets.CF_USER }}"
182+
password="${{ secrets.CF_PASSWORD }}"
183+
noSDMRoleUsername="${{ secrets.NOSDMROLEUSERNAME }}"
184+
noSDMRoleUserPassword="${{ secrets.NOSDMROLEUSERPASSWORD }}"
185+
if [ -z "$appUrl" ]; then echo "Error: appUrl is not set"; exit 1; fi
186+
if [ -z "$appUrlMT" ]; then echo "Error: appUrlMT is not set"; exit 1; fi
187+
if [ -z "$authUrl" ]; then echo "Error: authUrl is not set"; exit 1; fi
188+
if [ -z "$authUrlMT1" ]; then echo "Error: authUrlMT1 is not set"; exit 1; fi
189+
if [ -z "$authUrlMT2" ]; then echo "Error: authUrlMT2 is not set"; exit 1; fi
190+
if [ -z "$clientID" ]; then echo "Error: clientID is not set"; exit 1; fi
191+
if [ -z "$clientSecret" ]; then echo "Error: clientSecret is not set"; exit 1; fi
192+
if [ -z "$clientIDMT" ]; then echo "Error: clientIDMT is not set"; exit 1; fi
193+
if [ -z "$clientSecretMT" ]; then echo "Error: clientSecretMT is not set"; exit 1; fi
194+
if [ -z "$username" ]; then echo "Error: username is not set"; exit 1; fi
195+
if [ -z "$password" ]; then echo "Error: password is not set"; exit 1; fi
196+
if [ -z "$noSDMRoleUsername" ]; then echo "Error: noSDMRoleUsername is not set"; exit 1; fi
197+
if [ -z "$noSDMRoleUserPassword" ]; then echo "Error: noSDMRoleUserPassword is not set"; exit 1; fi
198+
mask() {
199+
local value="$1"
200+
if [ ${#value} -gt 6 ]; then
201+
echo "${value:0:3}*****${value: -3}"
202+
else
203+
echo "${value:0:2}*****"
204+
fi
205+
}
206+
cat > "$PROPERTIES_FILE" <<EOL
207+
appUrl=$appUrl
208+
appUrlMT=$appUrlMT
209+
authUrl=$authUrl
210+
authUrlMT1=$authUrlMT1
211+
authUrlMT2=$authUrlMT2
212+
clientID=$clientID
213+
clientSecret=$clientSecret
214+
clientIDMT=$clientIDMT
215+
clientSecretMT=$clientSecretMT
216+
username=$username
217+
password=$password
218+
noSDMRoleUsername=$noSDMRoleUsername
219+
noSDMRoleUserPassword=$noSDMRoleUserPassword
220+
EOL
221+
# Run Maven integration tests
222+
# mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=single -DskipUnitTests || { echo "Maven tests failed for Technical User Flow"; exit 1; }
223+
# mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=single -DskipUnitTests || { echo "Maven tests failed for Named User Flow"; exit 1; }
224+
mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=multi -Dtenant=TENANT1 -DskipUnitTests
225+
mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=multi -Dtenant=TENANT1 -DskipUnitTests
226+
mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=multi -Dtenant=TENANT2 -DskipUnitTests
227+
mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=multi -Dtenant=TENANT2 -DskipUnitTests

0 commit comments

Comments
 (0)