Remove obsolete files: simple_revalidation.sh and test script

This commit is contained in:
2025-11-26 18:42:10 +01:00
parent 2f8f09b353
commit 350aab1ef6
4 changed files with 1 additions and 479 deletions

View File

@@ -0,0 +1 @@
server

0
revalidate_all_features.sh Normal file → Executable file
View File

View File

@@ -1,139 +0,0 @@
#!/bin/bash
# 🔍 SIMPLIFIED REVALIDATION OF HMAC FILE SERVER
# Date: August 26, 2025
set -e
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${BLUE}🔍 REVALIDATING ALL HMAC FILE SERVER NETWORK RESILIENCE FEATURES${NC}"
echo "================================================================="
echo ""
PASSED=0
TOTAL=0
test_feature() {
local name="$1"
local test_cmd="$2"
TOTAL=$((TOTAL + 1))
echo -n "Testing $name... "
if eval "$test_cmd" >/dev/null 2>&1; then
echo -e "${GREEN}✅ PASS${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}❌ FAIL${NC}"
fi
}
echo "🔧 BINARY AND CONFIGURATION TESTS"
echo "=================================="
test_feature "Server binary exists" "[ -x './hmac-file-server-network-fixed' ]"
test_feature "Configuration exists" "[ -r 'config-mobile-resilient.toml' ]"
test_feature "Server version" "./hmac-file-server-network-fixed -version | grep -q 'v3.3'"
echo ""
echo "🔐 BEARER TOKEN VALIDATION TESTS"
echo "================================="
test_feature "validateBearerToken function" "grep -q 'func validateBearerToken' cmd/server/main.go"
test_feature "Mobile client detection" "grep -A5 'isMobileXMPP.*:=' cmd/server/main.go | grep -q 'conversations'"
test_feature "Grace period logic" "grep -q 'gracePeriod.*int64' cmd/server/main.go"
test_feature "Ultra grace period (72h)" "grep -q '259200.*72 hours' cmd/server/main.go"
test_feature "Standby recovery" "grep -q 'STANDBY RECOVERY' cmd/server/main.go"
test_feature "Network switch detection" "grep -q 'Network switching detected' cmd/server/main.go"
test_feature "Multiple HMAC formats" "grep -A50 'ENHANCED HMAC VALIDATION' cmd/server/main.go | grep -c 'expectedMAC' | grep -q '5'"
echo ""
echo "📡 NETWORK CHANGE DETECTION TESTS"
echo "=================================="
test_feature "getClientIP function" "grep -q 'func getClientIP' cmd/server/chunked_upload_handler.go"
test_feature "X-Forwarded-For support" "grep -A5 'X-Forwarded-For' cmd/server/chunked_upload_handler.go | grep -q 'xff.*!='"
test_feature "X-Real-IP support" "grep -A5 'X-Real-IP' cmd/server/chunked_upload_handler.go | grep -q 'xri.*!='"
echo ""
echo "⚙️ CONFIGURATION TESTS"
echo "======================"
test_feature "Universal binding (0.0.0.0)" "grep -q 'bind_ip.*0.0.0.0' config-mobile-resilient.toml"
test_feature "Network events enabled" "grep -q 'networkevents.*true' config-mobile-resilient.toml"
test_feature "Extended timeouts" "grep -q 'read_timeout.*600s' config-mobile-resilient.toml"
test_feature "Resumable uploads" "grep -q 'resumable_uploads_enabled.*true' config-mobile-resilient.toml"
test_feature "IP change handling" "grep -q 'allow_ip_changes.*true' config-mobile-resilient.toml"
echo ""
echo "🚀 SERVER FUNCTIONALITY TESTS"
echo "=============================="
echo -n "Testing server startup... "
timeout 10s ./hmac-file-server-network-fixed -config config-mobile-resilient.toml > /tmp/test_startup.log 2>&1 &
SERVER_PID=$!
sleep 3
if kill -0 $SERVER_PID 2>/dev/null; then
echo -e "${GREEN}✅ PASS${NC}"
PASSED=$((PASSED + 1))
echo -n "Testing health endpoint... "
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/health | grep -q "200"; then
echo -e "${GREEN}✅ PASS${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}❌ FAIL${NC}"
fi
kill $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null || true
else
echo -e "${RED}❌ FAIL${NC}"
fi
TOTAL=$((TOTAL + 2))
echo ""
echo "📊 FINAL RESULTS"
echo "================"
echo "Total tests: $TOTAL"
echo "Passed: $PASSED"
echo "Failed: $((TOTAL - PASSED))"
PERCENTAGE=$(( (PASSED * 100) / TOTAL ))
echo "Success rate: $PERCENTAGE%"
echo ""
if [ $PASSED -eq $TOTAL ]; then
echo -e "${GREEN}🎉 100% SUCCESS - ALL NETWORK RESILIENCE FEATURES VALIDATED!${NC}"
echo ""
echo -e "${GREEN}✅ CONFIRMED WORKING:${NC}"
echo " • WiFi ↔ LTE switching without 404 errors"
echo " • Device standby authentication (72h grace period)"
echo " • Mobile XMPP client detection and optimization"
echo " • IP change detection for network transitions"
echo " • Ultra-flexible Bearer token validation"
echo " • Multiple HMAC payload format support"
echo ""
echo -e "${BLUE}🚀 YOUR PROBLEM IS COMPLETELY SOLVED!${NC}"
echo "Deploy with: ./hmac-file-server-network-fixed -config config-mobile-resilient.toml"
elif [ $PERCENTAGE -ge 90 ]; then
echo -e "${YELLOW}⚠️ MOSTLY SUCCESSFUL ($PERCENTAGE%)${NC}"
echo "Core features working. Minor issues can be ignored."
echo -e "${GREEN}Network resilience is functional for production use.${NC}"
else
echo -e "${RED}❌ SIGNIFICANT ISSUES FOUND ($PERCENTAGE%)${NC}"
echo "Review failed tests above."
fi
echo ""
echo "Revalidation complete - $(date)"
# Cleanup
rm -f /tmp/test_startup.log

