- Migrated from HIVE branding to WHOOSH across all components - Enhanced backend API with new services: AI models, BZZZ integration, templates, members - Added comprehensive testing suite with security, performance, and integration tests - Improved frontend with new components for project setup, AI models, and team management - Updated MCP server implementation with WHOOSH-specific tools and resources - Enhanced deployment configurations with production-ready Docker setups - Added comprehensive documentation and setup guides - Implemented age encryption service and UCXL integration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
123 lines
4.7 KiB
Python
123 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for Age service functionality.
|
|
"""
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
# Add the backend to Python path
|
|
sys.path.append(str(Path(__file__).parent))
|
|
|
|
from app.services.age_service import AgeService
|
|
|
|
def test_age_service():
|
|
"""Test basic Age service functionality."""
|
|
print("🔐 Testing Age Service")
|
|
print("=" * 50)
|
|
|
|
try:
|
|
# Initialize Age service
|
|
age_service = AgeService()
|
|
print(f"✅ Age service initialized")
|
|
print(f" Age binary: {age_service.age_binary}")
|
|
print(f" Keys storage: {age_service.keys_storage_path}")
|
|
|
|
# Test key generation (without passphrase first)
|
|
print("\n🔑 Testing key generation...")
|
|
project_id = "test-project-age"
|
|
|
|
result = age_service.generate_master_key_pair(
|
|
project_id=project_id,
|
|
passphrase=None # Test without passphrase first
|
|
)
|
|
|
|
print(f"✅ Key pair generated successfully")
|
|
print(f" Key ID: {result['key_id']}")
|
|
print(f" Public key: {result['public_key']}")
|
|
print(f" Private key stored: {result['private_key_stored']}")
|
|
print(f" Encrypted: {result['encrypted']}")
|
|
|
|
# Test key listing
|
|
print("\n📋 Testing key listing...")
|
|
keys = age_service.list_project_keys(project_id)
|
|
print(f"✅ Found {len(keys)} keys for project {project_id}")
|
|
|
|
if keys:
|
|
key = keys[0]
|
|
print(f" Key ID: {key['key_id']}")
|
|
print(f" Created: {key['created_at']}")
|
|
print(f" Encrypted: {key['encrypted']}")
|
|
|
|
# Test key validation
|
|
print("\n🔍 Testing key validation...")
|
|
if keys:
|
|
key_id = keys[0]['key_id']
|
|
validation = age_service.validate_key_access(project_id, key_id)
|
|
print(f"✅ Key validation completed")
|
|
print(f" Accessible: {validation['accessible']}")
|
|
print(f" Private key exists: {validation['private_key_exists']}")
|
|
print(f" Public key exists: {validation['public_key_exists']}")
|
|
print(f" Metadata exists: {validation['metadata_exists']}")
|
|
|
|
# Test encryption/decryption
|
|
print("\n🔒 Testing encryption/decryption...")
|
|
if keys:
|
|
public_key = keys[0]['public_key']
|
|
test_data = "This is a test message for Age encryption!"
|
|
|
|
# Encrypt data
|
|
encrypted_data = age_service.encrypt_data(test_data, [public_key])
|
|
print(f"✅ Data encrypted successfully")
|
|
print(f" Original: {test_data}")
|
|
print(f" Encrypted length: {len(encrypted_data)} characters")
|
|
|
|
# Test decryption (would need private key and passphrase)
|
|
try:
|
|
private_key = age_service.decrypt_private_key(
|
|
project_id, key_id, None # No passphrase for unencrypted key
|
|
)
|
|
|
|
decrypted_data = age_service.decrypt_data(encrypted_data, private_key)
|
|
print(f"✅ Data decrypted successfully")
|
|
print(f" Decrypted: {decrypted_data}")
|
|
print(f" Match: {decrypted_data == test_data}")
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ Decryption test skipped: {e}")
|
|
|
|
# Test backup
|
|
print("\n💾 Testing key backup...")
|
|
if keys:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
backup_success = age_service.backup_key(
|
|
project_id, key_id, temp_dir
|
|
)
|
|
print(f"✅ Backup test: {backup_success}")
|
|
|
|
# Check backup files
|
|
backup_files = list(Path(temp_dir).glob("*"))
|
|
print(f" Backup files created: {len(backup_files)}")
|
|
for file in backup_files:
|
|
print(f" - {file.name}")
|
|
|
|
# Test recovery phrase generation
|
|
print("\n🔤 Testing recovery phrase...")
|
|
if keys:
|
|
recovery_phrase = age_service.generate_recovery_phrase(project_id, key_id)
|
|
print(f"✅ Recovery phrase generated")
|
|
print(f" Phrase: {recovery_phrase}")
|
|
print(f" Word count: {len(recovery_phrase.split())}")
|
|
|
|
print(f"\n🎉 All Age service tests completed successfully!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Age service test failed: {e}")
|
|
import traceback
|
|
print(f" Traceback: {traceback.format_exc()}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = test_age_service()
|
|
sys.exit(0 if success else 1) |