claude-flow-novice 2.2.4 ā 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -8
- package/scripts/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/.claude-flow/metrics/performance.json +9 -0
- package/scripts/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/CLEANUP_OPTIMIZATION_REPORT.json +312 -0
- package/scripts/CLEANUP_PERFORMANCE_OPTIMIZATION.md +387 -0
- package/scripts/CLEANUP_QUICK_START.md +268 -0
- package/scripts/CLEANUP_TEST_RESULTS.md +205 -0
- package/scripts/README.md +339 -0
- package/scripts/ace-query.sh +384 -0
- package/scripts/agent-token-analysis.js +430 -0
- package/scripts/auto-setup.js +332 -0
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/build/validate-agents.js +238 -0
- package/scripts/build-index.js +43 -0
- package/scripts/build-orchestrator.js +320 -0
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/ci-validation.js +375 -0
- package/scripts/cleanup-blocking-coordination.sh +420 -0
- package/scripts/cleanup-idle-sessions.sh +59 -0
- package/scripts/collect-build-metrics.js +65 -0
- package/scripts/demo/README.md +79 -0
- package/scripts/demo/autoscaling-demo-simplified.js +963 -0
- package/scripts/demo/comprehensive-dashboard-test.js +693 -0
- package/scripts/demo/confidence-log.js +87 -0
- package/scripts/demo/confidence-report.js +82 -0
- package/scripts/demo/demo-multi-swarm-coordination.js +325 -0
- package/scripts/demo/demo-production-deployment.js +399 -0
- package/scripts/demo/demo-visualization-system.js +149 -0
- package/scripts/demo/performance-analysis.cjs +71 -0
- package/scripts/demo/performance-analysis.js +71 -0
- package/scripts/demo/test-autoscaling-demo.js +314 -0
- package/scripts/dependency-optimizer.js +349 -0
- package/scripts/dependency-security-assessment.js +331 -0
- package/scripts/deploy-sdk.sh +176 -0
- package/scripts/deployment-readiness-report.json +179 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/ecosystem.config.cjs +90 -0
- package/scripts/fix-js-extensions.js +167 -0
- package/scripts/generate-basic-types.js +73 -0
- package/scripts/generate-changelog.js +318 -0
- package/scripts/git-hooks/pre-commit.sh +143 -0
- package/scripts/health-checks.js +634 -0
- package/scripts/hook-wrapper.sh +54 -0
- package/scripts/install/README.md +375 -0
- package/scripts/install/REDIS_SETUP_VALIDATION.json +245 -0
- package/scripts/install/check-prerequisites.js +303 -0
- package/scripts/install/config-wizard.js +606 -0
- package/scripts/install/dependency-checker.js +385 -0
- package/scripts/install/health-check.js +765 -0
- package/scripts/install/install.js +256 -0
- package/scripts/install/installation-benchmark.js +461 -0
- package/scripts/install/quick-install.js +720 -0
- package/scripts/install/quick-start-wizard.js +295 -0
- package/scripts/install/redis-cli.js +289 -0
- package/scripts/install/redis-install-guides.md +407 -0
- package/scripts/install/redis-setup.js +559 -0
- package/scripts/install/redis-test.js +278 -0
- package/scripts/install/service-manager.js +672 -0
- package/scripts/install/setup.js +832 -0
- package/scripts/install/uninstall.js +526 -0
- package/scripts/install/update.js +461 -0
- package/scripts/install-pre-commit-hook.sh +127 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/memory-monitor-coordinator.js +322 -0
- package/scripts/migrate-to-sdk.sh +520 -0
- package/scripts/migration/QUICK-START.md +189 -0
- package/scripts/migration/QUICK-START.md.backup-1760135091363 +189 -0
- package/scripts/migration/README.md +464 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md +500 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md.backup-1760135091348 +500 -0
- package/scripts/migration/UPDATE-PATHS-README.md +464 -0
- package/scripts/migration/UPDATE-PATHS-README.md.backup-1760135091337 +464 -0
- package/scripts/migration/example-patterns.json +19 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/migration/reorganize-workspace.js +504 -0
- package/scripts/migration/test-update-paths.js +359 -0
- package/scripts/migration/update-paths.js +664 -0
- package/scripts/migration/validate-migration.js +647 -0
- package/scripts/monitor-loop.sh +65 -0
- package/scripts/monitor-memory.sh +47 -0
- package/scripts/monitor-migration.js +339 -0
- package/scripts/monitor.py +43 -0
- package/scripts/monitoring/README.md +178 -0
- package/scripts/monitoring/alert-monitor.sh +220 -0
- package/scripts/monitoring/analyze-resources.sh +199 -0
- package/scripts/monitoring/dashboards/rate-limiting-dashboard.json +211 -0
- package/scripts/monitoring/dynamic-monitor.sh +85 -0
- package/scripts/monitoring/launch-stability-test.sh +184 -0
- package/scripts/monitoring/monitor-test.sh +93 -0
- package/scripts/monitoring/pre-test-validation.sh +208 -0
- package/scripts/monitoring/quick-test-alerting.sh +118 -0
- package/scripts/monitoring/quick-test-rate-limiting.sh +206 -0
- package/scripts/monitoring/rate-limiting-monitor.sh +380 -0
- package/scripts/monitoring/resource-monitor.sh +126 -0
- package/scripts/monitoring/stability-monitor.js +429 -0
- package/scripts/monitoring/test-monitor-quick.sh +54 -0
- package/scripts/monitoring/view-alerts.sh +307 -0
- package/scripts/npm-metrics-collector.js +482 -0
- package/scripts/npm-package-validation.cjs +299 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/optimize-package-swarm.js +54 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-monitor.js +644 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/post-deployment-monitoring.js +350 -0
- package/scripts/post-edit-pipeline.js +2091 -0
- package/scripts/post-install-claude-md.js +78 -0
- package/scripts/postinstall.js +79 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/pre-publish-validation.js +429 -0
- package/scripts/redis-lua/cleanup-blocking-coordination.lua +198 -0
- package/scripts/release-announcement.js +425 -0
- package/scripts/release-notification.js +248 -0
- package/scripts/release-rollback.js +376 -0
- package/scripts/release-validation.js +460 -0
- package/scripts/rollback-sdk.sh +66 -0
- package/scripts/run-production-validation.ts +590 -0
- package/scripts/run-stability-validation.sh +687 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/deployment-validation.cjs +279 -0
- package/scripts/security/envelope-encryption-confidence-report.cjs +422 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/install-git-secrets.sh +295 -0
- package/scripts/security/rotate-api-keys.js +469 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/security/security-audit.cjs +538 -0
- package/scripts/security/setup-redis-auth.sh +397 -0
- package/scripts/security/validate-envelope-encryption.cjs +340 -0
- package/scripts/security-scan.js +492 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/switch-api.sh +158 -0
- package/scripts/sync-agents.js +290 -0
- package/scripts/test/50-agent-test.js +625 -0
- package/scripts/test/NEW_STABILITY_TEST_GUIDE.md +407 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/STABILITY_TEST_EXAMPLE.md +347 -0
- package/scripts/test/STABILITY_TEST_README.md +480 -0
- package/scripts/test/agent-worker.js +309 -0
- package/scripts/test/ai-coordination-test.js +650 -0
- package/scripts/test/ai-mesh-coordination-test.js +416 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/cli-agent-coordination-test.js +313 -0
- package/scripts/test/coordinator-multilingual-test.js +396 -0
- package/scripts/test/coordinator-transparency-demo.js +585 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/mesh-coordination-zero-overlap-test.js +740 -0
- package/scripts/test/multilingual-hello-world-test.js +390 -0
- package/scripts/test/quick-multilingual-demo.js +464 -0
- package/scripts/test/real-agent-test.js +312 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/run-stability-test-examples.sh +292 -0
- package/scripts/test/stability-results/stability-metrics.jsonl +83 -0
- package/scripts/test/stability-results/stability-test-report.json +128 -0
- package/scripts/test/stability-results/stability-test.log +1827 -0
- package/scripts/test/stability-test-50-agents.js +734 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/test-cleanup-performance.sh +416 -0
- package/scripts/test-dashboard-auth.cjs +203 -0
- package/scripts/test-docker-deployment.sh +207 -0
- package/scripts/test-npm-package.cjs +167 -0
- package/scripts/test-provider-routing.cjs +226 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-runner.cjs +154 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/validate-agent-hooks.js +506 -0
- package/scripts/validate-changelog.js +241 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/scripts/validate-docker-infrastructure.sh +502 -0
- package/scripts/validate-entry-points.js +300 -0
- package/scripts/validate-stage3-performance.ts +377 -0
- package/scripts/validate-template-bundling.js +180 -0
- package/scripts/validation/README.md +33 -0
- package/scripts/validation/acl-security-validation.cjs +214 -0
- package/scripts/validation/acl-security-validation.js +402 -0
- package/scripts/validation/byzantine-verification.js +407 -0
- package/scripts/validation/final-phase-2-consensus.cjs +219 -0
- package/scripts/validation/final-security-validation.js +791 -0
- package/scripts/validation/final-wasm-validation.cjs +840 -0
- package/scripts/validation/integration-test-analysis.js +105 -0
- package/scripts/validation/phase-0-comprehensive-validation.js +474 -0
- package/scripts/validation/phase-0-consensus-report.js +139 -0
- package/scripts/validation/phase-0-final-report.js +112 -0
- package/scripts/validation/phase-0-redis-consensus-report.js +129 -0
- package/scripts/validation/phase-0-validation-improved.js +490 -0
- package/scripts/validation/phase-0-validation-test.js +65 -0
- package/scripts/validation/phase-1-consensus-report.cjs +342 -0
- package/scripts/validation/phase-1-consensus-validation.cjs +551 -0
- package/scripts/validation/phase-1-consensus-validation.js +551 -0
- package/scripts/validation/phase-2-consensus-report.cjs +186 -0
- package/scripts/validation/phase-2-validation.cjs +171 -0
- package/scripts/validation/phase-2-validation.js +171 -0
- package/scripts/validation/phase-4-consensus-report.js +181 -0
- package/scripts/validation/phase-4-final-validation.js +351 -0
- package/scripts/validation/phase-5-consensus-report.cjs +113 -0
- package/scripts/validation/phase-5-consensus-report.js +113 -0
- package/scripts/validation/security-analysis.js +49 -0
- package/scripts/validation/security-validation.js +492 -0
- package/scripts/validation/simple-security-validation.js +464 -0
- package/scripts/verify-installation.js +112 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/scripts/verify-sdk-phase1.cjs +293 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# test-cleanup-performance.sh
|
|
4
|
+
# Performance validation script for cleanup-blocking-coordination.sh
|
|
5
|
+
#
|
|
6
|
+
# This script:
|
|
7
|
+
# 1. Populates Redis with 10,000 test coordinators (mix of active and stale)
|
|
8
|
+
# 2. Runs cleanup with timing
|
|
9
|
+
# 3. Verifies 100% stale key removal, 0% active key deletion
|
|
10
|
+
# 4. Reports performance metrics
|
|
11
|
+
#
|
|
12
|
+
# Success criteria:
|
|
13
|
+
# - <5s execution time for 10,000 coordinators
|
|
14
|
+
# - 100% stale key removal (TTL > 10 minutes)
|
|
15
|
+
# - 0% active key deletion (TTL < 10 minutes)
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
set -euo pipefail
|
|
19
|
+
|
|
20
|
+
# ===== CONFIGURATION =====
|
|
21
|
+
|
|
22
|
+
# Redis connection
|
|
23
|
+
REDIS_HOST="${REDIS_HOST:-127.0.0.1}"
|
|
24
|
+
REDIS_PORT="${REDIS_PORT:-6379}"
|
|
25
|
+
REDIS_PASSWORD="${REDIS_PASSWORD:-}"
|
|
26
|
+
REDIS_DB="${REDIS_DB:-0}"
|
|
27
|
+
|
|
28
|
+
# Test parameters
|
|
29
|
+
TOTAL_COORDINATORS=10000
|
|
30
|
+
STALE_COORDINATOR_COUNT=9900 # 99% stale
|
|
31
|
+
ACTIVE_COORDINATOR_COUNT=100 # 1% active
|
|
32
|
+
STALE_THRESHOLD_SECONDS=600 # 10 minutes
|
|
33
|
+
|
|
34
|
+
# Script paths
|
|
35
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
36
|
+
CLEANUP_SCRIPT="${SCRIPT_DIR}/cleanup-blocking-coordination.sh"
|
|
37
|
+
|
|
38
|
+
# ===== HELPER FUNCTIONS =====
|
|
39
|
+
|
|
40
|
+
# Redis command wrapper
|
|
41
|
+
redis_cmd() {
|
|
42
|
+
if [ -n "${REDIS_PASSWORD}" ]; then
|
|
43
|
+
redis-cli -h "${REDIS_HOST}" -p "${REDIS_PORT}" -a "${REDIS_PASSWORD}" -n "${REDIS_DB}" "$@" 2>/dev/null
|
|
44
|
+
else
|
|
45
|
+
redis-cli -h "${REDIS_HOST}" -p "${REDIS_PORT}" -n "${REDIS_DB}" "$@" 2>/dev/null
|
|
46
|
+
fi
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Color output
|
|
50
|
+
GREEN='\033[0;32m'
|
|
51
|
+
RED='\033[0;31m'
|
|
52
|
+
YELLOW='\033[1;33m'
|
|
53
|
+
NC='\033[0m' # No Color
|
|
54
|
+
|
|
55
|
+
log_success() {
|
|
56
|
+
echo -e "${GREEN}ā${NC} $*"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
log_error() {
|
|
60
|
+
echo -e "${RED}ā${NC} $*"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log_info() {
|
|
64
|
+
echo -e "${YELLOW}ā${NC} $*"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Get current timestamp in milliseconds
|
|
68
|
+
current_timestamp_ms() {
|
|
69
|
+
echo $(($(date +%s) * 1000))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Count keys matching pattern
|
|
73
|
+
count_keys() {
|
|
74
|
+
local pattern="$1"
|
|
75
|
+
local count=0
|
|
76
|
+
local cursor=0
|
|
77
|
+
|
|
78
|
+
while true; do
|
|
79
|
+
local result
|
|
80
|
+
result=$(redis_cmd SCAN "${cursor}" MATCH "${pattern}" COUNT 1000)
|
|
81
|
+
cursor=$(echo "${result}" | head -n 1)
|
|
82
|
+
local keys
|
|
83
|
+
keys=$(echo "${result}" | tail -n +2)
|
|
84
|
+
|
|
85
|
+
if [ -n "${keys}" ]; then
|
|
86
|
+
count=$((count + $(echo "${keys}" | wc -l)))
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
if [ "${cursor}" = "0" ]; then
|
|
90
|
+
break
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
|
|
94
|
+
echo "${count}"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# ===== TEST FUNCTIONS =====
|
|
98
|
+
|
|
99
|
+
# Clean up any existing test data
|
|
100
|
+
cleanup_test_data() {
|
|
101
|
+
log_info "Cleaning up any existing test data..."
|
|
102
|
+
|
|
103
|
+
local patterns=(
|
|
104
|
+
"blocking:heartbeat:test-coordinator-*"
|
|
105
|
+
"blocking:ack:test-coordinator-*"
|
|
106
|
+
"blocking:signal:test-coordinator-*"
|
|
107
|
+
"blocking:idempotency:*test-coordinator-*"
|
|
108
|
+
"coordinator:activity:test-coordinator-*"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
for pattern in "${patterns[@]}"; do
|
|
112
|
+
local cursor=0
|
|
113
|
+
while true; do
|
|
114
|
+
local result
|
|
115
|
+
result=$(redis_cmd SCAN "${cursor}" MATCH "${pattern}" COUNT 1000)
|
|
116
|
+
cursor=$(echo "${result}" | head -n 1)
|
|
117
|
+
local keys
|
|
118
|
+
keys=$(echo "${result}" | tail -n +2 | tr '\n' ' ')
|
|
119
|
+
|
|
120
|
+
if [ -n "${keys}" ]; then
|
|
121
|
+
redis_cmd DEL ${keys} >/dev/null
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
if [ "${cursor}" = "0" ]; then
|
|
125
|
+
break
|
|
126
|
+
fi
|
|
127
|
+
done
|
|
128
|
+
done
|
|
129
|
+
|
|
130
|
+
log_success "Test data cleaned up"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# Populate Redis with test coordinators
|
|
134
|
+
populate_test_data() {
|
|
135
|
+
log_info "Populating Redis with ${TOTAL_COORDINATORS} test coordinators..."
|
|
136
|
+
log_info " - ${STALE_COORDINATOR_COUNT} stale coordinators (age > 10 minutes)"
|
|
137
|
+
log_info " - ${ACTIVE_COORDINATOR_COUNT} active coordinators (age < 10 minutes)"
|
|
138
|
+
|
|
139
|
+
local current_time_ms
|
|
140
|
+
current_time_ms=$(current_timestamp_ms)
|
|
141
|
+
|
|
142
|
+
# Stale threshold timestamp (10 minutes ago)
|
|
143
|
+
local stale_timestamp_ms=$((current_time_ms - (STALE_THRESHOLD_SECONDS * 1000) - 60000)) # 11 minutes ago
|
|
144
|
+
|
|
145
|
+
# Active timestamp (1 minute ago)
|
|
146
|
+
local active_timestamp_ms=$((current_time_ms - 60000)) # 1 minute ago
|
|
147
|
+
|
|
148
|
+
# Use batch pipeline for faster insertion
|
|
149
|
+
local batch_size=1000
|
|
150
|
+
local coordinator_id
|
|
151
|
+
local timestamp_ms
|
|
152
|
+
|
|
153
|
+
# Populate stale coordinators
|
|
154
|
+
for ((i=1; i<=STALE_COORDINATOR_COUNT; i+=batch_size)); do
|
|
155
|
+
{
|
|
156
|
+
for ((j=i; j<i+batch_size && j<=STALE_COORDINATOR_COUNT; j++)); do
|
|
157
|
+
coordinator_id="test-coordinator-stale-${j}"
|
|
158
|
+
timestamp_ms="${stale_timestamp_ms}"
|
|
159
|
+
|
|
160
|
+
# Heartbeat key
|
|
161
|
+
echo "SET blocking:heartbeat:${coordinator_id} '{\"coordinatorId\":\"${coordinator_id}\",\"timestamp\":${timestamp_ms}}'"
|
|
162
|
+
|
|
163
|
+
# ACK keys (2 per coordinator)
|
|
164
|
+
echo "SET blocking:ack:${coordinator_id}:agent-1 '1'"
|
|
165
|
+
echo "SET blocking:ack:${coordinator_id}:agent-2 '1'"
|
|
166
|
+
|
|
167
|
+
# Signal key
|
|
168
|
+
echo "SET blocking:signal:${coordinator_id} 'CONTINUE'"
|
|
169
|
+
|
|
170
|
+
# Idempotency key
|
|
171
|
+
echo "SET blocking:idempotency:${coordinator_id}:init '1'"
|
|
172
|
+
|
|
173
|
+
# Activity tracking key
|
|
174
|
+
echo "SET coordinator:activity:${coordinator_id} '${timestamp_ms}'"
|
|
175
|
+
done
|
|
176
|
+
} | redis_cmd --pipe >/dev/null
|
|
177
|
+
|
|
178
|
+
if ((i % 1000 == 0)); then
|
|
179
|
+
log_info " Progress: ${i}/${STALE_COORDINATOR_COUNT} stale coordinators populated"
|
|
180
|
+
fi
|
|
181
|
+
done
|
|
182
|
+
|
|
183
|
+
# Populate active coordinators
|
|
184
|
+
for ((i=1; i<=ACTIVE_COORDINATOR_COUNT; i+=batch_size)); do
|
|
185
|
+
{
|
|
186
|
+
for ((j=i; j<i+batch_size && j<=ACTIVE_COORDINATOR_COUNT; j++)); do
|
|
187
|
+
coordinator_id="test-coordinator-active-${j}"
|
|
188
|
+
timestamp_ms="${active_timestamp_ms}"
|
|
189
|
+
|
|
190
|
+
# Heartbeat key
|
|
191
|
+
echo "SET blocking:heartbeat:${coordinator_id} '{\"coordinatorId\":\"${coordinator_id}\",\"timestamp\":${timestamp_ms}}'"
|
|
192
|
+
|
|
193
|
+
# ACK keys (2 per coordinator)
|
|
194
|
+
echo "SET blocking:ack:${coordinator_id}:agent-1 '1'"
|
|
195
|
+
echo "SET blocking:ack:${coordinator_id}:agent-2 '1'"
|
|
196
|
+
|
|
197
|
+
# Signal key
|
|
198
|
+
echo "SET blocking:signal:${coordinator_id} 'CONTINUE'"
|
|
199
|
+
|
|
200
|
+
# Idempotency key
|
|
201
|
+
echo "SET blocking:idempotency:${coordinator_id}:init '1'"
|
|
202
|
+
|
|
203
|
+
# Activity tracking key
|
|
204
|
+
echo "SET coordinator:activity:${coordinator_id} '${timestamp_ms}'"
|
|
205
|
+
done
|
|
206
|
+
} | redis_cmd --pipe >/dev/null
|
|
207
|
+
done
|
|
208
|
+
|
|
209
|
+
log_success "Test data populated successfully"
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
# Verify test data population
|
|
213
|
+
verify_test_data() {
|
|
214
|
+
log_info "Verifying test data..."
|
|
215
|
+
|
|
216
|
+
local heartbeat_count
|
|
217
|
+
heartbeat_count=$(count_keys "blocking:heartbeat:test-coordinator-*")
|
|
218
|
+
|
|
219
|
+
if [ "${heartbeat_count}" -ne "${TOTAL_COORDINATORS}" ]; then
|
|
220
|
+
log_error "Expected ${TOTAL_COORDINATORS} heartbeat keys, found ${heartbeat_count}"
|
|
221
|
+
return 1
|
|
222
|
+
fi
|
|
223
|
+
|
|
224
|
+
log_success "Test data verified: ${heartbeat_count} coordinators"
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
# Run cleanup and measure performance
|
|
228
|
+
run_cleanup_test() {
|
|
229
|
+
log_info "Running cleanup script (Lua-based)..."
|
|
230
|
+
|
|
231
|
+
local start_time
|
|
232
|
+
start_time=$(date +%s%3N)
|
|
233
|
+
|
|
234
|
+
# Run cleanup script
|
|
235
|
+
if ! bash "${CLEANUP_SCRIPT}"; then
|
|
236
|
+
log_error "Cleanup script failed"
|
|
237
|
+
return 1
|
|
238
|
+
fi
|
|
239
|
+
|
|
240
|
+
local end_time
|
|
241
|
+
end_time=$(date +%s%3N)
|
|
242
|
+
local execution_time_ms=$((end_time - start_time))
|
|
243
|
+
|
|
244
|
+
log_success "Cleanup completed in ${execution_time_ms}ms"
|
|
245
|
+
|
|
246
|
+
# Return execution time
|
|
247
|
+
echo "${execution_time_ms}"
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
# Verify cleanup results
|
|
251
|
+
verify_cleanup_results() {
|
|
252
|
+
log_info "Verifying cleanup results..."
|
|
253
|
+
|
|
254
|
+
# Count remaining heartbeat keys
|
|
255
|
+
local stale_heartbeat_count
|
|
256
|
+
stale_heartbeat_count=$(count_keys "blocking:heartbeat:test-coordinator-stale-*")
|
|
257
|
+
|
|
258
|
+
local active_heartbeat_count
|
|
259
|
+
active_heartbeat_count=$(count_keys "blocking:heartbeat:test-coordinator-active-*")
|
|
260
|
+
|
|
261
|
+
# Verify stale coordinators removed
|
|
262
|
+
if [ "${stale_heartbeat_count}" -ne 0 ]; then
|
|
263
|
+
log_error "Stale coordinator removal failed: ${stale_heartbeat_count} stale coordinators remaining (expected 0)"
|
|
264
|
+
return 1
|
|
265
|
+
fi
|
|
266
|
+
|
|
267
|
+
log_success "100% stale coordinator removal: ${STALE_COORDINATOR_COUNT} removed"
|
|
268
|
+
|
|
269
|
+
# Verify active coordinators preserved
|
|
270
|
+
if [ "${active_heartbeat_count}" -ne "${ACTIVE_COORDINATOR_COUNT}" ]; then
|
|
271
|
+
log_error "Active coordinator preservation failed: ${active_heartbeat_count} active coordinators remaining (expected ${ACTIVE_COORDINATOR_COUNT})"
|
|
272
|
+
return 1
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
log_success "100% active coordinator preservation: ${ACTIVE_COORDINATOR_COUNT} preserved"
|
|
276
|
+
|
|
277
|
+
# Verify related keys also removed
|
|
278
|
+
local stale_ack_count
|
|
279
|
+
stale_ack_count=$(count_keys "blocking:ack:test-coordinator-stale-*")
|
|
280
|
+
|
|
281
|
+
local stale_signal_count
|
|
282
|
+
stale_signal_count=$(count_keys "blocking:signal:test-coordinator-stale-*")
|
|
283
|
+
|
|
284
|
+
if [ "${stale_ack_count}" -ne 0 ] || [ "${stale_signal_count}" -ne 0 ]; then
|
|
285
|
+
log_error "Related key removal failed: ${stale_ack_count} ACK keys, ${stale_signal_count} signal keys remaining"
|
|
286
|
+
return 1
|
|
287
|
+
fi
|
|
288
|
+
|
|
289
|
+
log_success "100% related key removal verified"
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
# Run fallback test for comparison
|
|
293
|
+
run_fallback_test() {
|
|
294
|
+
log_info "Running fallback test for comparison..."
|
|
295
|
+
|
|
296
|
+
# Re-populate test data
|
|
297
|
+
cleanup_test_data
|
|
298
|
+
populate_test_data
|
|
299
|
+
|
|
300
|
+
log_info "Running cleanup script (bash fallback)..."
|
|
301
|
+
|
|
302
|
+
local start_time
|
|
303
|
+
start_time=$(date +%s%3N)
|
|
304
|
+
|
|
305
|
+
# Run cleanup script with fallback flag
|
|
306
|
+
if ! bash "${CLEANUP_SCRIPT}" --fallback; then
|
|
307
|
+
log_error "Cleanup script (fallback) failed"
|
|
308
|
+
return 1
|
|
309
|
+
fi
|
|
310
|
+
|
|
311
|
+
local end_time
|
|
312
|
+
end_time=$(date +%s%3N)
|
|
313
|
+
local execution_time_ms=$((end_time - start_time))
|
|
314
|
+
|
|
315
|
+
log_success "Cleanup (fallback) completed in ${execution_time_ms}ms"
|
|
316
|
+
|
|
317
|
+
# Return execution time
|
|
318
|
+
echo "${execution_time_ms}"
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
# ===== MAIN EXECUTION =====
|
|
322
|
+
|
|
323
|
+
main() {
|
|
324
|
+
echo "========================================"
|
|
325
|
+
echo "Cleanup Performance Test"
|
|
326
|
+
echo "========================================"
|
|
327
|
+
echo ""
|
|
328
|
+
|
|
329
|
+
# Check prerequisites
|
|
330
|
+
if ! command -v redis-cli >/dev/null 2>&1; then
|
|
331
|
+
log_error "redis-cli not found, please install Redis"
|
|
332
|
+
exit 1
|
|
333
|
+
fi
|
|
334
|
+
|
|
335
|
+
if ! redis_cmd PING >/dev/null 2>&1; then
|
|
336
|
+
log_error "Redis connection failed (host: ${REDIS_HOST}, port: ${REDIS_PORT})"
|
|
337
|
+
exit 1
|
|
338
|
+
fi
|
|
339
|
+
|
|
340
|
+
if [ ! -f "${CLEANUP_SCRIPT}" ]; then
|
|
341
|
+
log_error "Cleanup script not found: ${CLEANUP_SCRIPT}"
|
|
342
|
+
exit 1
|
|
343
|
+
fi
|
|
344
|
+
|
|
345
|
+
log_success "Prerequisites verified"
|
|
346
|
+
echo ""
|
|
347
|
+
|
|
348
|
+
# Phase 1: Test Lua implementation
|
|
349
|
+
echo "Phase 1: Lua Implementation Test"
|
|
350
|
+
echo "========================================"
|
|
351
|
+
|
|
352
|
+
cleanup_test_data
|
|
353
|
+
populate_test_data
|
|
354
|
+
verify_test_data
|
|
355
|
+
|
|
356
|
+
echo ""
|
|
357
|
+
local lua_execution_time_ms
|
|
358
|
+
lua_execution_time_ms=$(run_cleanup_test)
|
|
359
|
+
|
|
360
|
+
echo ""
|
|
361
|
+
verify_cleanup_results
|
|
362
|
+
|
|
363
|
+
echo ""
|
|
364
|
+
echo "========================================"
|
|
365
|
+
echo "Lua Implementation Results:"
|
|
366
|
+
echo " Execution time: ${lua_execution_time_ms}ms"
|
|
367
|
+
echo " Performance: $(awk "BEGIN {printf \"%.2f\", ${TOTAL_COORDINATORS} / (${lua_execution_time_ms} / 1000.0)}")" coordinators/sec
|
|
368
|
+
echo " Target: <5000ms (5 seconds)"
|
|
369
|
+
|
|
370
|
+
if [ "${lua_execution_time_ms}" -lt 5000 ]; then
|
|
371
|
+
log_success "Performance target met (${lua_execution_time_ms}ms < 5000ms)"
|
|
372
|
+
else
|
|
373
|
+
log_error "Performance target missed (${lua_execution_time_ms}ms >= 5000ms)"
|
|
374
|
+
fi
|
|
375
|
+
echo "========================================"
|
|
376
|
+
echo ""
|
|
377
|
+
|
|
378
|
+
# Phase 2: Test bash fallback for comparison
|
|
379
|
+
echo "Phase 2: Bash Fallback Comparison Test"
|
|
380
|
+
echo "========================================"
|
|
381
|
+
|
|
382
|
+
local fallback_execution_time_ms
|
|
383
|
+
fallback_execution_time_ms=$(run_fallback_test)
|
|
384
|
+
|
|
385
|
+
echo ""
|
|
386
|
+
echo "========================================"
|
|
387
|
+
echo "Bash Fallback Results:"
|
|
388
|
+
echo " Execution time: ${fallback_execution_time_ms}ms"
|
|
389
|
+
echo " Performance: $(awk "BEGIN {printf \"%.2f\", ${TOTAL_COORDINATORS} / (${fallback_execution_time_ms} / 1000.0)}")" coordinators/sec
|
|
390
|
+
echo "========================================"
|
|
391
|
+
echo ""
|
|
392
|
+
|
|
393
|
+
# Performance comparison
|
|
394
|
+
echo "Performance Comparison:"
|
|
395
|
+
echo "========================================"
|
|
396
|
+
echo " Lua implementation: ${lua_execution_time_ms}ms"
|
|
397
|
+
echo " Bash fallback: ${fallback_execution_time_ms}ms"
|
|
398
|
+
echo " Speedup: $(awk "BEGIN {printf \"%.1f\", ${fallback_execution_time_ms} / ${lua_execution_time_ms}}")x faster"
|
|
399
|
+
echo "========================================"
|
|
400
|
+
echo ""
|
|
401
|
+
|
|
402
|
+
# Final cleanup
|
|
403
|
+
log_info "Cleaning up test data..."
|
|
404
|
+
cleanup_test_data
|
|
405
|
+
log_success "Test completed successfully"
|
|
406
|
+
|
|
407
|
+
# Exit with success if performance target met
|
|
408
|
+
if [ "${lua_execution_time_ms}" -lt 5000 ]; then
|
|
409
|
+
exit 0
|
|
410
|
+
else
|
|
411
|
+
exit 1
|
|
412
|
+
fi
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
# Execute main function
|
|
416
|
+
main "$@"
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dashboard Authentication Security Validation Test
|
|
5
|
+
* Tests the secure authentication implementation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const AuthenticationService = require('../monitor/dashboard/auth-service.cjs');
|
|
9
|
+
|
|
10
|
+
async function runAuthenticationTests() {
|
|
11
|
+
console.log('š Dashboard Authentication Security Validation\n');
|
|
12
|
+
|
|
13
|
+
const results = {
|
|
14
|
+
passed: 0,
|
|
15
|
+
failed: 0,
|
|
16
|
+
confidence: 0,
|
|
17
|
+
tests: []
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function recordTest(name, passed, details = '') {
|
|
21
|
+
results.tests.push({ name, passed, details });
|
|
22
|
+
if (passed) {
|
|
23
|
+
results.passed++;
|
|
24
|
+
console.log(`ā
${name}`);
|
|
25
|
+
} else {
|
|
26
|
+
results.failed++;
|
|
27
|
+
console.log(`ā ${name}${details ? ': ' + details : ''}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Test 1: Environment variable validation
|
|
32
|
+
console.log('Test 1: Environment Variable Configuration');
|
|
33
|
+
const envVarsPresent =
|
|
34
|
+
process.env.DASHBOARD_ADMIN_USER &&
|
|
35
|
+
process.env.DASHBOARD_ADMIN_PASS_HASH &&
|
|
36
|
+
process.env.DASHBOARD_SESSION_SECRET;
|
|
37
|
+
|
|
38
|
+
if (!envVarsPresent) {
|
|
39
|
+
console.log('ā ļø Setting test environment variables...\n');
|
|
40
|
+
|
|
41
|
+
// Set test credentials (bcrypt hash of "test123")
|
|
42
|
+
process.env.DASHBOARD_ADMIN_USER = 'admin';
|
|
43
|
+
process.env.DASHBOARD_ADMIN_PASS_HASH = '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyB4YqZ8T0u6';
|
|
44
|
+
process.env.DASHBOARD_MONITOR_USER = 'monitor';
|
|
45
|
+
process.env.DASHBOARD_MONITOR_PASS_HASH = '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyB4YqZ8T0u6';
|
|
46
|
+
process.env.DASHBOARD_SESSION_SECRET = 'test-session-secret-minimum-32-characters-long-for-security';
|
|
47
|
+
process.env.DASHBOARD_SESSION_TIMEOUT_HOURS = '1';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Test 2: Service initialization
|
|
51
|
+
console.log('\nTest 2: Authentication Service Initialization');
|
|
52
|
+
let authService;
|
|
53
|
+
try {
|
|
54
|
+
authService = new AuthenticationService();
|
|
55
|
+
recordTest('Service initialized successfully', true);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
recordTest('Service initialization', false, error.message);
|
|
58
|
+
return results;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Test 3: Configuration validation
|
|
62
|
+
console.log('\nTest 3: Configuration Validation');
|
|
63
|
+
try {
|
|
64
|
+
authService.validateConfiguration();
|
|
65
|
+
recordTest('Configuration validation passed', true);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
recordTest('Configuration validation', false, error.message);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Test 4: Valid authentication
|
|
71
|
+
console.log('\nTest 4: Valid Authentication');
|
|
72
|
+
try {
|
|
73
|
+
const result = await authService.authenticate('admin', 'test123');
|
|
74
|
+
recordTest('Valid credentials accepted', result !== null);
|
|
75
|
+
if (result) {
|
|
76
|
+
recordTest('Session token generated', !!result.token);
|
|
77
|
+
recordTest('User role included', !!result.user.role);
|
|
78
|
+
recordTest('Expiration time set', !!result.expiresAt);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
recordTest('Valid authentication', false, error.message);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Test 5: Invalid authentication
|
|
85
|
+
console.log('\nTest 5: Invalid Authentication');
|
|
86
|
+
try {
|
|
87
|
+
const result = await authService.authenticate('admin', 'wrongpassword');
|
|
88
|
+
recordTest('Invalid credentials rejected', result === null);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
recordTest('Invalid authentication handling', false, error.message);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Test 6: Session validation
|
|
94
|
+
console.log('\nTest 6: Session Validation');
|
|
95
|
+
try {
|
|
96
|
+
const authResult = await authService.authenticate('admin', 'test123');
|
|
97
|
+
if (authResult) {
|
|
98
|
+
const session = authService.validateSession(authResult.token);
|
|
99
|
+
recordTest('Valid session recognized', session !== null);
|
|
100
|
+
recordTest('Session username correct', session?.username === 'admin');
|
|
101
|
+
recordTest('Session role correct', session?.role === 'admin');
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
recordTest('Session validation', false, error.message);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Test 7: Invalid session
|
|
108
|
+
console.log('\nTest 7: Invalid Session Handling');
|
|
109
|
+
const invalidSession = authService.validateSession('invalid-token');
|
|
110
|
+
recordTest('Invalid token rejected', invalidSession === null);
|
|
111
|
+
|
|
112
|
+
// Test 8: Session revocation
|
|
113
|
+
console.log('\nTest 8: Session Revocation');
|
|
114
|
+
try {
|
|
115
|
+
const authResult = await authService.authenticate('monitor', 'test123');
|
|
116
|
+
if (authResult) {
|
|
117
|
+
authService.revokeSession(authResult.token);
|
|
118
|
+
const revokedSession = authService.validateSession(authResult.token);
|
|
119
|
+
recordTest('Revoked session invalidated', revokedSession === null);
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
recordTest('Session revocation', false, error.message);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Test 9: Bcrypt hash validation
|
|
126
|
+
console.log('\nTest 9: Bcrypt Hash Validation');
|
|
127
|
+
const validHash = '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyB4YqZ8T0u6';
|
|
128
|
+
const invalidHash = 'plaintext-password';
|
|
129
|
+
recordTest('Valid bcrypt hash recognized', authService.isBcryptHash(validHash));
|
|
130
|
+
recordTest('Invalid hash rejected', !authService.isBcryptHash(invalidHash));
|
|
131
|
+
|
|
132
|
+
// Test 10: Session statistics
|
|
133
|
+
console.log('\nTest 10: Session Statistics');
|
|
134
|
+
const stats = authService.getSessionStatistics();
|
|
135
|
+
recordTest('Statistics returned', !!stats);
|
|
136
|
+
recordTest('User count correct', stats.users >= 2);
|
|
137
|
+
|
|
138
|
+
// Test 11: Password hashing utility
|
|
139
|
+
console.log('\nTest 11: Password Hashing Utility');
|
|
140
|
+
try {
|
|
141
|
+
const hash = await AuthenticationService.hashPassword('testpassword', 12);
|
|
142
|
+
recordTest('Password hashing works', authService.isBcryptHash(hash));
|
|
143
|
+
} catch (error) {
|
|
144
|
+
recordTest('Password hashing', false, error.message);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Test 12: Constant-time comparison (timing attack protection)
|
|
148
|
+
console.log('\nTest 12: Timing Attack Protection');
|
|
149
|
+
try {
|
|
150
|
+
const start1 = Date.now();
|
|
151
|
+
await authService.authenticate('nonexistent', 'password');
|
|
152
|
+
const time1 = Date.now() - start1;
|
|
153
|
+
|
|
154
|
+
const start2 = Date.now();
|
|
155
|
+
await authService.authenticate('admin', 'wrongpassword');
|
|
156
|
+
const time2 = Date.now() - start2;
|
|
157
|
+
|
|
158
|
+
// Times should be similar (within 50ms) to prevent timing attacks
|
|
159
|
+
const timeDiff = Math.abs(time1 - time2);
|
|
160
|
+
recordTest('Timing attack protection', timeDiff < 50, `Difference: ${timeDiff}ms`);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
recordTest('Timing attack protection', false, error.message);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Test 13: No hardcoded credentials
|
|
166
|
+
console.log('\nTest 13: No Hardcoded Credentials');
|
|
167
|
+
const fs = require('fs');
|
|
168
|
+
const serverContent = fs.readFileSync(__dirname + '/../monitor/dashboard/server.js', 'utf8');
|
|
169
|
+
const hasHardcodedCreds = /password:\s*['"](?!process\.env)/.test(serverContent);
|
|
170
|
+
recordTest('No hardcoded passwords in server.js', !hasHardcodedCreds);
|
|
171
|
+
|
|
172
|
+
// Calculate confidence score
|
|
173
|
+
const totalTests = results.passed + results.failed;
|
|
174
|
+
results.confidence = totalTests > 0 ? (results.passed / totalTests) : 0;
|
|
175
|
+
|
|
176
|
+
// Summary
|
|
177
|
+
console.log('\n' + '='.repeat(60));
|
|
178
|
+
console.log('š Test Summary');
|
|
179
|
+
console.log('='.repeat(60));
|
|
180
|
+
console.log(`Total Tests: ${totalTests}`);
|
|
181
|
+
console.log(`Passed: ${results.passed} ā
`);
|
|
182
|
+
console.log(`Failed: ${results.failed} ā`);
|
|
183
|
+
console.log(`Confidence Score: ${(results.confidence * 100).toFixed(2)}%`);
|
|
184
|
+
console.log('='.repeat(60));
|
|
185
|
+
|
|
186
|
+
if (results.confidence >= 0.75) {
|
|
187
|
+
console.log('\nā
Authentication security validation PASSED (ā„0.75 threshold)');
|
|
188
|
+
} else {
|
|
189
|
+
console.log('\nā Authentication security validation FAILED (<0.75 threshold)');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return results;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Run tests
|
|
196
|
+
runAuthenticationTests()
|
|
197
|
+
.then(results => {
|
|
198
|
+
process.exit(results.confidence >= 0.75 ? 0 : 1);
|
|
199
|
+
})
|
|
200
|
+
.catch(error => {
|
|
201
|
+
console.error('Test execution error:', error);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
});
|