- Deleted obsolete test files: test_mime.go, test_mime_integration.go, and xmpp_client_upload_diagnosis.ipynb. - Updated README.md to reflect the new version 3.3.0 "Nexus Infinitum" and its features. - Added comprehensive release notes for version 3.3.0 detailing major enhancements and installation instructions. - Introduced cleanup script to remove development artifacts while preserving production files.
341 lines
11 KiB
Bash
341 lines
11 KiB
Bash
#!/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
|