fix: preserve data granularity and recover tasks safely
This commit is contained in:
+38
-1
@@ -3,7 +3,7 @@ import pytest
|
||||
|
||||
from studio.network import ProxyRouter, Transport, ProxyUnavailable
|
||||
from studio.settings import SettingsStore
|
||||
from studio.auth import CookieVault
|
||||
from studio.auth import CookieVault, AuthService
|
||||
|
||||
|
||||
class Response:
|
||||
@@ -91,3 +91,40 @@ def test_cookie_is_encrypted_and_not_returned_in_settings(tmp_path):
|
||||
assert b"secret-test-cookie" not in vault.path.read_bytes()
|
||||
assert "cookie" not in SettingsStore(tmp_path).read()
|
||||
|
||||
|
||||
def test_rate_limiting_does_not_quarantine_a_healthy_proxy(tmp_path):
|
||||
class Limited(Remote):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.calls = 0
|
||||
def request(self, *args, **kwargs):
|
||||
self.calls += 1
|
||||
if self.calls == 1:
|
||||
return Response({}, status=429)
|
||||
return super().request(*args, **kwargs)
|
||||
_, router, transport = setup_network(tmp_path, remote=Limited())
|
||||
original = router.resolve()
|
||||
assert transport.request("GET", "https://yz.chsi.com.cn/zsml/").json()["routed_through"] == original
|
||||
assert router.failed == set()
|
||||
|
||||
|
||||
def test_browser_cookie_domains_preserve_same_name_sessions(tmp_path):
|
||||
_, _, transport = setup_network(tmp_path)
|
||||
vault = CookieVault(tmp_path)
|
||||
vault.save([{"name": "JSESSIONID", "value": "account-cookie", "domain": "account.chsi.com.cn", "path": "/"}, {"name": "JSESSIONID", "value": "catalog-cookie", "domain": "yz.chsi.com.cn", "path": "/"}])
|
||||
AuthService(transport, vault)
|
||||
cookies = transport.session.cookies
|
||||
assert cookies.get("JSESSIONID", domain="account.chsi.com.cn") == "account-cookie"
|
||||
assert cookies.get("JSESSIONID", domain="yz.chsi.com.cn") == "catalog-cookie"
|
||||
|
||||
|
||||
def test_auth_checks_protected_direction_api_rather_than_public_school_index(tmp_path):
|
||||
class PublicIndex(Remote):
|
||||
def request(self, method, url, **kwargs):
|
||||
if url.endswith('/dws.do'):
|
||||
return Response({'flag': True, 'msg': {'list': []}})
|
||||
return Response({'flag': False, 'msg': '请登录'})
|
||||
_, _, transport = setup_network(tmp_path, remote=PublicIndex())
|
||||
auth = AuthService(transport, CookieVault(tmp_path))
|
||||
assert auth.check()['valid'] is False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user