-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.sh
More file actions
executable file
·125 lines (100 loc) · 4.46 KB
/
test_server.sh
File metadata and controls
executable file
·125 lines (100 loc) · 4.46 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
#!/bin/bash
# Integration test script for Python Odoo MCP Server
# Tests: health, auth, scope validation, tool execution, pool reuse
set -e
BASE_URL="http://localhost:3000"
TIMEOUT=5
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "=========================================="
echo "Python Odoo MCP Server - Integration Tests"
echo "=========================================="
echo ""
# Test credentials for generating API keys
CREDS_JSON='{"url":"https://demo.odoo.com","database":"demo","username":"admin","password":"admin","scope":"res.partner:RWD,sale.order:RW,*:R"}'
# Invalid API key
INVALID_API_KEY="invalid_key_!@#$%"
function test_endpoint() {
local name=$1
local method=$2
local endpoint=$3
local header=$4
local data=$5
local expected_status=$6
echo -n "Testing: $name... "
if [ -z "$data" ]; then
response=$(curl -s -w "\n%{http_code}" \
-X $method \
-H "Content-Type: application/json" \
${header:+-H "$header"} \
"$BASE_URL$endpoint" 2>/dev/null || echo "error")
else
response=$(curl -s -w "\n%{http_code}" \
-X $method \
-H "Content-Type: application/json" \
${header:+-H "$header"} \
-d "$data" \
"$BASE_URL$endpoint" 2>/dev/null || echo "error")
fi
status_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$status_code" = "$expected_status" ] || [ "$expected_status" = "*" ]; then
echo -e "${GREEN}✓ PASS${NC} (HTTP $status_code)"
return 0
else
echo -e "${RED}✗ FAIL${NC} (Expected $expected_status, got $status_code)"
echo " Response: $body"
return 1
fi
}
# ============================================================================
# TEST 1: Server is running
# ============================================================================
echo ""
echo -e "${YELLOW}[ Test Suite 1: Server Health ]${NC}"
test_endpoint "GET /" "GET" "/" "" "" "200"
test_endpoint "GET /health" "GET" "/health" "" "" "200"
# ============================================================================
# TEST 2: Tool discovery
# ============================================================================
echo ""
echo -e "${YELLOW}[ Test Suite 2: Tool Discovery ]${NC}"
test_endpoint "List tools" "POST" "/tools/list" "" "" "200"
# ============================================================================
# TEST 3: Authentication flows
# ============================================================================
echo ""
echo -e "${YELLOW}[ Test Suite 3: Authentication Flows ]${NC}"
# Test generating API key
test_endpoint "Generate API key" "POST" "/auth/generate" "Content-Type: application/json" "$CREDS_JSON" "200"
# Test missing API key header
test_endpoint "Missing X-API-Key header" "POST" "/tools/call" "" '{"name":"search","arguments":{}}' "200"
# Test invalid API key
test_endpoint "Invalid API key" "POST" "/tools/call" "X-API-Key: $INVALID_API_KEY" '{"name":"search","arguments":{}}' "200"
# ============================================================================
# TEST 4: Tool validation (requires valid API key)
# ============================================================================
echo ""
echo -e "${YELLOW}[ Test Suite 4: Tool Validation ]${NC}"
test_endpoint "Missing tool name" "POST" "/tools/call" "X-API-Key: $INVALID_API_KEY" '{"arguments":{}}' "200"
test_endpoint "Unknown tool" "POST" "/tools/call" "X-API-Key: $INVALID_API_KEY" '{"name":"unknown_tool","arguments":{}}' "200"
# ============================================================================
# TEST 5: API key validation endpoint
# ============================================================================
echo ""
echo -e "${YELLOW}[ Test Suite 5: API Key Validation ]${NC}"
# Test validating an invalid key
test_endpoint "Validate invalid key" "POST" "/auth/validate" "Content-Type: application/json" '{"api_key":"'$INVALID_API_KEY'"}' "*"
# ============================================================================
# SUMMARY
# ============================================================================
echo ""
echo "=========================================="
echo "Tests complete!"
echo ""
echo -e "${YELLOW}Note:${NC} Connection and authentication tests require a live Odoo instance."
echo "This test script validates error handling and edge cases only."
echo "=========================================="