51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
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()
|