01-will-unpwd-set.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. # Test whether a client produces a correct connect with a will, username and password.
  3. # The client should connect to port 1888 with keepalive=60, clean session set,
  4. # client id 01-will-unpwd-set , will topic set to "will-topic", will payload
  5. # set to "will message", will qos=2, will retain not set, username set to
  6. # "oibvvwqw" and password set to "#'^2hg9a&nm38*us".
  7. from mosq_test_helper import *
  8. port = mosq_test.get_lib_port()
  9. rc = 1
  10. keepalive = 60
  11. connect_packet = mosq_test.gen_connect("01-will-unpwd-set",
  12. keepalive=keepalive, username="oibvvwqw", password="#'^2hg9a&nm38*us",
  13. will_topic="will-topic", will_qos=2, will_payload=b"will message")
  14. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  15. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  16. sock.settimeout(10)
  17. sock.bind(('', port))
  18. sock.listen(5)
  19. client_args = sys.argv[1:]
  20. env = dict(os.environ)
  21. env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
  22. try:
  23. pp = env['PYTHONPATH']
  24. except KeyError:
  25. pp = ''
  26. env['PYTHONPATH'] = '../../lib/python:'+pp
  27. client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
  28. try:
  29. (conn, address) = sock.accept()
  30. conn.settimeout(10)
  31. mosq_test.expect_packet(conn, "connect", connect_packet)
  32. rc = 0
  33. conn.close()
  34. except mosq_test.TestError:
  35. pass
  36. finally:
  37. client.terminate()
  38. client.wait()
  39. sock.close()
  40. exit(rc)