1
1
from __future__ import annotations
2
2
3
- from telnetlib import Telnet
4
-
5
3
import pytest
4
+ from socket import socket
6
5
7
6
from honeypots import QTelnetServer
8
7
from .utils import (
13
12
PASSWORD ,
14
13
USERNAME ,
15
14
wait_for_server ,
15
+ connect_to
16
16
)
17
17
18
18
PORT = "50023"
23
23
[{"server" : QTelnetServer , "port" : PORT }],
24
24
indirect = True ,
25
25
)
26
+
26
27
def test_telnet_server (server_logs ):
27
- with wait_for_server (PORT ):
28
- telnet_client = Telnet (IP , int (PORT ))
29
- telnet_client .read_until (b"login: " )
30
- telnet_client .write (USERNAME .encode () + b"\n " )
31
- telnet_client .read_until (b"Password: " )
32
- telnet_client .write (PASSWORD .encode () + b"\n " )
28
+ with wait_for_server (PORT ), connect_to (IP , PORT ) as connection :
29
+ data , _ = connection .recvfrom (10000 )
30
+ connection .send (USERNAME .encode () + b"\n " )
31
+ data , _ = connection .recvfrom (10000 )
32
+ connection .send (PASSWORD .encode () + b"\n " )
33
33
34
34
logs = load_logs_from_file (server_logs )
35
35
36
36
assert len (logs ) == 2
37
- connect , login = logs
38
- assert_connect_is_logged (connect , PORT )
39
- assert_login_is_logged (login )
37
+ connect_ , login = logs
38
+ assert_connect_is_logged (connect_ , PORT )
39
+ assert_login_is_logged (login )
0 commit comments