55Connects via the ssh_port fixture to the SSH reverse proxy.
66"""
77
8+ import logging
89import uuid
910from pathlib import Path
1011from typing import Optional
1516from helpers .ssh_client import REFSSHClient
1617from helpers .web_client import REFWebClient
1718
19+ # Set up logging for this test module
20+ logger = logging .getLogger (__name__ )
21+ logger .setLevel (logging .DEBUG )
22+ # Ensure logs go to stdout
23+ if not logger .handlers :
24+ handler = logging .StreamHandler ()
25+ handler .setFormatter (logging .Formatter ("[%(name)s] %(message)s" ))
26+ logger .addHandler (handler )
27+
1828
1929class RustProxyTestState :
2030 """Shared state for Rust proxy tests."""
@@ -137,6 +147,7 @@ def test_05_register_student(
137147 web_client .logout ()
138148 mat_num = str (uuid .uuid4 ().int )[:8 ]
139149 rust_proxy_state .mat_num = mat_num
150+ logger .info (f"[TEST] Registering student with mat_num: { mat_num } " )
140151
141152 success , private_key , _ = web_client .register_student (
142153 mat_num = mat_num ,
@@ -149,6 +160,22 @@ def test_05_register_student(
149160 assert private_key is not None
150161 rust_proxy_state .private_key = private_key
151162
163+ # Log private key info
164+ logger .info (f"[TEST] Got private key of length { len (private_key )} " )
165+ logger .info (f"[TEST] Private key first 100 chars: { private_key [:100 ]} ..." )
166+
167+ # Parse the key to get the public key for comparison
168+ import io
169+ import paramiko
170+
171+ try :
172+ key_file = io .StringIO (private_key )
173+ pkey = paramiko .Ed25519Key .from_private_key (key_file )
174+ pub_key_str = f"{ pkey .get_name ()} { pkey .get_base64 ()} "
175+ logger .info (f"[TEST] Derived public key: { pub_key_str } " )
176+ except Exception as e :
177+ logger .error (f"[TEST] Failed to parse private key: { e } " )
178+
152179 # Re-login as admin
153180 web_client .login ("0" , admin_password )
154181
@@ -162,17 +189,65 @@ def test_01_ssh_connect_via_rust_proxy(
162189 ssh_host : str ,
163190 ssh_port : int ,
164191 rust_proxy_state : RustProxyTestState ,
192+ ref_instance ,
165193 ):
166194 """Verify SSH connection works through the Rust SSH proxy."""
167195 assert rust_proxy_state .private_key is not None
168196 assert rust_proxy_state .exercise_name is not None
169197
170- client = create_rust_ssh_client (
171- host = ssh_host ,
172- port = ssh_port ,
173- private_key = rust_proxy_state .private_key ,
174- exercise_name = rust_proxy_state .exercise_name ,
175- )
198+ logger .info (f"[TEST] Connecting to SSH proxy at { ssh_host } :{ ssh_port } " )
199+ logger .info (f"[TEST] Exercise name: { rust_proxy_state .exercise_name } " )
200+ logger .info (f"[TEST] Private key length: { len (rust_proxy_state .private_key )} " )
201+
202+ # Parse the key to log the public key
203+ import io
204+ import paramiko
205+
206+ try :
207+ key_file = io .StringIO (rust_proxy_state .private_key )
208+ pkey = paramiko .Ed25519Key .from_private_key (key_file )
209+ pub_key_str = f"{ pkey .get_name ()} { pkey .get_base64 ()} "
210+ logger .info (f"[TEST] Will authenticate with public key: { pub_key_str } " )
211+ except Exception as e :
212+ logger .error (f"[TEST] Failed to parse private key: { e } " )
213+
214+ # Capture SSH proxy logs before connection attempt
215+ logger .info ("[TEST] === SSH Proxy logs BEFORE connection attempt ===" )
216+ try :
217+ logs = ref_instance .logs (tail = 50 )
218+ for line in logs .split ("\n " ):
219+ if (
220+ "ssh-reverse-proxy" in line .lower ()
221+ or "[AUTH]" in line
222+ or "[API]" in line
223+ ):
224+ logger .info (f"[PROXY LOG] { line } " )
225+ except Exception as e :
226+ logger .error (f"[TEST] Failed to get logs: { e } " )
227+
228+ try :
229+ client = create_rust_ssh_client (
230+ host = ssh_host ,
231+ port = ssh_port ,
232+ private_key = rust_proxy_state .private_key ,
233+ exercise_name = rust_proxy_state .exercise_name ,
234+ )
235+ except Exception as e :
236+ # Capture SSH proxy logs after failed connection
237+ logger .error (f"[TEST] Connection failed: { e } " )
238+ logger .info ("[TEST] === SSH Proxy logs AFTER failed connection ===" )
239+ try :
240+ logs = ref_instance .logs (tail = 100 )
241+ for line in logs .split ("\n " ):
242+ if (
243+ "ssh-reverse-proxy" in line .lower ()
244+ or "[AUTH]" in line
245+ or "[API]" in line
246+ ):
247+ logger .info (f"[PROXY LOG] { line } " )
248+ except Exception as log_e :
249+ logger .error (f"[TEST] Failed to get logs: { log_e } " )
250+ raise
176251
177252 assert client .is_connected (), "Rust SSH proxy connection failed"
178253
0 commit comments