340
test
View File

@@ -1,340 +0,0 @@
#!/bin/bash
# HMAC File Server 3.3 "Nexus Infinitum" - Comprehensive Test Suite
# Consolidates all testing functionality for uploads, HMAC validation, network resilience, and XMPP integration
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
HMAC_KEY="f6g4ldPvQM7O2UTFeBEUUj33VrXypDAcsDt0yqKrLiOr5oQW"
BASE_URL="${BASE_URL:-}" # Will be auto-detected in main()
TEST_USER_ID="c184288b79f8b7a6f7d87ac7f1fb1ce6dcf49a80"
LOG_FILE="/tmp/hmac_test_results_$(date +%Y%m%d_%H%M%S).log"
# Test counters
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
# Logging function
log() {
echo -e "$1" | tee -a "$LOG_FILE"
}
# Test result function
test_result() {
TOTAL_TESTS=$((TOTAL_TESTS + 1))
if [ "$1" -eq 0 ]; then
PASSED_TESTS=$((PASSED_TESTS + 1))
log "${GREEN}✅ PASS${NC}: $2"
else
FAILED_TESTS=$((FAILED_TESTS + 1))
log "${RED}❌ FAIL${NC}: $2"
fi
}
# HMAC calculation function
calculate_hmac() {
local file_path="$1"
local file_size="$2"
local hmac_message="${file_path} ${file_size}"
echo -n "$hmac_message" | openssl dgst -sha256 -hmac "$HMAC_KEY" | cut -d' ' -f2
}
# Create test files
setup_test_files() {
log "${BLUE}📁 Setting up test files...${NC}"
# Small text file
echo "Small test file for HMAC validation" > /tmp/test_small.txt
# Medium MP4 file (simulating video)
echo "This is a test MP4 video file content for XMPP upload testing with some additional content to make it larger" > /tmp/test_medium.mp4
# Large file (1MB)
dd if=/dev/zero of=/tmp/test_large.bin bs=1024 count=1024 2>/dev/null
# Test image
echo -e '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x01\x00\x00\x00\x007n\xf9$\x00\x00\x00\nIDAT\x08\x1dc\xf8\x00\x00\x00\x01\x00\x01\x02\x93\x8d\xb8\x00\x00\x00\x00IEND\xaeB`\x82' > /tmp/test_image.png
log "${GREEN}✅ Test files created${NC}"
}
# Test 1: Basic HMAC validation
test_hmac_validation() {
log "\n${YELLOW}🔐 Test 1: HMAC Validation${NC}"
local file_path="${TEST_USER_ID}/test/basic.txt"
local file_size=$(stat -c%s /tmp/test_small.txt)
local hmac=$(calculate_hmac "$file_path" "$file_size")
log "File: /tmp/test_small.txt (${file_size} bytes)"
log "Path: ${file_path}"
log "HMAC: ${hmac}"
# Test upload
local response=$(curl -s -w "%{http_code}" -X PUT \
-H "Content-Type: text/plain" \
--data-binary "@/tmp/test_small.txt" \
"${BASE_URL}/${file_path}?v=${hmac}")
local http_code="${response: -3}"
test_result $([ "$http_code" = "201" ] && echo 0 || echo 1) "Basic HMAC validation (HTTP $http_code)"
}
# Test 2: MP4 file upload (XMPP compatibility)
test_mp4_upload() {
log "\n${YELLOW}🎥 Test 2: MP4 File Upload (XMPP)${NC}"
local file_path="${TEST_USER_ID}/xmpp/test_video.mp4"
local file_size=$(stat -c%s /tmp/test_medium.mp4)
local hmac=$(calculate_hmac "$file_path" "$file_size")
log "File: /tmp/test_medium.mp4 (${file_size} bytes)"
log "Path: ${file_path}"
log "HMAC: ${hmac}"
# Test upload
local response=$(curl -s -w "%{http_code}" -X PUT \
-H "Content-Type: video/mp4" \
--data-binary "@/tmp/test_medium.mp4" \
"${BASE_URL}/${file_path}?v=${hmac}")
local http_code="${response: -3}"
test_result $([ "$http_code" = "201" ] && echo 0 || echo 1) "MP4 upload for XMPP (HTTP $http_code)"
}
# Test 3: Large file upload
test_large_file() {
log "\n${YELLOW}📦 Test 3: Large File Upload${NC}"
local file_path="${TEST_USER_ID}/large/big_file.zip"
local file_size=$(stat -c%s /tmp/test_large.bin)
local hmac=$(calculate_hmac "$file_path" "$file_size")
log "File: /tmp/test_large.bin (${file_size} bytes)"
log "Path: ${file_path}"
log "HMAC: ${hmac}"
# Test upload with timeout - using .zip extension which is allowed
local response=$(timeout 60 curl -s -w "%{http_code}" -X PUT \
-H "Content-Type: application/zip" \
--data-binary "@/tmp/test_large.bin" \
"${BASE_URL}/${file_path}?v=${hmac}")
local exit_code=$?
local http_code="${response: -3}"
if [ $exit_code -eq 124 ]; then
test_result 1 "Large file upload (TIMEOUT)"
else
test_result $([ "$http_code" = "201" ] && echo 0 || echo 1) "Large file upload (HTTP $http_code)"
fi
}
# Test 4: Invalid HMAC (should fail)
test_invalid_hmac() {
log "\n${YELLOW}🚫 Test 4: Invalid HMAC (Should Fail)${NC}"
local file_path="${TEST_USER_ID}/test/invalid.txt"
local invalid_hmac="invalid_hmac_value_should_fail"
log "File: /tmp/test_small.txt"
log "Path: ${file_path}"
log "Invalid HMAC: ${invalid_hmac}"
# Test upload with invalid HMAC
local response=$(curl -s -w "%{http_code}" -X PUT \
-H "Content-Type: text/plain" \
--data-binary "@/tmp/test_small.txt" \
"${BASE_URL}/${file_path}?v=${invalid_hmac}")
local http_code="${response: -3}"
test_result $([ "$http_code" = "401" ] && echo 0 || echo 1) "Invalid HMAC rejection (HTTP $http_code)"
}
# Test 5: Unsupported file extension (should fail)
test_unsupported_extension() {
log "\n${YELLOW}🚫 Test 5: Unsupported Extension (Should Fail)${NC}"
# Create file with unsupported extension
echo "This should fail" > /tmp/test_unsupported.xyz
local file_path="${TEST_USER_ID}/test/unsupported.xyz"
local file_size=$(stat -c%s /tmp/test_unsupported.xyz)
local hmac=$(calculate_hmac "$file_path" "$file_size")
log "File: /tmp/test_unsupported.xyz (${file_size} bytes)"
log "Path: ${file_path}"
log "HMAC: ${hmac}"
# Test upload
local response=$(curl -s -w "%{http_code}" -X PUT \
-H "Content-Type: application/octet-stream" \
--data-binary "@/tmp/test_unsupported.xyz" \
"${BASE_URL}/${file_path}?v=${hmac}")
local http_code="${response: -3}"
test_result $([ "$http_code" = "400" ] && echo 0 || echo 1) "Unsupported extension rejection (HTTP $http_code)"
}
# Test 6: Image upload
test_image_upload() {
log "\n${YELLOW}🖼️ Test 6: Image Upload${NC}"
local file_path="${TEST_USER_ID}/images/test.png"
local file_size=$(stat -c%s /tmp/test_image.png)
local hmac=$(calculate_hmac "$file_path" "$file_size")
log "File: /tmp/test_image.png (${file_size} bytes)"
log "Path: ${file_path}"
log "HMAC: ${hmac}"
# Test upload
local response=$(curl -s -w "%{http_code}" -X PUT \
-H "Content-Type: image/png" \
--data-binary "@/tmp/test_image.png" \
"${BASE_URL}/${file_path}?v=${hmac}")
local http_code="${response: -3}"
test_result $([ "$http_code" = "201" ] && echo 0 || echo 1) "Image upload (HTTP $http_code)"
}
# Test 7: Server health check
test_server_health() {
log "\n${YELLOW}💓 Test 7: Server Health Check${NC}"
# Try different health endpoints
local health_endpoints=("/health" "" "/metrics")
local health_passed=false
for endpoint in "${health_endpoints[@]}"; do
local url="${BASE_URL}${endpoint}"
local response=$(curl -s -w "%{http_code}" --connect-timeout 5 --max-time 10 "$url" 2>/dev/null || echo "000")
local http_code="${response: -3}"
if [ "$http_code" = "200" ]; then
health_passed=true
log "✅ Health check passed on endpoint: $endpoint"
break
else
log "⚠️ Health endpoint $endpoint returned: HTTP $http_code"
fi
done
test_result $([ "$health_passed" = true ] && echo 0 || echo 1) "Server health check"
}
# Test 8: Network resilience status (if enabled)
test_network_resilience() {
log "\n${YELLOW}🌐 Test 8: Network Resilience Status${NC}"
# Check if network resilience endpoint exists
local response=$(curl -s -w "%{http_code}" "${BASE_URL}/metrics" 2>/dev/null || echo "000")
local http_code="${response: -3}"
test_result $([ "$http_code" = "200" ] && echo 0 || echo 1) "Network resilience metrics (HTTP $http_code)"
}
# Cleanup function
cleanup() {
log "\n${BLUE}🧹 Cleaning up test files...${NC}"
rm -f /tmp/test_small.txt /tmp/test_medium.mp4 /tmp/test_large.bin /tmp/test_image.png /tmp/test_unsupported.xyz
log "${GREEN}✅ Cleanup completed${NC}"
}
# Main test execution
main() {
log "${BLUE}🚀 HMAC File Server 3.3 Comprehensive Test Suite${NC}"
log "${BLUE}================================================${NC}"
log "Test started at: $(date)"
log "Log file: $LOG_FILE"
# Auto-detect server endpoint if not set
if [ -z "$BASE_URL" ]; then
if curl -s --connect-timeout 2 --max-time 5 "https://xmpp.uuxo.net/health" >/dev/null 2>&1; then
BASE_URL="https://xmpp.uuxo.net"
log "${GREEN}🌐 Using remote server: https://xmpp.uuxo.net${NC}"
elif curl -s --connect-timeout 2 --max-time 5 "http://localhost:8080/health" >/dev/null 2>&1; then
BASE_URL="http://localhost:8080"
log "${YELLOW}🏠 Using local server: http://localhost:8080${NC}"
else
BASE_URL="http://localhost:8080"
log "${RED}⚠️ No server detected, defaulting to: http://localhost:8080${NC}"
fi
fi
log "Base URL: $BASE_URL"
log ""
# Setup
setup_test_files
# Run all tests
test_server_health
test_hmac_validation
test_mp4_upload
test_image_upload
test_large_file
test_invalid_hmac
test_unsupported_extension
test_network_resilience
# Summary
log "\n${BLUE}📊 Test Summary${NC}"
log "${BLUE}===============${NC}"
log "Total Tests: $TOTAL_TESTS"
log "${GREEN}Passed: $PASSED_TESTS${NC}"
log "${RED}Failed: $FAILED_TESTS${NC}"
if [ $FAILED_TESTS -eq 0 ]; then
log "\n${GREEN}🎉 All tests passed! System is working correctly.${NC}"
exit_code=0
else
log "\n${RED}⚠️ Some tests failed. Check the logs above for details.${NC}"
exit_code=1
fi
log "\nTest completed at: $(date)"
log "Full log saved to: $LOG_FILE"
# Cleanup
cleanup
exit $exit_code
}
# Handle script arguments
case "${1:-}" in
"clean")
cleanup
exit 0
;;
"setup")
setup_test_files
exit 0
;;
"help"|"-h"|"--help")
echo "HMAC File Server 3.3 Comprehensive Test Suite"
echo ""
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " (none) Run all tests"
echo " clean Clean up test files"
echo " setup Setup test files only"
echo " help Show this help"
echo ""
exit 0
;;
*)
main
;;
esac