Preserve login routes across rotation and keep rejected migrations read-only

This commit is contained in:
Codex
2026-10-11 19:15:05 +08:00
parent 915241a2fd
commit ab4e4a4f79
6 changed files with 68 additions and 12 deletions
+11
View File
@@ -97,3 +97,14 @@ def test_migration_rolls_back_every_table_on_bad_source(mysql, tmp_path):
migrate_sqlite(tmp_path / 'bad.db', mysql)
assert mysql.overview()['records'] == 0
assert mysql.overview()['scores'] == 0
def test_rejected_migration_cli_does_not_pause_destination_jobs(mysql, tmp_path):
import subprocess
import sys
source = Database(tmp_path / 'source.db')
mysql.job_create('existing-running-job', {'year': 2027})
mysql.job_update('existing-running-job', status='running')
result = subprocess.run([sys.executable, '-m', 'studio.migrate', str(source.path), '--config', os.environ['STUDIO_MYSQL_TEST_CONFIG']], capture_output=True, text=True)
assert result.returncode != 0
assert mysql.job_get('existing-running-job')['status'] == 'running'
+45 -2
View File
@@ -3,8 +3,10 @@ import random
import os
import pytest
from studio.auth import CookieVault
from tests.test_network import setup_network
from studio.auth import CookieVault, AuthService, LOGIN_URL, CATALOG_ENTRY
from studio.connectors import CatalogClient
from studio.network import RemoteUnavailable
from tests.test_network import setup_network, Remote, Response
def test_requests_sample_a_fresh_delay_inside_configured_bounds(tmp_path, monkeypatch):
@@ -45,6 +47,47 @@ def test_route_pin_defers_rotation_until_login_proof_finishes(tmp_path):
assert transport.request('GET', 'https://yz.chsi.com.cn/zsml/').json()['routed_through'] == 'http://5.6.7.8:9090'
class RouteBoundSession(Remote):
def __init__(self):
super().__init__()
self.bound = set()
self.form_route = None
def request(self, method, url, **kwargs):
route = kwargs.get('proxies', {}).get('https')
if url == LOGIN_URL and method == 'GET':
self.form_route = route
return Response({}, text='<input type="hidden" name="lt" value="test"><input type="hidden" name="execution" value="test">')
if url == LOGIN_URL and method == 'POST':
if route != self.form_route:
raise RemoteUnavailable('login form and credentials used different routes')
return Response({})
if url == CATALOG_ENTRY:
self.bound = {route}
return Response({})
if url.endswith('/yjfxs.do'):
return Response({'flag': True, 'msg': {'list': [{'direction': 'confirmed'}]}}) if route in self.bound else Response({'flag': False, 'msg': '请登录'})
return super().request(method, url, **kwargs)
@pytest.mark.parametrize('threshold', [1, 2])
def test_auth_recovery_preserves_proven_route_through_catalog_retry(tmp_path, threshold):
settings, _, transport = setup_network(tmp_path, remote=RouteBoundSession())
settings.update({'proxy_rotate_every': threshold})
auth = AuthService(transport, CookieVault(tmp_path))
assert auth.check()['valid']
payload = CatalogClient(transport, auth).fetch_page('yjfxs', {'curPage': 2, 'start': 10, 'pageSize': 10})
assert payload['list'][0]['direction'] == 'confirmed'
def test_credential_login_pins_form_submission_and_verification(tmp_path):
settings, _, transport = setup_network(tmp_path, remote=RouteBoundSession())
settings.update({'proxy_rotate_every': 2})
transport.request('GET', 'https://yz.chsi.com.cn/zsml/')
auth = AuthService(transport, CookieVault(tmp_path))
assert auth.login('test-user', 'test-password')['valid']
def test_linux_cookie_vault_encrypts_and_preserves_domain_cookies(tmp_path, monkeypatch):
monkeypatch.setattr(platform, 'system', lambda: 'Linux')
cookies = [{'name': 'JSESSIONID', 'value': 'private-account-cookie', 'domain': 'account.chsi.com.cn'},