-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-api-tests.sh
More file actions
executable file
·159 lines (135 loc) · 4.5 KB
/
run-api-tests.sh
File metadata and controls
executable file
·159 lines (135 loc) · 4.5 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
echo "🧪 Running SCIM API Tests"
echo "========================"
BASE_URL="http://localhost:7001/scim-identifier/test-hr-server/scim/v2"
API_KEY="api-key-12345"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to test endpoint
test_endpoint() {
local name="$1"
local endpoint="$2"
local method="${3:-GET}"
local data="$4"
echo -n "Testing $name... "
if [ "$method" = "POST" ]; then
response=$(curl -s -w "%{http_code}" -X POST \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: application/scim+json" \
-H "Content-Type: application/scim+json" \
-d "$data" \
"$BASE_URL$endpoint")
else
response=$(curl -s -w "%{http_code}" \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: application/scim+json" \
"$BASE_URL$endpoint")
fi
# Extract status code (last 3 characters)
status_code="${response: -3}"
# Extract response body (everything except last 3 characters)
response_body="${response%???}"
if [ "$status_code" -ge 200 ] && [ "$status_code" -lt 300 ]; then
echo -e "${GREEN}✅ PASS${NC} ($status_code)"
return 0
else
echo -e "${RED}❌ FAIL${NC} ($status_code)"
echo "Response: $response_body"
return 1
fi
}
# Test discovery endpoints
echo "🔍 Testing Discovery Endpoints"
echo "------------------------------"
test_endpoint "ServiceProviderConfig" "/ServiceProviderConfig"
test_endpoint "ResourceTypes" "/ResourceTypes"
test_endpoint "Schemas" "/Schemas"
echo ""
echo "📋 Testing Resource Endpoints"
echo "----------------------------"
# Test Users
echo "👥 Testing Users..."
test_endpoint "List Users" "/Users"
test_endpoint "Get Users with count" "/Users?count=5"
# Test Groups
echo "👥 Testing Groups..."
test_endpoint "List Groups" "/Groups"
test_endpoint "Get Groups with count" "/Groups?count=5"
# Test Entitlements
echo "🔑 Testing Entitlements..."
test_endpoint "List Entitlements" "/Entitlements"
test_endpoint "Get Entitlements with count" "/Entitlements?count=5"
# Test Roles
echo "🎭 Testing Roles..."
test_endpoint "List Roles" "/Roles"
test_endpoint "Get Roles with count" "/Roles?count=5"
echo ""
echo "✏️ Testing Create Operations"
echo "---------------------------"
# Test creating a user
USER_DATA='{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"userName": "testuser-api",
"displayName": "Test User API",
"emails": [{"value": "testapi@example.com", "primary": true}],
"active": true
}'
test_endpoint "Create User" "/Users" "POST" "$USER_DATA"
# Test creating an entitlement
ENTITLEMENT_DATA='{
"schemas": ["urn:okta:scim:schemas:core:1.0:Entitlement"],
"displayName": "Test License API",
"type": "License",
"description": "Test entitlement created via API"
}'
test_endpoint "Create Entitlement" "/Entitlements" "POST" "$ENTITLEMENT_DATA"
# Test creating a role
ROLE_DATA='{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Role"],
"displayName": "Test Role API",
"description": "Test role created via API"
}'
test_endpoint "Create Role" "/Roles" "POST" "$ROLE_DATA"
echo ""
echo "🔍 Testing Error Conditions"
echo "--------------------------"
# Test with invalid API key
echo -n "Testing with invalid API key... "
response=$(curl -s -w "%{http_code}" \
-H "Authorization: Bearer invalid-key" \
-H "Accept: application/scim+json" \
"$BASE_URL/Users")
status_code="${response: -3}"
if [ "$status_code" -eq 401 ]; then
echo -e "${GREEN}✅ PASS${NC} (401 Unauthorized)"
else
echo -e "${RED}❌ FAIL${NC} (Expected 401, got $status_code)"
fi
# Test with invalid endpoint
echo -n "Testing invalid endpoint... "
response=$(curl -s -w "%{http_code}" \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: application/scim+json" \
"$BASE_URL/InvalidEndpoint")
status_code="${response: -3}"
if [ "$status_code" -eq 404 ]; then
echo -e "${GREEN}✅ PASS${NC} (404 Not Found)"
else
echo -e "${RED}❌ FAIL${NC} (Expected 404, got $status_code)"
fi
echo ""
echo "📊 Test Summary"
echo "=============="
echo "✅ All basic endpoint tests completed"
echo "✅ Create operations tested"
echo "✅ Error handling verified"
echo ""
echo "🎉 API tests completed successfully!"
echo ""
echo "💡 Next steps:"
echo " - Run manual tests in browser at http://localhost:8001"
echo " - Test UI interactions and form submissions"
echo " - Verify dynamic discovery and navigation"