Skip to content

Commit b441c6e

Browse files
try old seed keycloak
1 parent 29740d1 commit b441c6e

File tree

5 files changed

+160
-19
lines changed

5 files changed

+160
-19
lines changed

.github/scripts/end2end/run-e2e-ctst.sh

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,16 @@ kubectl create clusterrolebinding serviceaccounts-cluster-admin \
161161
--clusterrole=cluster-admin \
162162
--group=system:serviceaccounts
163163

164-
# --arg keycloak_host "${OIDC_HOST:-keycloak.zenko.local}" \
165-
# --arg keycloak_realm "${OIDC_REALM:-zenko}" \
166-
167-
# --arg keycloak_username "${OIDC_USERNAME:-storage_manager}" \
168-
# --arg keycloak_password "${OIDC_PASSWORD:-123}" \
169-
# --arg keycloak_client_id "${OIDC_CLIENT_ID:-zenko-ui}" \
170-
171-
172-
# docker run \
173-
# --rm \
174-
# --network=host \
175-
# "${E2E_IMAGE}" /bin/bash \
176-
# -c "SUBDOMAIN=${SUBDOMAIN} CONTROL_PLANE_INGRESS_ENDPOINT=${OIDC_ENDPOINT} ACCOUNT=${ZENKO_ACCOUNT_NAME} KEYCLOAK_REALM=${KEYCLOAK_TEST_REALM_NAME} STORAGE_MANAGER=${STORAGE_MANAGER_USER_NAME} STORAGE_ACCOUNT_OWNER=${STORAGE_ACCOUNT_OWNER_USER_NAME} DATA_CONSUMER=${DATA_CONSUMER_USER_NAME} DATA_ACCESSOR=${DATA_ACCESSOR_USER_NAME} /ctst/node_modules/cli-testing/bin/seedKeycloak.sh"; [[ $? -eq 1 ]] && exit 1 || echo 'Keycloak Configured!'
164+
SUBDOMAIN=${SUBDOMAIN} \
165+
CONTROL_PLANE_INGRESS_ENDPOINT=${OIDC_ENDPOINT} \
166+
ACCOUNT=${ZENKO_ACCOUNT_NAME} \
167+
KEYCLOAK_REALM=${KEYCLOAK_TEST_REALM_NAME} \
168+
STORAGE_MANAGER=${STORAGE_MANAGER_USER_NAME} \
169+
STORAGE_ACCOUNT_OWNER=${STORAGE_ACCOUNT_OWNER_USER_NAME} \
170+
DATA_CONSUMER=${DATA_CONSUMER_USER_NAME} \
171+
DATA_ACCESSOR=${DATA_ACCESSOR_USER_NAME} \
172+
bash "$(dirname "$0")/seedKeycloak.sh" || exit 1
173+
echo 'Keycloak Configured!'
177174

