| 1 |
|
| 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"password_file {port}.password\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_password_file.so\n") |
| 17 |
f.write(f"plugin_opt_password_file {port}.password\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("password-change-test") |
| 28 |
connack_packet = mosq_test.gen_connack(rc=0) |
| 29 |
|
| 30 |
with open(f"{port}.password", "wt") as f: |
| 31 |
f.write("test:$7$1000$97ozvObcN5zP4MGzYUw4uRp8+mPQbThrHOX69vdHHNVwV4iZf2K2X23FS7weilZMKeV+9oLHdilybmpXcFApYg==$WlM0jUhsiQNQJe4IDt5K1rmtAdaenWGdntswJmDkp74W9pdrt/+RdIK3YaJ09o3pD1xbtokXq933bQh+CrjA4Q==\n") |
| 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}.password", "wt") as f: |
| 40 |
f.write("test:bad\n") |
| 41 |
|
| 42 |
broker.send_signal(signal.SIGHUP) |
| 43 |
|
| 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}.password") |
| 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) |