-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bot.py
More file actions
135 lines (109 loc) Β· 4.8 KB
/
Copy pathtest_bot.py
File metadata and controls
135 lines (109 loc) Β· 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
"""
Simple test script for SecShare bot components
"""
import os
import sys
import asyncio
import tempfile
from pathlib import Path
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from SecShare import SecShareBot
async def test_secshare_bot():
"""Test the SecShare bot functionality"""
print("π§ͺ Testing SecShare Bot Components...")
# Initialize bot with dummy token
bot = SecShareBot("dummy_token")
# Use a different user ID to avoid hitting limits
test_user_id = 99999
# Test 1: User creation and management
print("\n1. Testing user management...")
user = bot._get_user(test_user_id, "testuser")
print(f"β
User created: {user.user_id}, Premium: {user.is_premium}")
# Test 2: Text transfer creation
print("\n2. Testing text transfer creation...")
try:
transfer_id = await bot.create_text_transfer(test_user_id, "Hello, this is a test message!")
print(f"β
Text transfer created: {transfer_id}")
# Test 3: Text transfer retrieval
print("\n3. Testing text transfer retrieval...")
transfer = bot.get_transfer(transfer_id)
if transfer:
print(f"β
Transfer retrieved: {transfer.transfer_id}")
print(f" Is file: {transfer.is_file}")
print(f" Has password: {transfer.password_hash is not None}")
else:
print("β Failed to retrieve transfer")
except Exception as e:
print(f"β Error creating text transfer: {e}")
# Test 4: File transfer creation
print("\n4. Testing file transfer creation...")
try:
# Create a temporary test file
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt') as f:
f.write("This is a test file content")
temp_file_path = f.name
transfer_id = await bot.create_file_transfer(test_user_id, temp_file_path, "test.txt", 1024)
print(f"β
File transfer created: {transfer_id}")
# Test 5: File transfer retrieval
print("\n5. Testing file transfer retrieval...")
transfer = bot.get_transfer(transfer_id)
if transfer:
print(f"β
File transfer retrieved: {transfer.transfer_id}")
print(f" File name: {transfer.file_name}")
print(f" File size: {transfer.file_size}")
print(f" File path exists: {os.path.exists(transfer.file_path)}")
else:
print("β Failed to retrieve file transfer")
# Clean up temp file
os.unlink(temp_file_path)
except Exception as e:
print(f"β Error creating file transfer: {e}")
# Test 6: User stats
print("\n6. Testing user stats...")
stats = bot.get_user_stats(test_user_id)
print(f"β
User stats: {stats}")
# Test 7: Password protection
print("\n7. Testing password protection...")
try:
transfer_id = await bot.create_text_transfer(test_user_id, "Secret message", "mypassword")
print(f"β
Password-protected transfer created: {transfer_id}")
# Try to get without password (should fail)
transfer = bot.get_transfer(transfer_id)
if transfer is None:
print("β
Password protection working (no access without password)")
else:
print("β Password protection not working")
# Try to get with wrong password (should fail)
transfer = bot.get_transfer(transfer_id, "wrongpassword")
if transfer is None:
print("β
Wrong password correctly rejected")
else:
print("β Wrong password accepted")
# Try to get with correct password (should succeed)
transfer = bot.get_transfer(transfer_id, "mypassword")
if transfer:
print("β
Correct password accepted")
else:
print("β Correct password rejected")
except Exception as e:
print(f"β Error testing password protection: {e}")
# Test 8: Directory permissions
print("\n8. Testing directory permissions...")
temp_dir = bot.config['temp_dir']
data_dir = bot.config['data_dir']
print(f" Temp directory: {temp_dir} (exists: {os.path.exists(temp_dir)})")
print(f" Data directory: {data_dir} (exists: {os.path.exists(data_dir)})")
# Test write permissions
try:
test_file = os.path.join(temp_dir, "test_write.tmp")
with open(test_file, 'w') as f:
f.write("test")
os.remove(test_file)
print("β
Temp directory is writable")
except Exception as e:
print(f"β Temp directory not writable: {e}")
print("\nπ Testing completed!")
if __name__ == "__main__":
asyncio.run(test_secshare_bot())