178175
# Running end2end ctst tests
179176
# Using overrides as we need to attach a local folder to the pod
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/bash
2+
3+
SUBDOMAIN=${SUBDOMAIN:-"my-company.com"}
4+
CONTROL_PLANE_INGRESS_ENDPOINT=${CONTROL_PLANE_INGRESS_ENDPOINT:-"https://ui.${SUBDOMAIN}"}
5+
ACCOUNT=${ACCOUNT:-"AccountTest"}
6+
URI="${CONTROL_PLANE_INGRESS_ENDPOINT}/auth/admin/realms/${KEYCLOAK_REALM:-"artesca"}"
7+
HEADER="Content-Type: application/json"
8+
STORAGE_MANAGER=${STORAGE_MANAGER:-"storage_manager"}
9+
STORAGE_ACCOUNT_OWNER=${STORAGE_ACCOUNT_OWNER:-"storage_account_owner"}
10+
DATA_CONSUMER=${DATA_CONSUMER:-"data_consumer"}
11+
DATA_ACCESSOR=${DATA_ACCESSOR:-"data_accessor"}
12+
PASSWORD_CONFIGURATION='[{"type":"password","value":"123","temporary":"false"}]'
13+
14+
echo "Request for authorization"
15+
RESULT=`curl -k \
16+
--data "username=${KEYCLOAK_USERNAME:-"admin"}&password=${KEYCLOAK_PASSWORD:-"password"}&grant_type=password&client_id=${KEYCLOAK_CLIENT_ID:-"admin-cli"}" \
17+
${CONTROL_PLANE_INGRESS_ENDPOINT}/auth/realms/master/protocol/openid-connect/token`
18+
[ -z "$RESULT" ] && exit 1
19+
20+
echo "Recovery of the token"
21+
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
22+
23+
echo "Display token"
24+
echo $TOKEN
25+
26+
echo "- Group creation"
27+
28+
curl -k "${URI}/groups" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data '{"name":"'${ACCOUNT}'::StorageAccountOwner"}' || exit 1
29+
curl -k "${URI}/groups" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data '{"name":"'${ACCOUNT}'::DataConsumer"}' || exit 1
30+
curl -k "${URI}/groups" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data '{"name":"'${ACCOUNT}'::DataAccessor"}' || exit 1
31+
32+
echo "- Role creation"
33+
34+
curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data '{"name":"'${ACCOUNT}'::StorageAccountOwner"}' || exit 1
35+
curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data '{"name":"'${ACCOUNT}'::DataConsumer"}' || exit 1
36+
curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data '{"name":"'${ACCOUNT}'::DataAccessor"}' || exit 1
37+
38+
echo "Done"
39+
40+
echo "- User creation"
41+
42+
curl -k "${URI}/users" \
43+
-H "${HEADER}" \
44+
-H "Authorization: bearer $TOKEN" \
45+
--data "{\
46+
\"username\":\"${STORAGE_MANAGER}\",\
47+
\"firstName\":\"${STORAGE_MANAGER}\",\
48+
\"lastName\":\"${STORAGE_MANAGER}\",\
49+
\"email\":\"${STORAGE_MANAGER}@scality.com\",\
50+
\"enabled\":\"true\",\
51+
\"credentials\":${PASSWORD_CONFIGURATION},\
52+
\"realmRoles\":[\"StorageManager\"]}" || exit 1
53+
54+
curl -k "${URI}/users" \
55+
-H "${HEADER}" \
56+
-H "Authorization: bearer $TOKEN" \
57+
--data "{\
58+
\"username\":\"${STORAGE_ACCOUNT_OWNER}\",\
59+
\"firstName\":\"${STORAGE_ACCOUNT_OWNER}\",\
60+
\"lastName\":\"${STORAGE_ACCOUNT_OWNER}\",\
61+
\"email\":\"${STORAGE_ACCOUNT_OWNER}@scality.com\",\
62+
\"enabled\":\"true\",\
63+
\"credentials\":${PASSWORD_CONFIGURATION},\
64+
\"groups\":[\"${ACCOUNT}::StorageAccountOwner\"]}" || exit 1
65+
66+
curl -k "${URI}/users" \
67+
-H "${HEADER}" \
68+
-H "Authorization: bearer $TOKEN" \
69+
--data "{\
70+
\"username\":\"${DATA_CONSUMER}\",\
71+
\"firstName\":\"${DATA_CONSUMER}\",\
72+
\"lastName\":\"${DATA_CONSUMER}\",\
73+
\"email\":\"${DATA_CONSUMER}@scality.com\",\
74+
\"enabled\":\"true\",\
75+
\"credentials\":${PASSWORD_CONFIGURATION},\
76+
\"groups\":[\"${ACCOUNT}::DataConsumer\"]}" || exit 1
77+
78+
curl -k "${URI}/users" \
79+
-H "${HEADER}" \
80+
-H "Authorization: bearer $TOKEN" \
81+
--data "{\
82+
\"username\":\"${DATA_ACCESSOR}\",\
83+
\"firstName\":\"${DATA_ACCESSOR}\",\
84+
\"lastName\":\"${DATA_ACCESSOR}\",\
85+
\"email\":\"${DATA_ACCESSOR}@scality.com\",\
86+
\"enabled\":\"true\",\
87+
\"credentials\":${PASSWORD_CONFIGURATION},\
88+
\"groups\":[\"${ACCOUNT}::DataAccessor\"]}" || exit 1
89+
90+
echo "Done"
91+
92+
echo "- Attach the Storage Manager"
93+
94+
ID=`curl -k "${URI}/users?username=${STORAGE_MANAGER}" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
95+
| sed 's/.*id":"//g' | sed 's/".*//g'`
96+
[ -z "$ID" ] && exit 1
97+
98+
ROLE=`curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
99+
| jq -r '.[] | select(.. | .name? == "StorageManager")'`
100+
[ -z "$ROLE" ] && exit 1
101+
102+
curl -k -X POST "${URI}/users/${ID}/role-mappings/realm" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data "[$ROLE]" || exit 1
103+
104+
echo "- Attach the Storage Account Owner"
105+
106+
ID=`curl -k "${URI}/users?username=${STORAGE_ACCOUNT_OWNER}" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
107+
| sed 's/.*id":"//g' | sed 's/".*//g'`
108+
[ -z "$ID" ] && exit 1
109+
110+
ROLE=`curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
111+
| jq -r '.[] | select(.. | .name? == "'"${ACCOUNT}"'::StorageAccountOwner")'`
112+
[ -z "$ROLE" ] && exit 1
113+
114+
curl -k -X POST "${URI}/users/${ID}/role-mappings/realm" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data "[$ROLE]" || exit 1
115+
116+
echo "- Attach the Data Consumer"
117+
118+
ID=`curl -k "${URI}/users?username=${DATA_CONSUMER}" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
119+
| sed 's/.*id":"//g' | sed 's/".*//g'`
120+
[ -z "$ID" ] && exit 1
121+
122+
ROLE=`curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
123+
| jq -r '.[] | select(.. | .name? == "'"${ACCOUNT}"'::DataConsumer")'`
124+
[ -z "$ROLE" ] && exit 1
125+
126+
curl -k -X POST "${URI}/users/${ID}/role-mappings/realm" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data "[$ROLE]" || exit 1
127+
128+
echo "- Attach the Data Accessor"
129+
130+
ID=`curl -k "${URI}/users?username=${DATA_ACCESSOR}" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
131+
| sed 's/.*id":"//g' | sed 's/".*//g'`
132+
[ -z "$ID" ] && exit 1
133+
134+
ROLE=`curl -k "${URI}/roles" -H "${HEADER}" -H "Authorization: bearer $TOKEN" \
135+
| jq -r '.[] | select(.. | .name? == "'"${ACCOUNT}"'::DataAccessor")'`
136+
[ -z "$ROLE" ] && exit 1
137+
138+
curl -k -X POST "${URI}/users/${ID}/role-mappings/realm" -H "${HEADER}" -H "Authorization: bearer $TOKEN" --data "[$ROLE]" || exit 1
139+
140+
echo "Done"

