Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·139 lines (114 loc) · 3.47 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·139 lines (114 loc) · 3.47 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
#!/bin/bash
# Test script for mTLS examples
set -e
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE} mTLS Examples Test Suite${NC}"
echo -e "${BLUE}================================================${NC}"
echo ""
# Check if certificates exist
echo -e "${YELLOW}Checking certificates...${NC}"
if [ ! -f "certs/ca/ca-cert.pem" ]; then
echo -e "${RED}✗ CA certificate not found${NC}"
echo "Generating certificates..."
./mtls ca create --batch --cn "Test CA" --key-type rsa4096
echo -e "${GREEN}✓ CA created${NC}"
fi
if [ ! -f "certs/servers/localhost/server-cert.pem" ]; then
echo -e "${RED}✗ Server certificate not found${NC}"
echo "Generating server certificate..."
./mtls cert create --batch \
--ca ./certs/ca \
--cn "localhost" \
--dns "localhost,127.0.0.1" \
--ip "127.0.0.1" \
--key-type rsa2048
echo -e "${GREEN}✓ Server certificate created${NC}"
else
echo -e "${GREEN}✓ Certificates found${NC}"
fi
echo ""
echo -e "${YELLOW}Building examples...${NC}"
# Build Go server
cd examples/go-server
go build -o server main.go
echo -e "${GREEN}✓ Go server built${NC}"
cd ../..
# Build Go client
cd examples/go-client
go build -o client main.go
echo -e "${GREEN}✓ Go client built${NC}"
cd ../..
echo ""
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE} Test 1: Go Server + Go Client${NC}"
echo -e "${BLUE}================================================${NC}"
echo ""
# Start Go server in background
cd examples/go-server
./server > server.log 2>&1 &
SERVER_PID=$!
cd ../..
echo -e "${YELLOW}Server started (PID: $SERVER_PID)${NC}"
echo "Waiting for server to start..."
sleep 2
# Run Go client
echo -e "${YELLOW}Running client tests...${NC}"
cd examples/go-client
./client
CLIENT_EXIT=$?
cd ../..
# Stop server
echo ""
echo -e "${YELLOW}Stopping server...${NC}"
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
if [ $CLIENT_EXIT -eq 0 ]; then
echo -e "${GREEN}✓ Test passed${NC}"
else
echo -e "${RED}✗ Test failed${NC}"
exit 1
fi
echo ""
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE} Test 2: cURL Test${NC}"
echo -e "${BLUE}================================================${NC}"
echo ""
# Start Go server again
cd examples/go-server
./server > server.log 2>&1 &
SERVER_PID=$!
cd ../..
echo "Waiting for server to start..."
sleep 2
# Test with curl
echo -e "${YELLOW}Testing with curl...${NC}"
CURL_OUTPUT=$(curl --silent \
--cert certs/servers/localhost/server-cert.pem \
--key certs/servers/localhost/server-key.pem \
--cacert certs/ca/ca-cert.pem \
https://localhost:8443)
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ cURL test passed${NC}"
echo "Response:"
echo "$CURL_OUTPUT" | head -3
else
echo -e "${RED}✗ cURL test failed${NC}"
fi
# Stop server
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
echo ""
echo -e "${GREEN}================================================${NC}"
echo -e "${GREEN} All tests completed!${NC}"
echo -e "${GREEN}================================================${NC}"
echo ""
echo "You can now:"
echo " 1. Run the Go server: cd examples/go-server && ./server"
echo " 2. Run the Go client: cd examples/go-client && ./client"
echo " 3. Run Caddy: cd examples/caddy && ./run.sh"
echo ""