14-dynsec-client-invalid.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. #!/usr/bin/env python3
  2. # Check invalid inputs for client commands
  3. from mosq_test_helper import *
  4. import json
  5. import shutil
  6. def write_config(filename, port):
  7. with open(filename, 'w') as f:
  8. f.write("listener %d\n" % (port))
  9. f.write("allow_anonymous true\n")
  10. f.write("plugin ../../plugins/dynamic-security/mosquitto_dynamic_security.so\n")
  11. f.write("plugin_opt_config_file %d/dynamic-security.json\n" % (port))
  12. def command_check(sock, command_payload, expected_response, msg=""):
  13. command_packet = mosq_test.gen_publish(topic="$CONTROL/dynamic-security/v1", qos=0, payload=json.dumps(command_payload))
  14. sock.send(command_packet)
  15. response = json.loads(mosq_test.read_publish(sock))
  16. if response != expected_response:
  17. print(expected_response)
  18. print(response)
  19. if msg != "":
  20. print(msg)
  21. raise ValueError(response)
  22. port = mosq_test.get_port()
  23. conf_file = os.path.basename(__file__).replace('.py', '.conf')
  24. write_config(conf_file, port)
  25. # ==========================================================================
  26. # Create client
  27. # ==========================================================================
  28. # No username
  29. create_client1_command = { 'commands': [{'command': 'createClient' }] }
  30. create_client1_response = {'responses': [{'command': 'createClient', 'error': 'Invalid/missing username'}]}
  31. # Username not a string
  32. create_client2_command = { 'commands': [{'command': 'createClient', 'username': 5 }] }
  33. create_client2_response = {'responses': [{'command': 'createClient', 'error': 'Invalid/missing username'}]}
  34. # Username not UTF-8
  35. create_client3_command = { 'commands': [{'command': 'createClient', 'username': '￿LO' }] }
  36. create_client3_response = {'responses': [{'command': 'createClient', 'error': 'Username not valid UTF-8'}]}
  37. # Password not a string
  38. create_client4_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':5 }] }
  39. create_client4_response = {'responses': [{'command': 'createClient', 'error': 'Invalid/missing password'}]}
  40. # Client id not a string
  41. create_client5_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':'5', 'clientid':5}] }
  42. create_client5_response = {'responses': [{'command': 'createClient', 'error': 'Invalid/missing client id'}]}
  43. # Client id not UTF-8
  44. create_client6_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'clientid':'￿LO' }] }
  45. create_client6_response = {'responses': [{'command': 'createClient', 'error': 'Client ID not valid UTF-8'}]}
  46. # Text name not a string
  47. create_client7_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':'5', 'textname':5}] }
  48. create_client7_response = {'responses': [{'command': 'createClient', 'error': 'Invalid/missing textname'}]}
  49. # Text description not a string
  50. create_client8_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':'5', 'textdescription':5}] }
  51. create_client8_response = {'responses': [{'command': 'createClient', 'error': 'Invalid/missing textdescription'}]}
  52. # Client already exists
  53. create_client9_command = { 'commands': [{'command': 'createClient', 'username': 'admin', 'password':'5'}]}
  54. create_client9_response = {'responses': [{'command': 'createClient', 'error': 'Client already exists'}]}
  55. # Roles not an array
  56. create_client10_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':'5', 'roles':'bad'}] }
  57. create_client10_response = {'responses': [{'command': 'createClient', 'error': "'roles' not an array or missing/invalid rolename"}]}
  58. # Role not found
  59. create_client11_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':'5', 'roles':[{'rolename':'notfound'}]}] }
  60. create_client11_response = {'responses': [{'command': 'createClient', 'error': 'Role not found'}]}
  61. # Group not found
  62. create_client12_command = { 'commands': [{'command': 'createClient', 'username': 'user', 'password':'5', 'groups':[{'groupname':'notfound'}]}] }
  63. create_client12_response = {'responses': [{'command': 'createClient', 'error': 'Group not found'}]}
  64. # ==========================================================================
  65. # Delete client
  66. # ==========================================================================
  67. # No username
  68. delete_client1_command = { 'commands': [{'command': 'deleteClient'}]}
  69. delete_client1_response = {'responses': [{'command': 'deleteClient', 'error': 'Invalid/missing username'}]}
  70. # Username not a string
  71. delete_client2_command = { 'commands': [{'command': 'deleteClient', 'username':5}]}
  72. delete_client2_response = {'responses': [{'command': 'deleteClient', 'error': 'Invalid/missing username'}]}
  73. # Username not UTF-8
  74. delete_client3_command = { 'commands': [{'command': 'deleteClient', 'username': '￿LO' }] }
  75. delete_client3_response = {'responses': [{'command': 'deleteClient', 'error': 'Username not valid UTF-8'}]}
  76. # Client not found
  77. delete_client4_command = { 'commands': [{'command': 'deleteClient', 'username':'notfound'}]}
  78. delete_client4_response = {'responses': [{'command': 'deleteClient', 'error': 'Client not found'}]}
  79. # ==========================================================================
  80. # Disable client
  81. # ==========================================================================
  82. # No username
  83. disable_client1_command = { 'commands': [{'command': 'disableClient'}]}
  84. disable_client1_response = {'responses': [{'command': 'disableClient', 'error': 'Invalid/missing username'}]}
  85. # Username not a string
  86. disable_client2_command = { 'commands': [{'command': 'disableClient', 'username':5}]}
  87. disable_client2_response = {'responses': [{'command': 'disableClient', 'error': 'Invalid/missing username'}]}
  88. # Username not UTF-8
  89. disable_client3_command = { 'commands': [{'command': 'disableClient', 'username': '￿LO' }] }
  90. disable_client3_response = {'responses': [{'command': 'disableClient', 'error': 'Username not valid UTF-8'}]}
  91. # Client not found
  92. disable_client4_command = { 'commands': [{'command': 'disableClient', 'username':'notfound'}]}
  93. disable_client4_response = {'responses': [{'command': 'disableClient', 'error': 'Client not found'}]}
  94. # ==========================================================================
  95. # Enable client
  96. # ==========================================================================
  97. # No username
  98. enable_client1_command = { 'commands': [{'command': 'enableClient'}]}
  99. enable_client1_response = {'responses': [{'command': 'enableClient', 'error': 'Invalid/missing username'}]}
  100. # Username not a string
  101. enable_client2_command = { 'commands': [{'command': 'enableClient', 'username':5}]}
  102. enable_client2_response = {'responses': [{'command': 'enableClient', 'error': 'Invalid/missing username'}]}
  103. # Username not UTF-8
  104. enable_client3_command = { 'commands': [{'command': 'enableClient', 'username': '￿LO' }] }
  105. enable_client3_response = {'responses': [{'command': 'enableClient', 'error': 'Username not valid UTF-8'}]}
  106. # Client not found
  107. enable_client4_command = { 'commands': [{'command': 'enableClient', 'username':'notfound'}]}
  108. enable_client4_response = {'responses': [{'command': 'enableClient', 'error': 'Client not found'}]}
  109. # ==========================================================================
  110. # Set client id
  111. # ==========================================================================
  112. # No username
  113. set_client_id1_command = { 'commands': [{'command': 'setClientId'}]}
  114. set_client_id1_response = {'responses': [{'command': 'setClientId', 'error': 'Invalid/missing username'}]}
  115. # Username not a string
  116. set_client_id2_command = { 'commands': [{'command': 'setClientId', 'username':5}]}
  117. set_client_id2_response = {'responses': [{'command': 'setClientId', 'error': 'Invalid/missing username'}]}
  118. # Username not UTF-8
  119. set_client_id3_command = { 'commands': [{'command': 'setClientId', 'username': '￿LO' }] }
  120. set_client_id3_response = {'responses': [{'command': 'setClientId', 'error': 'Username not valid UTF-8'}]}
  121. # No client id
  122. set_client_id4_command = { 'commands': [{'command': 'setClientId', 'username':'user'}]}
  123. set_client_id4_response = {'responses': [{'command': 'setClientId', 'error': 'Client not found'}]}
  124. # Client id not a string
  125. set_client_id5_command = { 'commands': [{'command': 'setClientId', 'username':'user', 'clientid':5}]}
  126. set_client_id5_response = {'responses': [{'command': 'setClientId', 'error': 'Invalid/missing client ID'}]}
  127. # Client id not UTF-8
  128. set_client_id6_command = { 'commands': [{'command': 'setClientId', 'username':'user', 'clientid': '￿LO' }] }
  129. set_client_id6_response = {'responses': [{'command': 'setClientId', 'error': 'Client ID not valid UTF-8'}]}
  130. # Client not found
  131. set_client_id7_command = { 'commands': [{'command': 'setClientId', 'username':'notfound', 'clientid':'newid'}]}
  132. set_client_id7_response = {'responses': [{'command': 'setClientId', 'error': 'Client not found'}]}
  133. # ==========================================================================
  134. # Set password
  135. # ==========================================================================
  136. # No username
  137. set_password1_command = { 'commands': [{'command': 'setClientPassword'}]}
  138. set_password1_response = {'responses': [{'command': 'setClientPassword', 'error': 'Invalid/missing username'}]}
  139. # Username not a string
  140. set_password2_command = { 'commands': [{'command': 'setClientPassword', 'username':5}]}
  141. set_password2_response = {'responses': [{'command': 'setClientPassword', 'error': 'Invalid/missing username'}]}
  142. # Username not UTF-8
  143. set_password3_command = { 'commands': [{'command': 'setClientPassword', 'username':'￿LO' }] }
  144. set_password3_response = {'responses': [{'command': 'setClientPassword', 'error': 'Username not valid UTF-8'}]}
  145. # No password
  146. set_password4_command = { 'commands': [{'command': 'setClientPassword', 'username':'user'}]}
  147. set_password4_response = {'responses': [{'command': 'setClientPassword', 'error': 'Invalid/missing password'}]}
  148. # password not a string
  149. set_password5_command = { 'commands': [{'command': 'setClientPassword', 'username':'user', 'password':5}]}
  150. set_password5_response = {'responses': [{'command': 'setClientPassword', 'error': 'Invalid/missing password'}]}
  151. # password is empty
  152. set_password6_command = { 'commands': [{'command': 'setClientPassword', 'username':'user', 'password':''}]}
  153. set_password6_response = {'responses': [{'command': 'setClientPassword', 'error': 'Empty password is not allowed'}]}
  154. # Client not found
  155. set_password7_command = { 'commands': [{'command': 'setClientPassword', 'username':'notfound', 'password':'newpw'}]}
  156. set_password7_response = {'responses': [{'command': 'setClientPassword', 'error': 'Client not found'}]}
  157. # ==========================================================================
  158. # Get client
  159. # ==========================================================================
  160. # No username
  161. get_client1_command = { 'commands': [{'command': 'getClient'}]}
  162. get_client1_response = {'responses': [{'command': 'getClient', 'error': 'Invalid/missing username'}]}
  163. # Username not a string
  164. get_client2_command = { 'commands': [{'command': 'getClient', 'username':5}]}
  165. get_client2_response = {'responses': [{'command': 'getClient', 'error': 'Invalid/missing username'}]}
  166. # Username not UTF-8
  167. get_client3_command = { 'commands': [{'command': 'getClient', 'username':'￿LO' }] }
  168. get_client3_response = {'responses': [{'command': 'getClient', 'error': 'Username not valid UTF-8'}]}
  169. # Client not found
  170. get_client4_command = { 'commands': [{'command': 'getClient', 'username':'notfound'}]}
  171. get_client4_response = {'responses': [{'command': 'getClient', 'error': 'Client not found'}]}
  172. # ==========================================================================
  173. # Add role
  174. # ==========================================================================
  175. # No username
  176. add_role1_command = { 'commands': [{'command': 'addClientRole'}]}
  177. add_role1_response = {'responses': [{'command': 'addClientRole', 'error': 'Invalid/missing username'}]}
  178. # Username not a string
  179. add_role2_command = { 'commands': [{'command': 'addClientRole', 'username':5}]}
  180. add_role2_response = {'responses': [{'command': 'addClientRole', 'error': 'Invalid/missing username'}]}
  181. # Username not UTF-8
  182. add_role3_command = { 'commands': [{'command': 'addClientRole', 'username':'￿LO' }] }
  183. add_role3_response = {'responses': [{'command': 'addClientRole', 'error': 'Username not valid UTF-8'}]}
  184. # No rolename
  185. add_role4_command = { 'commands': [{'command': 'addClientRole', 'username':'user'}]}
  186. add_role4_response = {'responses': [{'command': 'addClientRole', 'error': 'Invalid/missing rolename'}]}
  187. # rolename not a string
  188. add_role5_command = { 'commands': [{'command': 'addClientRole', 'username':'user', 'rolename':5}]}
  189. add_role5_response = {'responses': [{'command': 'addClientRole', 'error': 'Invalid/missing rolename'}]}
  190. # rolename not UTF-8
  191. add_role6_command = { 'commands': [{'command': 'addClientRole', 'username':'user', 'rolename':'￿LO' }] }
  192. add_role6_response = {'responses': [{'command': 'addClientRole', 'error': 'Role name not valid UTF-8'}]}
  193. # Client not found
  194. add_role7_command = { 'commands': [{'command': 'addClientRole', 'username':'notfound', 'rolename':'notfound'}]}
  195. add_role7_response = {'responses': [{'command': 'addClientRole', 'error': 'Client not found'}]}
  196. # Role not found
  197. add_role8_command = { 'commands': [{'command': 'addClientRole', 'username':'admin', 'rolename':'notfound'}]}
  198. add_role8_response = {'responses': [{'command': 'addClientRole', 'error': 'Role not found'}]}
  199. # ==========================================================================
  200. # Remove role
  201. # ==========================================================================
  202. # No username
  203. remove_role1_command = { 'commands': [{'command': 'removeClientRole'}]}
  204. remove_role1_response = {'responses': [{'command': 'removeClientRole', 'error': 'Invalid/missing username'}]}
  205. # Username not a string
  206. remove_role2_command = { 'commands': [{'command': 'removeClientRole', 'username':5}]}
  207. remove_role2_response = {'responses': [{'command': 'removeClientRole', 'error': 'Invalid/missing username'}]}
  208. # Username not UTF-8
  209. remove_role3_command = { 'commands': [{'command': 'removeClientRole', 'username':'￿LO' }] }
  210. remove_role3_response = {'responses': [{'command': 'removeClientRole', 'error': 'Username not valid UTF-8'}]}
  211. # No rolename
  212. remove_role4_command = { 'commands': [{'command': 'removeClientRole', 'username':'user'}]}
  213. remove_role4_response = {'responses': [{'command': 'removeClientRole', 'error': 'Invalid/missing rolename'}]}
  214. # rolename not a string
  215. remove_role5_command = { 'commands': [{'command': 'removeClientRole', 'username':'user', 'rolename':5}]}
  216. remove_role5_response = {'responses': [{'command': 'removeClientRole', 'error': 'Invalid/missing rolename'}]}
  217. # rolename not UTF-8
  218. remove_role6_command = { 'commands': [{'command': 'removeClientRole', 'username':'user', 'rolename':'￿LO' }] }
  219. remove_role6_response = {'responses': [{'command': 'removeClientRole', 'error': 'Role name not valid UTF-8'}]}
  220. # Client not found
  221. remove_role7_command = { 'commands': [{'command': 'removeClientRole', 'username':'notfound', 'rolename':'notfound'}]}
  222. remove_role7_response = {'responses': [{'command': 'removeClientRole', 'error': 'Client not found'}]}
  223. # Role not found
  224. remove_role8_command = { 'commands': [{'command': 'removeClientRole', 'username':'admin', 'rolename':'notfound'}]}
  225. remove_role8_response = {'responses': [{'command': 'removeClientRole', 'error': 'Role not found'}]}
  226. # ==========================================================================
  227. # Modify client
  228. # ==========================================================================
  229. # Create a client to modify
  230. modify_client0_command = { 'commands': [{'command': 'createClient', 'username':'user'}]}
  231. modify_client0_response = {'responses': [{'command': 'createClient'}]}
  232. # No username
  233. modify_client1_command = { 'commands': [{'command': 'modifyClient'}]}
  234. modify_client1_response = {'responses': [{'command': 'modifyClient', 'error': 'Invalid/missing username'}]}
  235. # Username not a string
  236. modify_client2_command = { 'commands': [{'command': 'modifyClient', 'username':5}]}
  237. modify_client2_response = {'responses': [{'command': 'modifyClient', 'error': 'Invalid/missing username'}]}
  238. # Username not UTF-8
  239. modify_client3_command = { 'commands': [{'command': 'modifyClient', 'username':'￿LO' }] }
  240. modify_client3_response = {'responses': [{'command': 'modifyClient', 'error': 'Username not valid UTF-8'}]}
  241. # roles not a list
  242. modify_client4_command = { 'commands': [{'command': 'modifyClient', 'username':'user', 'password':'test', 'roles':'string'}]}
  243. modify_client4_response = {'responses': [{'command': 'modifyClient', 'error': "'roles' not an array or missing/invalid rolename"}]}
  244. # No rolename
  245. modify_client5_command = { 'commands': [{'command': 'modifyClient', 'username':'user', 'roles':[{'rolename':5}]}]}
  246. modify_client5_response = {'responses': [{'command': 'modifyClient', 'error': "'roles' not an array or missing/invalid rolename"}]}
  247. # rolename not UTF-8
  248. #modify_client6_command = { 'commands': [{'command': 'modifyClient', 'username':'user', 'rolename':'￿LO' }] }
  249. #modify_client6_response = {'responses': [{'command': 'modifyClient', 'error': 'Username not valid UTF-8'}]}
  250. # Client not found
  251. modify_client7_command = { 'commands': [{'command': 'modifyClient', 'username':'notfound', 'rolename':'notfound'}]}
  252. modify_client7_response = {'responses': [{'command': 'modifyClient', 'error': 'Client not found'}]}
  253. # Role not found
  254. modify_client8_command = { 'commands': [{'command': 'modifyClient', 'username':'user', 'roles':[{'rolename':'notfound'}]}]}
  255. modify_client8_response = {'responses': [{'command': 'modifyClient', 'error': 'Role not found'}]}
  256. rc = 1
  257. keepalive = 10
  258. connect_packet = mosq_test.gen_connect("ctrl-test", keepalive=keepalive, username="admin", password="admin")
  259. connack_packet = mosq_test.gen_connack(rc=0)
  260. mid = 2
  261. subscribe_packet = mosq_test.gen_subscribe(mid, "$CONTROL/dynamic-security/#", 1)
  262. suback_packet = mosq_test.gen_suback(mid, 1)
  263. try:
  264. os.mkdir(str(port))
  265. shutil.copyfile("dynamic-security-init.json", "%d/dynamic-security.json" % (port))
  266. except FileExistsError:
  267. pass
  268. broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
  269. try:
  270. sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port)
  271. mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
  272. command_check(sock, create_client1_command, create_client1_response, "1")
  273. command_check(sock, create_client2_command, create_client2_response, "2")
  274. command_check(sock, create_client3_command, create_client3_response, "3")
  275. command_check(sock, create_client4_command, create_client4_response, "4")
  276. command_check(sock, create_client5_command, create_client5_response, "5")
  277. command_check(sock, create_client6_command, create_client6_response, "6")
  278. command_check(sock, create_client7_command, create_client7_response, "7")
  279. command_check(sock, create_client8_command, create_client8_response, "8")
  280. command_check(sock, create_client9_command, create_client9_response, "9")
  281. command_check(sock, create_client10_command, create_client10_response, "10")
  282. command_check(sock, create_client11_command, create_client11_response, "11")
  283. command_check(sock, create_client12_command, create_client12_response, "12")
  284. command_check(sock, delete_client1_command, delete_client1_response, "1")
  285. command_check(sock, delete_client2_command, delete_client2_response, "2")
  286. #command_check(sock, delete_client3_command, delete_client3_response, "3")
  287. command_check(sock, delete_client4_command, delete_client4_response, "4")
  288. command_check(sock, disable_client1_command, disable_client1_response, "1")
  289. command_check(sock, disable_client2_command, disable_client2_response, "2")
  290. command_check(sock, disable_client3_command, disable_client3_response, "3")
  291. command_check(sock, disable_client4_command, disable_client4_response, "4")
  292. command_check(sock, enable_client1_command, enable_client1_response, "1")
  293. command_check(sock, enable_client2_command, enable_client2_response, "2")
  294. command_check(sock, enable_client3_command, enable_client3_response, "3")
  295. command_check(sock, enable_client4_command, enable_client4_response, "4")
  296. command_check(sock, set_client_id1_command, set_client_id1_response, "1")
  297. command_check(sock, set_client_id2_command, set_client_id2_response, "2")
  298. command_check(sock, set_client_id3_command, set_client_id3_response, "3")
  299. command_check(sock, set_client_id4_command, set_client_id4_response, "4")
  300. command_check(sock, set_client_id5_command, set_client_id5_response, "5")
  301. command_check(sock, set_client_id6_command, set_client_id6_response, "6")
  302. command_check(sock, set_client_id7_command, set_client_id7_response, "7")
  303. command_check(sock, set_password1_command, set_password1_response, "1")
  304. command_check(sock, set_password2_command, set_password2_response, "2")
  305. command_check(sock, set_password3_command, set_password3_response, "3")
  306. command_check(sock, set_password4_command, set_password4_response, "4")
  307. command_check(sock, set_password5_command, set_password5_response, "5")
  308. command_check(sock, set_password6_command, set_password6_response, "6")
  309. command_check(sock, set_password7_command, set_password7_response, "7")
  310. command_check(sock, get_client1_command, get_client1_response, "1")
  311. command_check(sock, get_client2_command, get_client2_response, "2")
  312. command_check(sock, get_client3_command, get_client3_response, "3")
  313. command_check(sock, get_client4_command, get_client4_response, "4")
  314. command_check(sock, add_role1_command, add_role1_response, "1")
  315. command_check(sock, add_role2_command, add_role2_response, "2")
  316. command_check(sock, add_role3_command, add_role3_response, "3")
  317. command_check(sock, add_role4_command, add_role4_response, "4")
  318. command_check(sock, add_role5_command, add_role5_response, "5")
  319. command_check(sock, add_role6_command, add_role6_response, "6")
  320. command_check(sock, add_role7_command, add_role7_response, "7")
  321. command_check(sock, add_role8_command, add_role8_response, "8")
  322. command_check(sock, remove_role1_command, remove_role1_response, "1")
  323. command_check(sock, remove_role2_command, remove_role2_response, "2")
  324. command_check(sock, remove_role3_command, remove_role3_response, "3")
  325. command_check(sock, remove_role4_command, remove_role4_response, "4")
  326. command_check(sock, remove_role5_command, remove_role5_response, "5")
  327. command_check(sock, remove_role6_command, remove_role6_response, "6")
  328. command_check(sock, remove_role7_command, remove_role7_response, "7")
  329. command_check(sock, remove_role8_command, remove_role8_response, "8")
  330. command_check(sock, modify_client0_command, modify_client0_response, "1")
  331. command_check(sock, modify_client1_command, modify_client1_response, "1")
  332. command_check(sock, modify_client2_command, modify_client2_response, "2")
  333. command_check(sock, modify_client3_command, modify_client3_response, "3")
  334. command_check(sock, modify_client4_command, modify_client4_response, "4")
  335. command_check(sock, modify_client5_command, modify_client5_response, "5")
  336. #command_check(sock, modify_client6_command, modify_client6_response, "6")
  337. command_check(sock, modify_client7_command, modify_client7_response, "7")
  338. command_check(sock, modify_client8_command, modify_client8_response, "8")
  339. rc = 0
  340. sock.close()
  341. except mosq_test.TestError:
  342. pass
  343. finally:
  344. os.remove(conf_file)
  345. try:
  346. os.remove(f"{port}/dynamic-security.json")
  347. except FileNotFoundError:
  348. pass
  349. os.rmdir(f"{port}")
  350. broker.terminate()
  351. broker.wait()
  352. (stdo, stde) = broker.communicate()
  353. if rc:
  354. print(stde.decode('utf-8'))
  355. exit(rc)