-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·242 lines (212 loc) · 8.17 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·242 lines (212 loc) · 8.17 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash
set -euo pipefail
SPINYARN_BIN="${SPINYARN_BIN:-./target/release/spinyarn}"
SPINYARN_HOST="${SPINYARN_HOST:-127.0.0.1}"
SPINYARN_PORT="${SPINYARN_PORT:-14523}"
BASE_URL="http://${SPINYARN_HOST}:${SPINYARN_PORT}"
TEST_LOG="$(pwd)/spinyarn-test.log"
cleanup() {
if [[ -n "${SPINYARN_PID:-}" ]] && kill -0 "$SPINYARN_PID" 2>/dev/null; then
kill "$SPINYARN_PID" 2>/dev/null || true
wait "$SPINYARN_PID" 2>/dev/null || true
fi
rm -f "$TEST_LOG"
}
trap cleanup EXIT
start_server() {
echo "[*] Starting SpinYarn on ${SPINYARN_HOST}:${SPINYARN_PORT} ..."
rm -f "$TEST_LOG"
# Mappings ship next to the binary, not embedded. Copy them there if missing.
local bin_dir
bin_dir="$(dirname "$SPINYARN_BIN")"
if [[ -d "mappings" && ! -d "$bin_dir/mappings" ]]; then
echo "[*] Copying mappings/ to $bin_dir/mappings"
cp -r mappings "$bin_dir/"
fi
SPINYARN_PID=$(RUST_LOG=error "$SPINYARN_BIN" > "$TEST_LOG" 2>&1 & echo $!)
# The server auto-increments its port when the configured one is taken.
# Probe the base port and a range after it to find where it actually bound,
# so we never talk to an unrelated process listening on the base port.
local p
for offset in {0..30}; do
p=$((SPINYARN_PORT + offset))
if curl -sf --max-time 1 "http://${SPINYARN_HOST}:${p}/api/v1/health" >/dev/null 2>&1; then
BASE_URL="http://${SPINYARN_HOST}:${p}"
SPINYARN_PORT="$p"
echo "[✓] Server is ready (PID=${SPINYARN_PID}, port=${p})"
return 0
fi
sleep 0.3
done
echo "[✗] Server failed to start"
if [[ -f "$TEST_LOG" ]]; then
cat "$TEST_LOG"
fi
exit 1
}
assert_equals() {
local label="$1" actual="$2" expected="$3"
if [[ "$actual" == "$expected" ]]; then
echo "[✓] $label"
else
echo "[✗] $label"
echo " expected: $expected"
echo " actual: $actual"
exit 1
fi
}
assert_contains() {
local label="$1" text="$2" substr="$3"
if [[ "$text" == *"$substr"* ]]; then
echo "[✓] $label"
else
echo "[✗] $label"
echo " expected to contain: $substr"
echo " actual: $text"
exit 1
fi
}
test_health() {
echo ""
echo "=== Test: Health ==="
local resp
resp=$(curl -sf "${BASE_URL}/api/v1/health")
assert_equals "health.status == healthy" \
"$(echo "$resp" | jq -r .data.status)" "healthy"
}
test_deobfuscate_stack() {
echo ""
echo "=== Test: Deobfuscate Stack Line (bundled 1.21.4) ==="
local resp
resp=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate" \
-H "Content-Type: application/json" \
-d '{"content": "at net.minecraft.class_7833.method_46349(Test.java:1)", "version": "1.21.4"}')
assert_equals "success == true" "$(echo "$resp" | jq -r .success)" "true"
local text
text=$(echo "$resp" | jq -r .data.deobfuscated)
assert_contains "class mapped" "$text" "net.minecraft.util.math.RotationAxis"
}
test_deobfuscate_legacy_version() {
echo ""
echo "=== Test: Deobfuscate v1 Mapping (bundled 1.14.4) ==="
local resp
resp=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate" \
-H "Content-Type: application/json" \
-d '{"content": "at net.minecraft.class_310.method_1576(Client.java:456)", "version": "1.14.4"}')
assert_equals "success == true" "$(echo "$resp" | jq -r .success)" "true"
local text
text=$(echo "$resp" | jq -r .data.deobfuscated)
assert_contains "class mapped" "$text" "net.minecraft.client.MinecraftClient"
}
test_deobfuscate_descriptor() {
echo ""
echo "=== Test: Deobfuscate Descriptor (residual) ==="
local resp
resp=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate" \
-H "Content-Type: application/json" \
-d '{"content": "method_46349(Lnet/minecraft/class_7833;)V", "version": "1.21.4"}')
local text
text=$(echo "$resp" | jq -r .data.deobfuscated)
assert_contains "descriptor class mapped" "$text" "Lnet/minecraft/util/math/RotationAxis;"
}
test_deobfuscate_multi_line() {
echo ""
echo "=== Test: Deobfuscate Multi-line Log ==="
local resp
resp=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate" \
-H "Content-Type: application/json" \
-d '{"content": "ERROR: something went wrong\nat net.minecraft.class_7833.method_46349(Test.java:1)\n[00:00:01] done", "version": "1.21.4"}')
local text
text=$(echo "$resp" | jq -r .data.deobfuscated)
assert_contains "non-stack line kept" "$text" "ERROR: something went wrong"
assert_contains "stack line mapped" "$text" "net.minecraft.util.math.RotationAxis"
}
test_deobfuscate_unsupported() {
echo ""
echo "=== Test: Unsupported Version Passthrough ==="
local resp
resp=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate" \
-H "Content-Type: application/json" \
-d '{"content": "at net.minecraft.class_7833", "version": "1.13.2"}')
assert_equals "passthrough.success == true" "$(echo "$resp" | jq -r .success)" "true"
assert_equals "deobfuscated == input" \
"$(echo "$resp" | jq -r .data.deobfuscated)" "at net.minecraft.class_7833"
assert_equals "classes_mapped == 0" \
"$(echo "$resp" | jq -r .data.stats.classes_mapped)" "0"
}
test_deobfuscate_plain() {
echo ""
echo "=== Test: Deobfuscate Plain Text ==="
local ctype
ctype=$(curl -s -o /dev/null -w "%{content_type}" \
-X POST "${BASE_URL}/api/v1/deobfuscate/plain" \
-H "Content-Type: application/json" \
-d '{"content": "at net.minecraft.class_7833.method_46349(Test.java:1)", "version": "1.21.4"}')
assert_equals "content-type == text/plain" "$ctype" "text/plain; charset=utf-8"
local body
body=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate/plain" \
-H "Content-Type: application/json" \
-d '{"content": "at net.minecraft.class_7833.method_46349(Test.java:1)", "version": "1.21.4"}')
assert_contains "plain class mapped" "$body" "net.minecraft.util.math.RotationAxis"
local passthrough
passthrough=$(curl -sf -X POST "${BASE_URL}/api/v1/deobfuscate/plain" \
-H "Content-Type: application/json" \
-d '{"content": "at net.minecraft.class_7833", "version": "1.13.2"}')
assert_equals "plain passthrough == input" "$passthrough" "at net.minecraft.class_7833"
}
test_invalid_request() {
echo ""
echo "=== Test: Invalid Request ==="
local http_code
http_code=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST "${BASE_URL}/api/v1/deobfuscate" \
-H "Content-Type: application/json" \
-d '{"content": ""}')
assert_equals "returns 422 for missing version" "$http_code" "422"
}
main() {
echo "========================================="
echo " SpinYarn Integration Test Suite"
echo "========================================="
if ! command -v jq &>/dev/null; then
echo "[✗] jq is required but not installed"
exit 1
fi
if ! command -v curl &>/dev/null; then
echo "[✗] curl is required but not installed"
exit 1
fi
if [[ ! -x "$SPINYARN_BIN" ]]; then
echo "[✗] SpinYarn binary not found at: $SPINYARN_BIN"
echo " Build with: cargo build --release"
exit 1
fi
# The stack/deobfuscation tests need real mappings. Fail loudly instead of
# silently passthrough-ing every class (mappings are no longer committed).
local missing=0
for v in 1.21.4 1.14.4; do
if [[ ! -f "mappings/${v}.tiny.gz" ]]; then
echo "[✗] Missing mapping: mappings/${v}.tiny.gz"
missing=1
fi
done
if [[ $missing -eq 1 ]]; then
echo " Download required Yarn mappings with:"
echo " bash scripts/download_mappings.sh 1.21.4 1.14.4"
exit 1
fi
start_server
test_health
test_deobfuscate_stack
test_deobfuscate_legacy_version
test_deobfuscate_descriptor
test_deobfuscate_multi_line
test_deobfuscate_unsupported
test_deobfuscate_plain
test_invalid_request
echo ""
echo "========================================="
echo " All tests passed!"
echo "========================================="
}
main "$@"