Files
IKAR/tool/seed_admin_ui_test.py
T
sevenhill b4c27da560
Tests / test (push) Canceled after 0s
Native crypto / native-crypto (push) Canceled after 0s
Release (main) / android (oneme) (push) Canceled after 0s
Release (main) / android (qlyra) (push) Canceled after 0s
Release (main) / windows (push) Canceled after 0s
Release (main) / linux (push) Canceled after 0s
Release (main) / macos (push) Canceled after 0s
Release (main) / ios (push) Canceled after 0s
Release (main) / release (push) Canceled after 0s
Add full IKAR administration console with secure session controls
2026-10-07 23:42:02 +03:00

40 lines
2.8 KiB
Python

"""Seed the isolated local admin UI test database; never accepts a production path."""
import json, sqlite3, uuid
from datetime import datetime, timezone
from pathlib import Path
repo = Path(__file__).resolve().parent.parent
server = json.loads((repo / 'artifacts/admin-local-server.json').read_text(encoding='utf-8-sig'))
root = Path(server['root']).resolve()
if not root.name.startswith('ikar-admin-ui-') or server['url'] != 'http://127.0.0.1:15199':
raise RuntimeError('Only the isolated loopback fixture is allowed')
db = sqlite3.connect(root / 'Data/ikar.db')
db.execute('PRAGMA foreign_keys=ON')
now = datetime.now(timezone.utc).isoformat()
def row(table, values):
for _, name, kind, required, default, primary in db.execute(f'PRAGMA table_info("{table}")'):
if name not in values and required and default is None and not primary:
values[name] = 0 if kind == 'INTEGER' else now if name.endswith(('At', 'Until')) else ''
fields = ','.join('"' + key + '"' for key in values)
db.execute(f'INSERT INTO "{table}" ({fields}) VALUES ({",".join("?" for _ in values)})', list(values.values()))
def user(name, bot=False):
identifier = str(uuid.uuid4()).upper()
row('Users', {'Id': identifier, 'Username': name, 'NormalizedUsername': name.upper(), 'DisplayName': name, 'IsBot': int(bot)})
return identifier
owner = user('UI пользователь <script>alert(1)</script>')
botuser = user('ui-test-bot', True)
for number in range(29): user(f'UI пользователь {number:02}')
session = str(uuid.uuid4()).upper()
row('UserSessions', {'Id': session, 'UserId': owner, 'TokenHash': 'test-fixture-secret', 'ClientPlatform': 'android', 'ClientVersionCode': 5, 'ClientVersionName': '1.0.4'})
chat = str(uuid.uuid4()).upper()
row('Chats', {'Id': chat, 'Type': 2, 'Title': 'UI группа', 'CreatedById': owner, 'ReactionSettingsJson': '{}'})
row('ChatMembers', {'ChatId': chat, 'UserId': owner, 'IsOwner': 1, 'Role': 2})
message = str(uuid.uuid4()).upper()
row('Messages', {'Id': message, 'ChatId': chat, 'SenderId': owner, 'Text': 'Сообщение для проверки модерации'})
bot = str(uuid.uuid4()).upper()
row('Bots', {'Id': bot, 'UserId': botuser, 'OwnerUserId': owner, 'TokenHash': 'not-exposed-test-secret', 'IsEnabled': 1})
row('ModerationCases', {'SourceLogId': 100001, 'ReporterId': owner, 'ReporterName': 'UI заявитель', 'TargetKind': 'message', 'TargetId': message, 'ChatId': chat, 'PayloadJson': '{"reasonId":1,"typeId":4,"ids":[1]}', 'Status': 'open', 'CreatedUnixMs': int(datetime.now(timezone.utc).timestamp()*1000)})
db.commit(); db.close()
(repo / 'artifacts/admin-ui-fixture.json').write_text(json.dumps({'userId': owner.lower(), 'chatId': chat.lower(), 'messageId': message.lower(), 'botId': bot.lower()}))
print(json.dumps({'seeded': True, 'users': 32, 'reports': 1}))