-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-admin-db.example.sh
More file actions
executable file
·136 lines (121 loc) · 5.21 KB
/
test-admin-db.example.sh
File metadata and controls
executable file
·136 lines (121 loc) · 5.21 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
#!/bin/bash
# Copyright (c) 2025 TESOBE
#
# This file is part of OBP-OIDC.
#
# OBP-OIDC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OBP-OIDC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OBP-OIDC. If not, see <http://www.gnu.org/licenses/>.
# OBP-OIDC Admin Database Connection Test Script
#
# SETUP INSTRUCTIONS:
# 1. Copy this file to test-admin-db.sh:
# cp test-admin-db.example.sh test-admin-db.sh
# 2. Edit test-admin-db.sh with your admin database credentials
# 3. Make it executable:
# chmod +x test-admin-db.sh
# 4. Run it:
# ./test-admin-db.sh
echo "🔧 OBP-OIDC Admin Database Connection Test"
echo "==========================================="
# Admin Database Configuration
# ⚠️ IMPORTANT: Edit these values for your admin database setup
# These are example values - CHANGE THEM!
DB_HOST=localhost
DB_PORT=5432
DB_NAME=sandbox
OIDC_ADMIN_USER=oidc_admin_user
OIDC_ADMIN_PASSWORD=CHANGE_THIS_TO_A_VERY_STRONG_ADMIN_PASSWORD_2024!
echo "📋 Testing admin database connection:"
echo " Host: $DB_HOST:$DB_PORT"
echo " Database: $DB_NAME"
echo " Admin User: $OIDC_ADMIN_USER"
echo ""
# Test basic connection
echo "🔌 Testing basic database connection..."
if psql "postgresql://$OIDC_ADMIN_USER:$OIDC_ADMIN_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -c "SELECT version();" > /dev/null 2>&1; then
echo "✅ Basic connection successful"
else
echo "❌ Basic connection failed"
echo " Please check your database credentials and ensure PostgreSQL is running"
exit 1
fi
# Test v_oidc_admin_clients view access
echo ""
echo "📊 Testing v_oidc_admin_clients view access..."
if psql "postgresql://$OIDC_ADMIN_USER:$OIDC_ADMIN_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -c "SELECT COUNT(*) FROM v_oidc_admin_clients;" > /dev/null 2>&1; then
CLIENT_COUNT=$(psql "postgresql://$OIDC_ADMIN_USER:$OIDC_ADMIN_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -t -c "SELECT COUNT(*) FROM v_oidc_admin_clients;" | xargs)
echo "✅ v_oidc_admin_clients view accessible"
echo " Found $CLIENT_COUNT client(s) in the view"
else
echo "❌ v_oidc_admin_clients view not accessible"
echo " Please ensure the view exists and your user has the correct permissions"
exit 1
fi
# Test write permissions (INSERT)
echo ""
echo "✏️ Testing write permissions (INSERT)..."
TEST_CLIENT_ID="test-client-$(date +%s)"
INSERT_RESULT=$(psql "postgresql://$OIDC_ADMIN_USER:$OIDC_ADMIN_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -t -c "
INSERT INTO v_oidc_admin_clients (
client_id, client_secret, client_name, redirect_uris,
grant_types, response_types, scopes, token_endpoint_auth_method
) VALUES (
'$TEST_CLIENT_ID', 'test-secret', 'Test Client', 'http://localhost:3000/callback',
'authorization_code', 'code', 'openid', 'client_secret_basic'
) RETURNING client_id;" 2>&1)
if echo "$INSERT_RESULT" | grep -q "$TEST_CLIENT_ID"; then
echo "✅ INSERT permission working"
# Test UPDATE permission
echo "🔄 Testing UPDATE permission..."
UPDATE_RESULT=$(psql "postgresql://$OIDC_ADMIN_USER:$OIDC_ADMIN_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -t -c "
UPDATE v_oidc_admin_clients
SET client_name = 'Updated Test Client'
WHERE client_id = '$TEST_CLIENT_ID'
RETURNING client_id;" 2>&1)
if echo "$UPDATE_RESULT" | grep -q "$TEST_CLIENT_ID"; then
echo "✅ UPDATE permission working"
else
echo "❌ UPDATE permission failed: $UPDATE_RESULT"
fi
# Test DELETE permission
echo "🗑️ Testing DELETE permission..."
DELETE_RESULT=$(psql "postgresql://$OIDC_ADMIN_USER:$OIDC_ADMIN_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -t -c "
DELETE FROM v_oidc_admin_clients
WHERE client_id = '$TEST_CLIENT_ID'
RETURNING client_id;" 2>&1)
if echo "$DELETE_RESULT" | grep -q "$TEST_CLIENT_ID"; then
echo "✅ DELETE permission working"
echo "🧹 Test client cleaned up successfully"
else
echo "❌ DELETE permission failed: $DELETE_RESULT"
echo "⚠️ You may need to manually clean up the test client: $TEST_CLIENT_ID"
fi
else
echo "❌ INSERT permission failed: $INSERT_RESULT"
echo " Please ensure your admin user has INSERT permissions on v_oidc_admin_clients"
fi
echo ""
echo "🎉 Admin database connection test completed!"
echo ""
echo "📝 Summary:"
echo " - Basic connection: ✅"
echo " - View access: ✅"
echo " - Write permissions test completed"
echo ""
echo "💡 If all tests passed, your admin database configuration is ready!"
echo " You can now use the OIDC provider's client management features."
echo ""
echo "🚀 Next steps:"
echo " 1. Update your run-server.sh with these admin database credentials"
echo " 2. Start the OIDC server with: ./run-server.sh"
echo " 3. The server will automatically test both database connections on startup"