feat: extract proxy server from lfs-proxy.py into module

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 17:49:54 +08:00
parent 001ab4e954
commit db4a64319c
2 changed files with 146 additions and 0 deletions

50
tests/test_proxy.py Normal file
View File

@@ -0,0 +1,50 @@
import threading
import http.client
import time
import pytest
from unittest.mock import MagicMock, patch
from jianda_proxy.proxy import create_server
class TestCreateServer:
def test_creates_server_with_config(self):
config = {
"remote_domain": "git.example.com",
"upstream_host": "1.2.3.4",
"upstream_port": "9000",
"listen_host": "127.0.0.1",
"listen_port": "19999",
}
server = create_server(config)
assert server is not None
server.server_close()
def test_binds_to_correct_port(self):
config = {
"remote_domain": "git.example.com",
"upstream_host": "1.2.3.4",
"upstream_port": "9000",
"listen_host": "127.0.0.1",
"listen_port": "19998",
}
server = create_server(config)
assert server.server_address[1] == 19998
server.server_close()
class TestProxyHandler:
def test_forward_proxy_mode(self):
from jianda_proxy.proxy import ProxyHandler
config = {
"remote_domain": "git.example.com",
"upstream_host": "1.2.3.4",
"upstream_port": "9000",
"listen_host": "127.0.0.1",
"listen_port": "19997",
}
server = create_server(config)
# Verify the handler has the correct config set as class attributes
assert hasattr(ProxyHandler, "REMOTE_DOMAIN")
assert ProxyHandler.REMOTE_DOMAIN == "git.example.com"
server.server_close()