- Create shared tests/common.rs with TestEnvironment setup - Simplify gemini_test_client.py to single-request client - Refactor config validation tests to use common setup - Add test_valid_config_startup for complete server validation - Fix clippy warning in main.rs - Remove unused code and consolidate test infrastructure
71 lines
No EOL
1.9 KiB
Python
Executable file
71 lines
No EOL
1.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
Simple Gemini Test Client
|
|
|
|
Makes a single Gemini request and prints the status line.
|
|
Used by integration tests for rate limiting validation.
|
|
|
|
Usage: python3 tests/gemini_test_client.py gemini://host:port/path
|
|
"""
|
|
|
|
import sys
|
|
import socket
|
|
import ssl
|
|
|
|
def main():
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python3 gemini_test_client.py <gemini-url>", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
url = sys.argv[1]
|
|
|
|
# Parse URL (basic parsing)
|
|
if not url.startswith('gemini://'):
|
|
print("Error: URL must start with gemini://", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
url_parts = url[9:].split('/', 1) # Remove gemini://
|
|
host_port = url_parts[0]
|
|
path = '/' + url_parts[1] if len(url_parts) > 1 else '/'
|
|
|
|
if ':' in host_port:
|
|
host, port = host_port.rsplit(':', 1)
|
|
port = int(port)
|
|
else:
|
|
host = host_port
|
|
port = 1965
|
|
|
|
try:
|
|
# Create SSL connection
|
|
context = ssl.create_default_context()
|
|
context.check_hostname = False
|
|
context.verify_mode = ssl.CERT_NONE
|
|
|
|
sock = socket.create_connection((host, port), timeout=5.0)
|
|
ssl_sock = context.wrap_socket(sock, server_hostname=host)
|
|
|
|
# Send request
|
|
request = f"{url}\r\n"
|
|
ssl_sock.send(request.encode('utf-8'))
|
|
|
|
# Read response header
|
|
response = b''
|
|
while b'\r\n' not in response and len(response) < 1024:
|
|
data = ssl_sock.recv(1)
|
|
if not data:
|
|
break
|
|
response += data
|
|
|
|
ssl_sock.close()
|
|
|
|
if response:
|
|
status_line = response.decode('utf-8', errors='ignore').split('\r\n')[0]
|
|
print(status_line)
|
|
else:
|
|
print("Error: No response")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
if __name__ == '__main__':
|
|
main() |