Skip to content

Commit

Permalink
Add test for first packet not being CONNECT.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Dec 19, 2018
1 parent dab6452 commit ef724e6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/broker/01-connect-bad-packet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python

# Test whether a first packet of non-CONNECT is rejected.

from mosq_test_helper import *

rc = 1
mid = 2
publish_packet = mosq_test.gen_publish("pub/qos1/test", qos=1, mid=mid, payload="message")
puback_packet = mosq_test.gen_puback(mid)


port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)

try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect(("localhost", port))
sock.send(publish_packet)
data = sock.recv(1)
sock.close()
if len(data) == 0:
rc = 0
except socket.error:
rc = 0
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde)

exit(rc)

1 change: 1 addition & 0 deletions test/broker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ptest : test-compile
test : test-compile 01 02 03 04 05 06 07 08 09 10 11 12

01 :
./01-connect-bad-packet.py
./01-connect-duplicate.py
./01-connect-duplicate-v5.py
./01-connect-success.py
Expand Down
1 change: 1 addition & 0 deletions test/broker/ptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
max_running = 10
tests = [
#(ports required, 'path'),
(1, './01-connect-bad-packet.py'),
(1, './01-connect-duplicate.py'),
(1, './01-connect-duplicate-v5.py'),
(1, './01-connect-success.py'),
Expand Down

0 comments on commit ef724e6

Please sign in to comment.