Created
September 12, 2025 18:03
-
-
Save Deniz97/d15cf10d9407edd71b2ed697d20e73f6 to your computer and use it in GitHub Desktop.
Simple API test script for employee monitoring system - Tests USB, file system, application, and upload activity logging endpoints with hardcoded examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Simple API test script with hardcoded examples | |
| # Usage: ./test-api-logs.sh [API_BASE_URL] [DEVICE_API_KEY] | |
| # | |
| # ============================================================================= | |
| # SUPPORTED EVENT TYPES AND ACTIONS | |
| # ============================================================================= | |
| # | |
| # 1. USB_ACTIVITY | |
| # Actions: "plugged_in", "plugged_out", "connected", "disconnected", "inserted", "removed" | |
| # Description: USB device connection/disconnection events | |
| # Metadata: deviceName, deviceId, capacity, vendor, serialNumber, fileCount, totalSize | |
| # | |
| # 2. FILE_SYSTEM_ACTIVITY | |
| # Actions: "created", "create", "renamed", "rename", "deleted", "delete" | |
| # Description: File system operations (Turkish descriptions supported) | |
| # Metadata: file_path, old_file_path, new_file_path, file_extension, fileSize, category | |
| # | |
| # 3. APPLICATION_ACTIVITY | |
| # Actions: "started", "focused", "opened", "saved", "accessed", "used" | |
| # Description: Application usage tracking and monitoring | |
| # Metadata: application_name, category, duration, activityType, windowTitle, processId | |
| # | |
| # 4. UPLOAD_ACTIVITY | |
| # Actions: "uploaded" | |
| # Description: File upload monitoring through web browsers | |
| # Metadata: file_name, file_size, upload_url, mime_type, category, browser, destination | |
| # | |
| # ============================================================================= | |
| # AUTHENTICATION | |
| # ============================================================================= | |
| # Header: X-Device-API-Key: [DEVICE_API_KEY] | |
| # Endpoint: POST /api/logs (for log submission) | |
| # Endpoint: GET /api/me (for device information) | |
| # | |
| # ============================================================================= | |
| set -e | |
| API_BASE_URL="${1:-http://localhost:3000}" | |
| DEVICE_API_KEY="${2:-device-api-key-123}" | |
| echo "π§ͺ Simple API test with hardcoded examples..." | |
| echo "API URL: $API_BASE_URL/api/logs" | |
| echo "Device API Key: $DEVICE_API_KEY" | |
| echo "" | |
| # Test 0: Device info endpoint | |
| echo "π₯ Test 0: Device information (/api/me)" | |
| RESPONSE=$(curl -s -w "\n%{http_code}" \ | |
| -X GET \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| "$API_BASE_URL/api/me") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | sed '$d') | |
| if [[ $HTTP_CODE == "200" ]]; then | |
| echo "β Device info test passed" | |
| echo "Response: $BODY" | |
| else | |
| echo "β Device info test failed (HTTP $HTTP_CODE)" | |
| echo "Response: $BODY" | |
| fi | |
| echo "" | |
| # Test 1: File system activity (matching your example format) | |
| echo "π Test 1: File system activity (rename operation)" | |
| FILE_LOG=$(cat <<'EOF' | |
| { | |
| "id": "9a4b3fa7-4525-4087-9de2-ffe67a1b6345", | |
| "timestamp": "2025-01-12T23:30:43.311Z", | |
| "event": { | |
| "type": "file_system_activity", | |
| "action": "renamed", | |
| "description": "Dosya yeniden adlandΔ±rΔ±ldΔ±: 1. Dosya - Kopya.txt -> 2. Dosya.txt" | |
| }, | |
| "user": { | |
| "user_id": "Berkan", | |
| "machine_id": "DESKTOP-7129HN9", | |
| "session_id": "DESKTOP-7129HN9_Berkan_20258987_233043" | |
| }, | |
| "metadata": { | |
| "old_file_path": "C:\\Users\\Berkan\\Downloads\\Yeni klasΓΆr\\1. Dosya - Kopya.txt", | |
| "new_file_path": "C:\\Users\\Berkan\\Downloads\\Yeni klasΓΆr\\2. Dosya.txt", | |
| "old_file_extension": ".txt", | |
| "new_file_extension": ".txt" | |
| } | |
| } | |
| EOF | |
| ) | |
| RESPONSE=$(curl -s -w "\n%{http_code}" \ | |
| -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| -d "$FILE_LOG" \ | |
| "$API_BASE_URL/api/logs") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | sed '$d') | |
| if [[ $HTTP_CODE == "200" ]]; then | |
| echo "β File system activity test passed" | |
| echo "Response: $BODY" | |
| else | |
| echo "β File system activity test failed (HTTP $HTTP_CODE)" | |
| echo "Response: $BODY" | |
| fi | |
| echo "" | |
| # Test 2: USB activity | |
| echo "π Test 2: USB activity (plug in)" | |
| USB_LOG=$(cat <<'EOF' | |
| { | |
| "id": "usb-test-12345", | |
| "timestamp": "2025-01-12T23:35:00.000Z", | |
| "event": { | |
| "type": "usb_activity", | |
| "action": "plugged_in", | |
| "description": "USB device connected: SanDisk Ultra USB 3.0 (32GB)" | |
| }, | |
| "user": { | |
| "user_id": "TestUser", | |
| "machine_id": "TEST-MACHINE-001", | |
| "session_id": "TEST-MACHINE-001_TestUser_20250112_233500" | |
| }, | |
| "metadata": { | |
| "deviceName": "SanDisk Ultra USB 3.0", | |
| "capacity": "32GB", | |
| "vendor": "SanDisk", | |
| "serialNumber": "ABC123DEF456", | |
| "deviceId": "VID_0781&PID_5591" | |
| } | |
| } | |
| EOF | |
| ) | |
| RESPONSE=$(curl -s -w "\n%{http_code}" \ | |
| -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| -d "$USB_LOG" \ | |
| "$API_BASE_URL/api/logs") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | sed '$d') | |
| if [[ $HTTP_CODE == "200" ]]; then | |
| echo "β USB activity test passed" | |
| echo "Response: $BODY" | |
| else | |
| echo "β USB activity test failed (HTTP $HTTP_CODE)" | |
| echo "Response: $BODY" | |
| fi | |
| echo "" | |
| # Test 3: Application activity | |
| echo "π± Test 3: Application activity" | |
| APP_LOG=$(cat <<'EOF' | |
| { | |
| "id": "app-test-67890", | |
| "timestamp": "2025-01-12T23:40:00.000Z", | |
| "event": { | |
| "type": "application_activity", | |
| "action": "started", | |
| "description": "Application started: Google Chrome" | |
| }, | |
| "user": { | |
| "user_id": "TestUser", | |
| "machine_id": "TEST-MACHINE-001", | |
| "session_id": "TEST-MACHINE-001_TestUser_20250112_234000" | |
| }, | |
| "metadata": { | |
| "application_name": "Google Chrome", | |
| "category": "Browser", | |
| "processId": 1234, | |
| "windowTitle": "New Tab - Google Chrome" | |
| } | |
| } | |
| EOF | |
| ) | |
| RESPONSE=$(curl -s -w "\n%{http_code}" \ | |
| -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| -d "$APP_LOG" \ | |
| "$API_BASE_URL/api/logs") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | sed '$d') | |
| if [[ $HTTP_CODE == "200" ]]; then | |
| echo "β Application activity test passed" | |
| echo "Response: $BODY" | |
| else | |
| echo "β Application activity test failed (HTTP $HTTP_CODE)" | |
| echo "Response: $BODY" | |
| fi | |
| echo "" | |
| # Test 4: Upload activity | |
| echo "π€ Test 4: Upload activity" | |
| UPLOAD_LOG=$(cat <<'EOF' | |
| { | |
| "id": "upload-test-11111", | |
| "timestamp": "2025-01-12T23:45:00.000Z", | |
| "event": { | |
| "type": "upload_activity", | |
| "action": "uploaded", | |
| "description": "File uploaded: document.pdf to Google Drive via Chrome" | |
| }, | |
| "user": { | |
| "user_id": "TestUser", | |
| "machine_id": "TEST-MACHINE-001", | |
| "session_id": "TEST-MACHINE-001_TestUser_20250112_234500" | |
| }, | |
| "metadata": { | |
| "file_name": "document.pdf", | |
| "file_size": 1048576, | |
| "upload_url": "https://drive.google.com/upload", | |
| "browser": "Chrome", | |
| "destination": "Google Drive" | |
| } | |
| } | |
| EOF | |
| ) | |
| RESPONSE=$(curl -s -w "\n%{http_code}" \ | |
| -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| -d "$UPLOAD_LOG" \ | |
| "$API_BASE_URL/api/logs") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | sed '$d') | |
| if [[ $HTTP_CODE == "200" ]]; then | |
| echo "β Upload activity test passed" | |
| echo "Response: $BODY" | |
| else | |
| echo "β Upload activity test failed (HTTP $HTTP_CODE)" | |
| echo "Response: $BODY" | |
| fi | |
| echo "" | |
| # Test 5: Health check | |
| echo "π₯ Test 5: Health check (GET request)" | |
| RESPONSE=$(curl -s -w "\n%{http_code}" \ | |
| -X GET \ | |
| "$API_BASE_URL/api/logs") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | sed '$d') | |
| if [[ $HTTP_CODE == "200" ]]; then | |
| echo "β Health check test passed" | |
| echo "Response: $BODY" | |
| else | |
| echo "β Health check test failed (HTTP $HTTP_CODE)" | |
| echo "Response: $BODY" | |
| fi | |
| echo "" | |
| echo "π All tests completed!" | |
| echo "" | |
| echo "To run the comprehensive agent demo:" | |
| echo " ./demo-agent-logs.sh $API_BASE_URL $DEVICE_API_KEY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment