forked from cloud-gov/uaa-credentials-broker
/
acceptance-tests.sh
executable file
·66 lines (48 loc) · 1.83 KB
/
acceptance-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
set -e
set -u
cf login -a $CF_API_URL -u $CF_USERNAME -p $CF_PASSWORD -o $CF_ORGANIZATION -s $CF_SPACE
uaac target $UAA_API_URL
uaac token client get $UAA_CLIENT_ID -s $UAA_CLIENT_SECRET
set -x
space_guid=$(cf space "${CF_SPACE}" --guid)
# Test user plan
# Create service instance
cf create-service "${USER_SERVICE_NAME}" "${USER_PLAN_NAME}" "${SERVICE_INSTANCE_NAME}"
instance_guid=$(cf service "${SERVICE_INSTANCE_NAME}" --guid)
# User exists in UAA
user_guid=$(uaac user get "${instance_guid}" -a id | awk '{ print $2 }')
# User has space developer role
space_developers=$(cf curl "/v2/spaces/${space_guid}/developers" | jq -r '.resources[] | .metadata.guid')
echo "{$space_developers}" | grep "${user_guid}"
# Delete service instance
cf delete-service -f "${SERVICE_INSTANCE_NAME}"
# User does not have space developer role
space_developers=$(cf curl "/v2/spaces/${space_guid}/developers" | jq -r '.resources[] | .metadata.guid')
if echo "${space_developers}" | grep "${user_guid}"; then
echo "Unexpectedly found user ${instance_guid} in CF"
exit 1
fi
# User does not exist in UAA
if uaac client get "${instance_guid}"; then
echo "Unexpectedly found user ${instance_guid} in UAA"
exit 1
fi
# Test client plan
# Create service instance
cf create-service "${CLIENT_SERVICE_NAME}" "${CLIENT_PLAN_NAME}" "${SERVICE_INSTANCE_NAME}" -c '{"redirect_uri": ["https://cloud.gov"]}'
instance_guid=$(cf service "${SERVICE_INSTANCE_NAME}" --guid)
# User exists in UAA
uaac client get "${instance_guid}"
# Delete service instance
cf delete-service -f "${SERVICE_INSTANCE_NAME}"
# User does not exist in UAA
if uaac client get "${instance_guid}"; then
echo "Unexpectedly found user ${instance_guid} in UAA"
exit 1
fi
# Ensure service instance is deleted
teardown() {
cf delete-service -f "${SERVICE_INSTANCE_NAME}"
}
trap teardown EXIT