-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·128 lines (107 loc) · 3.92 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·128 lines (107 loc) · 3.92 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
#!/bin/bash
# SPDX-FileCopyrightText: © 2024-2025 Phala Network <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
BINARY="$PROJECT_ROOT/target/debug/dstack-verifier"
LOG_FILE="/tmp/verifier-test.log"
FIXTURE_FILE="$SCRIPT_DIR/fixtures/quote-report.json"
echo -e "${YELLOW}dstack-verifier Test Script${NC}"
echo "=================================="
# Function to cleanup on exit
cleanup() {
echo -e "\n${YELLOW}Cleaning up...${NC}"
pkill -f dstack-verifier 2>/dev/null || true
sleep 1
}
trap cleanup EXIT
# Build the project
echo -e "${YELLOW}Building dstack-verifier...${NC}"
cd "$PROJECT_ROOT"
cargo build --bin dstack-verifier --quiet
if [ ! -f "$BINARY" ]; then
echo -e "${RED}Error: Binary not found at $BINARY${NC}"
exit 1
fi
# Start the server
echo -e "${YELLOW}Starting dstack-verifier server...${NC}"
"$BINARY" >"$LOG_FILE" 2>&1 &
SERVER_PID=$!
# Wait for server to start
echo -e "${YELLOW}Waiting for server to start...${NC}"
for i in {1..10}; do
if curl -s http://localhost:8080/health >/dev/null 2>&1; then
echo -e "${GREEN}Server started successfully${NC}"
break
fi
if [ $i -eq 10 ]; then
echo -e "${RED}Server failed to start${NC}"
echo "Server logs:"
cat "$LOG_FILE"
exit 1
fi
sleep 1
done
# Check if fixture file exists
if [ ! -f "$FIXTURE_FILE" ]; then
echo -e "${RED}Error: Fixture file not found at $FIXTURE_FILE${NC}"
exit 1
fi
# Run the verification test
echo -e "${YELLOW}Running verification test...${NC}"
echo "Using fixture: $FIXTURE_FILE"
RESPONSE=$(curl -s -X POST http://localhost:8080/verify \
-H "Content-Type: application/json" \
-d @"$FIXTURE_FILE")
# Parse and display results
echo -e "\n${YELLOW}Test Results:${NC}"
echo "============="
IS_VALID=$(echo "$RESPONSE" | jq -r '.is_valid')
QUOTE_VERIFIED=$(echo "$RESPONSE" | jq -r '.details.quote_verified')
EVENT_LOG_VERIFIED=$(echo "$RESPONSE" | jq -r '.details.event_log_verified')
OS_IMAGE_VERIFIED=$(echo "$RESPONSE" | jq -r '.details.os_image_hash_verified')
TCB_STATUS=$(echo "$RESPONSE" | jq -r '.details.tcb_status')
REASON=$(echo "$RESPONSE" | jq -r '.reason // "null"')
echo -e "Overall Valid: $([ "$IS_VALID" = "true" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}") $IS_VALID"
echo -e "Quote Verified: $([ "$QUOTE_VERIFIED" = "true" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}") $QUOTE_VERIFIED"
echo -e "Event Log Verified: $([ "$EVENT_LOG_VERIFIED" = "true" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}") $EVENT_LOG_VERIFIED"
echo -e "OS Image Verified: $([ "$OS_IMAGE_VERIFIED" = "true" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}") $OS_IMAGE_VERIFIED"
echo -e "TCB Status: ${GREEN}$TCB_STATUS${NC}"
if [ "$REASON" != "null" ]; then
echo -e "${RED}Failure Reason:${NC}"
echo "$REASON"
fi
# Show app info if available
APP_ID=$(echo "$RESPONSE" | jq -r '.details.app_info.app_id // "null"')
OS_IMAGE_HASH=$(echo "$RESPONSE" | jq -r '.details.app_info.os_image_hash // "null"')
if [ "$APP_ID" != "null" ]; then
echo -e "\n${YELLOW}App Information:${NC}"
echo "App ID: $APP_ID"
echo "Compose Hash: $(echo "$RESPONSE" | jq -r '.details.app_info.compose_hash')"
echo "OS Image Hash: $OS_IMAGE_HASH"
fi
# Show report data
REPORT_DATA=$(echo "$RESPONSE" | jq -r '.details.report_data // "null"')
if [ "$REPORT_DATA" != "null" ]; then
echo -e "\n${YELLOW}Report Data:${NC}"
echo "$REPORT_DATA"
fi
echo -e "\n${YELLOW}Server Logs:${NC}"
echo "============"
tail -10 "$LOG_FILE"
echo -e "\n${YELLOW}Test completed!${NC}"
if [ "$IS_VALID" = "true" ]; then
echo -e "${GREEN}✓ Verification PASSED${NC}"
exit 0
else
echo -e "${RED}✗ Verification FAILED${NC}"
exit 1
fi