01-unpwd-set.py 788 字节
Newer Older
1
#!/usr/bin/env python3
R
Roger Light 已提交
2 3 4 5 6 7

# Test whether a client produces a correct connect with a username and password.

# The client should connect to port 1888 with keepalive=60, clean session set,
# client id 01-unpwd-set, username set to uname and password set to ;'[08gn=#

8
import context
R
Roger Light 已提交
9
import paho_test
R
Roger Light 已提交
10 11 12

rc = 1
keepalive = 60
13 14
username = "uname"
password = ";'[08gn=#"
15 16
connect_packet = paho_test.gen_connect(
    "01-unpwd-set", keepalive=keepalive, username=username, password=password)
R
Roger Light 已提交
17

18
sock = paho_test.create_server_socket()
R
Roger Light 已提交
19

20
client = context.start_client()
R
Roger Light 已提交
21 22 23 24 25

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)

R
Roger A. Light 已提交
26
    paho_test.expect_packet(conn, "connect", connect_packet)
R
Roger A. Light 已提交
27
    rc = 0
R
Roger Light 已提交
28 29 30 31 32 33 34 35

    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()

exit(rc)