tests/ctst/common/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
cleanupAccount,
1717
} from './utils';
1818

19-
import 'cli-testing/hooks/KeycloakSetup';
19+
// import 'cli-testing/hooks/KeycloakSetup';
2020
import 'cli-testing/hooks/Logger';
2121
import 'cli-testing/hooks/versionTags';
2222

tests/ctst/steps/pra.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Then('object {string} should {string} be {string} and have the storage class {st
270270
Identity.useIdentity(IdentityEnum.ACCOUNT, Zenko.sites['source'].accountName);
271271
}
272272
try {
273-
await verifyObjectLocation.call(this, objName, objectTransitionStatus, storageClass);
273+
await verifyObjectLocation.call(this, objName, objectTransitionStatus, storageClass, 340000);
274274
if (isVerb === 'not') {
275275
throw new Error(`Object ${objName} should not be ${objectTransitionStatus}`);
276276
}

tests/ctst/steps/utils/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ async function putBucketReplication(
474474
}
475475

476476
async function verifyObjectLocation(this: Zenko, objectName: string,
477-
objectTransitionStatus: string, storageClass: string) {
477+
objectTransitionStatus: string, storageClass: string, timeoutMs = 120000) {
478478
const objName =
479479
getObjectNameWithBackendFlakiness.call(this, objectName) || this.getSaved<string>('objectName');
480480
this.resetCommand();
@@ -489,11 +489,15 @@ async function verifyObjectLocation(this: Zenko, objectName: string,
489489
const startTime = Date.now();
490490

491491
while (!conditionOk) {
492+
if (Date.now() - startTime > timeoutMs) {
493+
throw new Error(
494+
`verifyObjectLocation timed out after ${timeoutMs / 1000}s ` +
495+
`waiting for object "${objName}" to reach status "${objectTransitionStatus}" ` +
496+
`with storage class "${storageClass}"`
497+
);
498+
}
492499
const res = await S3.headObject(this.getCommandParameters());
493500
if (res.err?.includes('NotFound')) {
494-
if (Date.now() - startTime > 300000) {
495-
throw new Error('Object not found after 300 seconds');
496-
}
497501
await Utils.sleep(1000);
498502
continue;
499503
} else if (res.err) {

0 commit comments

Comments
 (0)