Debian Codegraph @

test/broker/23-security-acl-file-reload.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #!/usr/bin/env python3
2
3 from mosq_test_helper import *
4 import signal
5
6 def write_config_default(filename, port):
7 with open(filename, 'w') as f:
8 f.write("listener %d\n" % (port))
9 f.write(f"acl_file {port}.acl\n")
10 f.write("allow_anonymous true\n")
11
12
13 def write_config_plugin(filename, port):
14 with open(filename, 'w') as f:
15 f.write("listener %d\n" % (port))
•16 f.write(f"plugin {mosq_test.get_plugin_path()}/mosquitto_acl_file.so\n")
17 f.write(f"plugin_opt_acl_file {port}.acl\n")
18 f.write("allow_anonymous true\n")
19
20
21 def do_test(write_config_func):
22 port = mosq_test.get_port()
23 conf_file = os.path.basename(__file__).replace('.py', '.conf')
24 write_config_func(conf_file, port)
25
26 rc = 1
27 connect_packet = mosq_test.gen_connect("acl-change-test")
28 connack_packet = mosq_test.gen_connack(rc=0)
29
30 with open(f"{port}.acl", "wt") as f:
31 f.write("topic readwrite a/#")
32
33 broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
34
35 try:
36 sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
37 sock.close()
38
39 with open(f"{port}.acl", "wt") as f:
40 f.write("topic readwrite a#")
41
42 broker.send_signal(signal.SIGHUP)
43 # Broker should terminate
44 if mosq_test.wait_for_subprocess(broker) == 0 and broker.returncode == 3:
45 rc = 0
46 except mosq_test.TestError:
47 pass
48 except Exception as err:
49 print(err)
50 finally:
51 os.remove(conf_file)
52 os.remove(f"{port}.acl")
53 broker.terminate()
54 (stdo, stde) = broker.communicate()
55 if rc:
56 print(stde.decode('utf-8'))
57 exit(rc)
58
59 do_test(write_config_default)
60 do_test(write_config_plugin)