Tests: Fix client/app output comparisons

This commit is contained in:
Roger Light
2026-05-03 01:17:26 +01:00
parent 159b646b3b
commit 50a1083b60
16 changed files with 389 additions and 406 deletions
+66 -66
View File
@@ -12,77 +12,77 @@ def do_test(args, rc_expected, response=None):
env=env, capture_output=True, encoding='utf-8', timeout=2)
if response is not None:
if proc.stderr != response:
if response not in proc.stderr:
print(len(proc.stderr))
print(len(response))
raise ValueError(proc.stderr)
raise ValueError(f"'{response}' not in '{proc.stderr}'")
if proc.returncode != rc_expected:
raise ValueError(f"return code {proc.returncode} != expected {rc_expected} while testing args: {args}")
env = mosq_test.env_add_ld_library_path()
do_test(["-A"], 1, response="Error: -A argument given but no address specified.\n\n")
do_test(["--cafile"], 1, response="Error: --cafile argument given but no file specified.\n\n")
do_test(["--cafile", "missing", "broker", "listListeners"], 1, "Error: Problem setting TLS options: File not found.\n")
do_test(["--capath"], 1, response="Error: --capath argument given but no directory specified.\n\n")
do_test(["--cert"], 1, response="Error: --cert argument given but no file specified.\n\n")
do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n")
do_test(["-A"], 1, response="Error: -A argument given but no address specified.")
do_test(["--cafile"], 1, response="Error: --cafile argument given but no file specified.")
do_test(["--cafile", "missing", "broker", "listListeners"], 1, "Error: Problem setting TLS options: File not found.")
do_test(["--capath"], 1, response="Error: --capath argument given but no directory specified.")
do_test(["--cert"], 1, response="Error: --cert argument given but no file specified.")
do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.")
do_test(["--help"], 1) # Gives generic help
do_test(["--key"], 1, response="Error: --key argument given but no file specified.\n\n")
do_test(["--key", ssl_dir / "client.key"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n")
do_test(["--ciphers"], 1, response="Error: --ciphers argument given but no ciphers specified.\n\n")
do_test(["-f"], 1, response="Error: -f argument given but no data file specified.\n\n")
do_test(["--host"], 1, response="Error: -h argument given but no host specified.\n\n")
do_test(["-i"], 1, response="Error: -i argument given but no id specified.\n\n")
do_test(["--keyform"], 1, response="Error: --keyform argument given but no keyform specified.\n\n")
do_test(["--keyform", "key"], 1, response="Error: If keyform is set, keyfile must be also specified.\n")
do_test(["--key"], 1, response="Error: --key argument given but no file specified.")
do_test(["--key", ssl_dir / "client.key"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.")
do_test(["--ciphers"], 1, response="Error: --ciphers argument given but no ciphers specified.")
do_test(["-f"], 1, response="Error: -f argument given but no data file specified.")
do_test(["--host"], 1, response="Error: -h argument given but no host specified.")
do_test(["-i"], 1, response="Error: -i argument given but no id specified.")
do_test(["--keyform"], 1, response="Error: --keyform argument given but no keyform specified.")
do_test(["--keyform", "key"], 1, response="Error: If keyform is set, keyfile must be also specified.")
do_test(["--keyform", "key", "--cafile", "file", "--cert", "file", "--key", "file", "broker", "listListeners"], 1,
response="Error: Problem setting key form, it must be one of 'pem' or 'engine'.\n")
do_test(['-L'], 1, response="Error: -L argument given but no URL specified.\n\n")
do_test(['-L', 'invalid://'], 1, response="Error: Unsupported URL scheme.\n\n")
do_test(['-L', 'mqtt://localhost'], 1, response="Error: Invalid URL for -L argument specified - topic missing.\n")
do_test(['-L', 'mqtts://localhost'], 1, response="Error: Invalid URL for -L argument specified - topic missing.\n")
do_test(['-L', 'mqtts://:@localhost/topic'], 1, response="Error: Empty username in URL.\n")
do_test(['-L', 'mqtts://localhost:/topic'], 1, response="Error: Empty port in URL.\n")
do_test(["-o"], 1, response="Error: -o argument given but no options file specified.\n\n")
do_test(["-p"], 1, response="Error: -p argument given but no port specified.\n\n")
do_test(["-p", "-1"], 1, response="Error: Invalid port given: -1\n")
do_test(["-p", "65536"], 1, response="Error: Invalid port given: 65536\n")
do_test(["-P"], 1, response="Error: -P argument given but no password specified.\n\n")
response="Error: Problem setting key form, it must be one of 'pem' or 'engine'.")
do_test(['-L'], 1, response="Error: -L argument given but no URL specified.")
do_test(['-L', 'invalid://'], 1, response="Error: Unsupported URL scheme.")
do_test(['-L', 'mqtt://localhost'], 1, response="Error: Invalid URL for -L argument specified - topic missing.")
do_test(['-L', 'mqtts://localhost'], 1, response="Error: Invalid URL for -L argument specified - topic missing.")
do_test(['-L', 'mqtts://:@localhost/topic'], 1, response="Error: Empty username in URL.")
do_test(['-L', 'mqtts://localhost:/topic'], 1, response="Error: Empty port in URL.")
do_test(["-o"], 1, response="Error: -o argument given but no options file specified.")
do_test(["-p"], 1, response="Error: -p argument given but no port specified.")
do_test(["-p", "-1"], 1, response="Error: Invalid port given: -1")
do_test(["-p", "65536"], 1, response="Error: Invalid port given: 65536")
do_test(["-P"], 1, response="Error: -P argument given but no password specified.")
if mosq_test.check_features(["WITH_SOCKS"]):
do_test(["--proxy"], 1, response="Error: --proxy argument given but no proxy url specified.\n\n")
do_test(["--proxy", "mqtt://localhost"], 1, response="Error: Unsupported proxy protocol: mqtt://localhost\n")
do_test(["--proxy", "socks5h://"], 1, response="Error: Invalid proxy.\n")
do_test(["--proxy", "socks5h://localhost:0"], 1, response="Error: Invalid proxy port 0\n")
do_test(["--proxy", "socks5h://localhost:65536"], 1, response="Error: Invalid proxy port 65536\n")
do_test(["--proxy", "socks5h://username%@localhost"], 1, response="Error: Invalid URL encoding in username.\n")
do_test(["--proxy", "socks5h://username%41@localhost"], 1, response="Error: Invalid URL encoding in username.\n")
do_test(["--proxy", "socks5h://username:password%@localhost"], 1, response="Error: Invalid URL encoding in password.\n")
do_test(["--proxy", "socks5h://username:password%41@localhost"], 1, response="Error: Invalid URL encoding in password.\n")
do_test(["--proxy"], 1, response="Error: --proxy argument given but no proxy url specified.")
do_test(["--proxy", "mqtt://localhost"], 1, response="Error: Unsupported proxy protocol: mqtt://localhost")
do_test(["--proxy", "socks5h://"], 1, response="Error: Invalid proxy.")
do_test(["--proxy", "socks5h://localhost:0"], 1, response="Error: Invalid proxy port 0")
do_test(["--proxy", "socks5h://localhost:65536"], 1, response="Error: Invalid proxy port 65536")
do_test(["--proxy", "socks5h://username%@localhost"], 1, response="Error: Invalid URL encoding in username.")
do_test(["--proxy", "socks5h://username%41@localhost"], 1, response="Error: Invalid URL encoding in username.")
do_test(["--proxy", "socks5h://username:password%@localhost"], 1, response="Error: Invalid URL encoding in password.")
do_test(["--proxy", "socks5h://username:password%41@localhost"], 1, response="Error: Invalid URL encoding in password.")
else:
do_test(["--proxy", "socks5h://username:password%41@localhost"], 1, response="Error: Unknown option '--proxy'.\n")
do_test(["--proxy", "socks5h://username:password%41@localhost"], 1, response="Error: Unknown option '--proxy'.")
if mosq_test.check_features(["WITH_TLS_PSK"]):
do_test(["--psk"], 1, response="Error: --psk argument given but no key specified.\n\n")
do_test(["--psk", "missing.psk"], 1, response="Error: --psk-identity required if --psk used.\n")
do_test(["--psk-identity"], 1, response="Error: --psk-identity argument given but no identity specified.\n\n")
do_test(["--cafile", ssl_dir / "all-ca.crt", "--psk", "missing.psk", "--psk-identity", "identity"], 1, response="Error: Only one of --psk or --cafile/--capath may be used at once.\n")
do_test(["--psk"], 1, response="Error: --psk argument given but no key specified.")
do_test(["--psk", "missing.psk"], 1, response="Error: --psk-identity required if --psk used.")
do_test(["--psk-identity"], 1, response="Error: --psk-identity argument given but no identity specified.")
do_test(["--cafile", ssl_dir / "all-ca.crt", "--psk", "missing.psk", "--psk-identity", "identity"], 1, response="Error: Only one of --psk or --cafile/--capath may be used at once.")
do_test(["-q"], 1, response="Error: -q argument given but no QoS specified.\n\n")
do_test(["-q", "-1"], 1, response="Error: Invalid QoS given: -1\n")
do_test(["-q", "3"], 1, response="Error: Invalid QoS given: 3\n")
do_test(["--tls-alpn"], 1, response="Error: --tls-alpn argument given but no protocol specified.\n\n")
do_test(["--tls-engine"], 1, response="Error: --tls-engine argument given but no engine_id specified.\n\n")
do_test(["--tls-engine-kpass-sha1"], 1, response="Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.\n\n")
do_test(["--tls-version"], 1, response="Error: --tls-version argument given but no version specified.\n\n")
do_test(["--username"], 1, response="Error: -u argument given but no username specified.\n\n")
do_test(["--unix"], 1, response="Error: --unix argument given but no socket path specified.\n\n")
do_test(["-V"], 1, response="Error: --protocol-version argument given but no version specified.\n\n")
do_test(["-V", "2"], 1, response="Error: Invalid protocol version argument given.\n\n")
do_test(["-V", "6"], 1, response="Error: Invalid protocol version argument given.\n\n")
do_test(["--unknown"], 1, response="Error: Unknown option '--unknown'.\n")
do_test(["-q"], 1, response="Error: -q argument given but no QoS specified.")
do_test(["-q", "-1"], 1, response="Error: Invalid QoS given: -1")
do_test(["-q", "3"], 1, response="Error: Invalid QoS given: 3")
do_test(["--tls-alpn"], 1, response="Error: --tls-alpn argument given but no protocol specified.")
do_test(["--tls-engine"], 1, response="Error: --tls-engine argument given but no engine_id specified.")
do_test(["--tls-engine-kpass-sha1"], 1, response="Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.")
do_test(["--tls-version"], 1, response="Error: --tls-version argument given but no version specified.")
do_test(["--username"], 1, response="Error: -u argument given but no username specified.")
do_test(["--unix"], 1, response="Error: --unix argument given but no socket path specified.")
do_test(["-V"], 1, response="Error: --protocol-version argument given but no version specified.")
do_test(["-V", "2"], 1, response="Error: Invalid protocol version argument given.")
do_test(["-V", "6"], 1, response="Error: Invalid protocol version argument given.")
do_test(["--unknown"], 1, response="Error: Unknown option '--unknown'.")
do_test(["--version"], 1) # Gives generic help
# Behaviour with incomplete args is now to run the shell, so these tests don't work
@@ -133,34 +133,34 @@ do_test(["--version"], 1) # Gives generic help
#do_test(["--verbose"], 1) # Gives generic help
# Broker
do_test(["broker", "unknown"], 13, response="Command 'unknown' not recognised.\n")
do_test(["broker", "unknown"], 13, response="Command 'unknown' not recognised.")
if mosq_test.check_features(["WITH_PLUGINS", "WITH_PLUGIN_DYNAMIC_SECURITY"]):
# Dynsec
do_test(["dynsec", "unknown"], 13, response="Command 'unknown' not recognised.\n")
do_test(["-f", "file", "dynsec", "setClientPassword", "admin", "admin", "-i"], 3, response="Error: -i argument given, but no iterations provided.\nError: Invalid input.\n")
do_test(["-f", "file", "dynsec", "setClientPassword", "admin", "admin", "-c"], 3, response="Error: Unknown argument: -c\nError: Invalid input.\n")
do_test(["dynsec", "createClient", "client", "-i"], 3, response="Error: -i argument given, but no clientid provided.\nError: Invalid input.\n")
do_test(["dynsec", "createClient", "client", "-p"], 3, response="Error: -p argument given, but no password provided.\nError: Invalid input.\n")
do_test(["dynsec", "unknown"], 13, response="Command 'unknown' not recognised.")
do_test(["-f", "file", "dynsec", "setClientPassword", "admin", "admin", "-i"], 3, response="Error: -i argument given, but no iterations provided.\nError: Invalid input.")
do_test(["-f", "file", "dynsec", "setClientPassword", "admin", "admin", "-c"], 3, response="Error: Unknown argument: -c\nError: Invalid input.")
do_test(["dynsec", "createClient", "client", "-i"], 3, response="Error: -i argument given, but no clientid provided.\nError: Invalid input.")
do_test(["dynsec", "createClient", "client", "-p"], 3, response="Error: -p argument given, but no password provided.\nError: Invalid input.")
# Env modification
# Missing file
env["HOME"] = "/tmp"
do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n")
do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.")
# Invalid file
env["XDG_CONFIG_HOME"] = "."
with open("mosquitto_ctrl", "w") as f:
f.write(f"--cert {ssl_dir / 'client.crt'}\n")
f.write(f"--key\n")
do_test(["broker"], 1, response="Error: --key argument given but no file specified.\n\n")
f.write(f"--cert {ssl_dir / 'client.crt'}")
f.write(f"--key")
do_test(["broker"], 1, response="Error: --key argument given but no file specified.")
# Empty file
env["XDG_CONFIG_HOME"] = "."
with open("mosquitto_ctrl", "w") as f:
pass
do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n")
do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.")
os.remove("mosquitto_ctrl")
exit(0)
+1 -1
View File
@@ -34,7 +34,7 @@ def ctrl_dynsec_cmd(args, ports, response=None, input=None):
proc = subprocess.run([mosq_paths.mosquitto_ctrl]
+ opts + ["dynsec"] + args,
env=env, capture_output=True, encoding='utf-8', timeout=2, input=input)
env=env, capture_output=True, text=True, encoding='utf-8', input=input)
if response is not None:
if proc.stdout != response:
+18 -17
View File
@@ -9,10 +9,10 @@ mosq_test.require_features(["WITH_TLS"])
def do_test(args, rc_expected, response=None, input=None):
proc = subprocess.run([mosq_paths.mosquitto_passwd]
+ args,
capture_output=True, encoding='utf-8', timeout=2, input=input)
capture_output=True, encoding='utf-8', timeout=2, text=True, input=input)
if response is not None:
if proc.stderr != response:
if not proc.stderr.startswith(response):
print(len(proc.stderr))
print(len(response))
raise ValueError(proc.stderr)
@@ -22,21 +22,22 @@ def do_test(args, rc_expected, response=None, input=None):
raise ValueError(args)
do_test([], 1) # For the usage message
do_test(["-H"], 1, response="Error: -H argument given but not enough other arguments.\n")
do_test(["-H", "nohash"], 1, response="Error: Unknown hash type 'nohash'\n")
do_test(["-I"], 1, response="Error: -I argument given but not enough other arguments.\n")
do_test(["-I", "0"], 1, response="Error: Number of iterations must be > 0.\n")
do_test(["-c", "-D"], 1, response="Error: -c and -D cannot be used together.\n")
do_test(["-c", "-U"], 1, response="Error: -c and -U cannot be used together.\n")
do_test(["-U", "-D"], 1, response="Error: -D and -U cannot be used together.\n")
do_test(["-b", "-D"], 1, response="Error: -b and -D cannot be used together.\n")
do_test(["-c", "-b"], 1, response="Error: -c argument given but password file, username, or password missing.\n")
do_test(["-c"], 1, response="Error: -c argument given but password file or username missing.\n")
do_test(["-D"], 1, response="Error: -D argument given but password file or username missing.\n")
do_test(["-U"], 1, response="Error: -U argument given but password file missing.\n")
do_test(["-D", "pwfile", "bad-username:"], 1, response="Error: Username must not contain the ':' character.\n")
do_test(["-D", "pwfile", "bad-username\n"], 1, response="Error: Username must not contain control characters.\n")
do_test(["-D", "pwfile", "a"*65536], 1, response="Error: Username must be less than 65536 characters long.\n")
do_test(["-H"], 1, response="Error: -H argument given but not enough other arguments.")
do_test(["-H", "nohash"], 1, response="Error: Unknown hash type 'nohash'")
do_test(["-I"], 1, response="Error: -I argument given but not enough other arguments.")
do_test(["-I", "0"], 1, response="Error: Number of iterations must be > 0.")
do_test(["-c", "-D"], 1, response="Error: -c and -D cannot be used together.")
do_test(["-c", "-U"], 1, response="Error: -c and -U cannot be used together.")
do_test(["-U", "-D"], 1, response="Error: -D and -U cannot be used together.")
do_test(["-b", "-D"], 1, response="Error: -b and -D cannot be used together.")
do_test(["-c", "-b"], 1, response="Error: -c argument given but password file, username, or password missing.")
do_test(["-c"], 1, response="Error: -c argument given but password file or username missing.")
do_test(["-D"], 1, response="Error: -D argument given but password file or username missing.")
do_test(["-U"], 1, response="Error: -U argument given but password file missing.")
do_test(["-D", "pwfile", "bad-username:"], 1, response="Error: Username must not contain the ':' character.")
do_test(["-D", "pwfile", "bad-username\n"], 1, response="Error: Username must not contain control characters.")
if platform.system() != 'Windows':
do_test(["-D", "pwfile", "a"*65536], 1, response="Error: Username must be less than 65536 characters long.")
do_test(["-c", "file", "username"], 2, response="Error: Passwords do not match.\n", input="not\nmatching\n")
+1 -1
View File
@@ -23,7 +23,7 @@ def client_check(port, username, password, rc):
def passwd_cmd(args, response=None, input=None, expected_rc=0):
proc = subprocess.run([mosq_paths.mosquitto_passwd]
+ args,
capture_output=True, encoding='utf-8', timeout=2, input=input)
capture_output=True, encoding='utf-8', timeout=2, text=True, input=input)
if response is not None:
if proc.stdout != response and proc.stderr != response:
+1 -1
View File
@@ -9,7 +9,7 @@ mosq_test.require_features(["WITH_TLS"])
def do_test(args, rc_expected, response=None, input=None):
proc = subprocess.run([mosq_paths.mosquitto_passwd]
+ args,
capture_output=True, encoding='utf-8', timeout=2, input=input)
capture_output=True, text=True, encoding='utf-8', timeout=2, input=input)
if response is not None:
if proc.stdout[0:len(response)] != response:
+7 -7
View File
@@ -10,7 +10,7 @@ def do_test(args, rc_expected, response=None, input=None):
capture_output=True, encoding='utf-8', timeout=2, input=input)
if response is not None:
if proc.stderr != response:
if response not in proc.stderr:
print(len(proc.stderr))
print(len(response))
raise ValueError(proc.stderr)
@@ -21,12 +21,12 @@ def do_test(args, rc_expected, response=None, input=None):
do_test([], 1) # For the usage message
do_test(["--help"], 1)
do_test(["--invalid"], 1, response="Error: One of -a or -p must be used.\n")
do_test(["-p"], 1, response="Error: -p argument given but process ID missing.\n")
do_test(["-p", "0"], 1, response="Error: Process ID must be >0.\n")
do_test(["-p", "1"], 1, response="Error: No signal given.\n")
do_test(["-a"], 1, response="Error: No signal given.\n")
do_test(["-p", "1", "invalid"], 1, response="Error: Unknown signal 'invalid'.\n")
do_test(["--invalid"], 1, response="Error: One of -a or -p must be used.")
do_test(["-p"], 1, response="Error: -p argument given but process ID missing.")
do_test(["-p", "0"], 1, response="Error: Process ID must be >0.")
do_test(["-p", "1"], 1, response="Error: No signal given.")
do_test(["-a"], 1, response="Error: No signal given.")
do_test(["-p", "1", "invalid"], 1, response="Error: Unknown signal 'invalid'.")
do_test(["-p", "1", "config-reload"], 0)
do_test(["-p", "1", "log-rotate"], 0)
do_test(["-p", "1", "shutdown"], 0)
@@ -24,13 +24,11 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = sub.communicate()
if sub.returncode != rc_expected:
raise mosq_test.TestError(sub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_sub --help' to see usage.\n"
# Missing args for TLS-PSK related options
do_test(['--psk'], "Error: --psk argument given but no key specified.\n\n" + helps, 1)
do_test(['--psk-identity'], "Error: --psk-identity argument given but no identity specified.\n\n" + helps, 1)
do_test(['--psk'], "Error: --psk argument given but no key specified.", 1)
do_test(['--psk-identity'], "Error: --psk-identity argument given but no identity specified.", 1)
+14 -16
View File
@@ -24,24 +24,22 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = sub.communicate()
if sub.returncode != rc_expected:
raise mosq_test.TestError(sub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_sub --help' to see usage.\n"
# Missing args for TLS related options
do_test(['--cafile'], "Error: --cafile argument given but no file specified.\n\n" + helps, 1)
do_test(['--capath'], "Error: --capath argument given but no directory specified.\n\n" + helps, 1)
do_test(['--cert'], "Error: --cert argument given but no file specified.\n\n" + helps, 1)
do_test(['--ciphers'], "Error: --ciphers argument given but no ciphers specified.\n\n" + helps, 1)
do_test(['--key'], "Error: --key argument given but no file specified.\n\n" + helps, 1)
do_test(['--keyform'], "Error: --keyform argument given but no keyform specified.\n\n" + helps, 1)
do_test(['--tls-alpn'], "Error: --tls-alpn argument given but no protocol specified.\n\n" + helps, 1)
do_test(['--tls-engine'], "Error: --tls-engine argument given but no engine_id specified.\n\n" + helps, 1)
do_test(['--tls-engine-kpass-sha1'], "Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.\n\n" + helps, 1)
do_test(['--tls-version'], "Error: --tls-version argument given but no version specified.\n\n" + helps, 1)
do_test(['--tls-keylog'], "Error: --tls-keylog argument given but no file specified.\n\n" + helps, 1)
do_test(['-L', 'mqtts://localhost'], "Error: Invalid URL for -L argument specified - topic missing.\n" + helps, 1)
do_test(['-L', 'wss://localhost'], "Error: Invalid URL for -L argument specified - topic missing.\n" + helps, 1)
do_test(['--cafile'], "Error: --cafile argument given but no file specified.", 1)
do_test(['--capath'], "Error: --capath argument given but no directory specified.", 1)
do_test(['--cert'], "Error: --cert argument given but no file specified.", 1)
do_test(['--ciphers'], "Error: --ciphers argument given but no ciphers specified.", 1)
do_test(['--key'], "Error: --key argument given but no file specified.", 1)
do_test(['--keyform'], "Error: --keyform argument given but no keyform specified.", 1)
do_test(['--tls-alpn'], "Error: --tls-alpn argument given but no protocol specified.", 1)
do_test(['--tls-engine'], "Error: --tls-engine argument given but no engine_id specified.", 1)
do_test(['--tls-engine-kpass-sha1'], "Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.", 1)
do_test(['--tls-version'], "Error: --tls-version argument given but no version specified.", 1)
do_test(['--tls-keylog'], "Error: --tls-keylog argument given but no file specified.", 1)
do_test(['-L', 'mqtts://localhost'], "Error: Invalid URL for -L argument specified - topic missing.", 1)
do_test(['-L', 'wss://localhost'], "Error: Invalid URL for -L argument specified - topic missing.", 1)
@@ -22,113 +22,111 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = sub.communicate()
if sub.returncode != rc_expected:
raise mosq_test.TestError(sub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_sub --help' to see usage.\n"
# Usage and version, ignore actual text though.
do_test(['--help'], None, 1)
do_test(['--version'], None, 1)
# Missing args
do_test(['-A'], "Error: -A argument given but no address specified.\n\n" + helps, 1)
do_test(['-C'], "Error: -C argument given but no count specified.\n\n" + helps, 1)
do_test(['-h'], "Error: -h argument given but no host specified.\n\n" + helps, 1)
do_test(['-i'], "Error: -i argument given but no id specified.\n\n" + helps, 1)
do_test(['-I'], "Error: -I argument given but no id prefix specified.\n\n" + helps, 1)
do_test(['-k'], "Error: -k argument given but no keepalive specified.\n\n" + helps, 1)
do_test(['-L'], "Error: -L argument given but no URL specified.\n\n" + helps, 1)
do_test(['-M'], "Error: -M argument given but max_inflight not specified.\n\n" + helps, 1)
do_test(['-o'], "Error: -o argument given but no options file specified.\n\n" + helps, 1)
do_test(['-p'], "Error: -p argument given but no port specified.\n\n" + helps, 1)
do_test(['-P'], "Error: -P argument given but no password specified.\n\n" + helps, 1)
do_test(['-A'], "Error: -A argument given but no address specified.", 1)
do_test(['-C'], "Error: -C argument given but no count specified.", 1)
do_test(['-h'], "Error: -h argument given but no host specified.", 1)
do_test(['-i'], "Error: -i argument given but no id specified.", 1)
do_test(['-I'], "Error: -I argument given but no id prefix specified.", 1)
do_test(['-k'], "Error: -k argument given but no keepalive specified.", 1)
do_test(['-L'], "Error: -L argument given but no URL specified.", 1)
do_test(['-M'], "Error: -M argument given but max_inflight not specified.", 1)
do_test(['-o'], "Error: -o argument given but no options file specified.", 1)
do_test(['-p'], "Error: -p argument given but no port specified.", 1)
do_test(['-P'], "Error: -P argument given but no password specified.", 1)
if mosq_test.check_features(["WITH_SOCKS"]):
do_test(['--proxy'], "Error: --proxy argument given but no proxy url specified.\n\n" + helps, 1)
do_test(['--proxy'], "Error: --proxy argument given but no proxy url specified.", 1)
else:
do_test(['--proxy'], "Error: Unknown option '--proxy'.\n" + helps, 1)
do_test(['--random-filter'], "Error: --random-filter argument given but no chance specified.\n\n" + helps, 1)
do_test(['-q'], "Error: -q argument given but no QoS specified.\n\n" + helps, 1)
do_test(['-t'], "Error: -t argument given but no topic specified.\n\n" + helps, 1)
do_test(['-u'], "Error: -u argument given but no username specified.\n\n" + helps, 1)
do_test(['--unix'], "Error: --unix argument given but no socket path specified.\n\n" + helps, 1)
do_test(['-V'], "Error: --protocol-version argument given but no version specified.\n\n" + helps, 1)
do_test(['--will-payload'], "Error: --will-payload argument given but no will payload specified.\n\n" + helps, 1)
do_test(['--will-qos'], "Error: --will-qos argument given but no will QoS specified.\n\n" + helps, 1)
do_test(['--will-topic'], "Error: --will-topic argument given but no will topic specified.\n\n" + helps, 1)
do_test(['-x'], "Error: -x argument given but no session expiry interval specified.\n\n" + helps, 1)
do_test(['-F'], "Error: -F argument given but no format specified.\n\n" + helps, 1)
do_test(['-o'], "Error: -o argument given but no options file specified.\n\n" + helps, 1)
do_test(['-T'], "Error: -T argument given but no topic filter specified.\n\n" + helps, 1)
do_test(['-U'], "Error: -U argument given but no unsubscribe topic specified.\n\n" + helps, 1)
do_test(['-W'], "Error: -W argument given but no timeout specified.\n\n" + helps, 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.\n" + helps, 1)
do_test(['--proxy'], "Error: Unknown option '--proxy'.", 1)
do_test(['--random-filter'], "Error: --random-filter argument given but no chance specified.", 1)
do_test(['-q'], "Error: -q argument given but no QoS specified.", 1)
do_test(['-t'], "Error: -t argument given but no topic specified.", 1)
do_test(['-u'], "Error: -u argument given but no username specified.", 1)
do_test(['--unix'], "Error: --unix argument given but no socket path specified.", 1)
do_test(['-V'], "Error: --protocol-version argument given but no version specified.", 1)
do_test(['--will-payload'], "Error: --will-payload argument given but no will payload specified.", 1)
do_test(['--will-qos'], "Error: --will-qos argument given but no will QoS specified.", 1)
do_test(['--will-topic'], "Error: --will-topic argument given but no will topic specified.", 1)
do_test(['-x'], "Error: -x argument given but no session expiry interval specified.", 1)
do_test(['-F'], "Error: -F argument given but no format specified.", 1)
do_test(['-o'], "Error: -o argument given but no options file specified.", 1)
do_test(['-T'], "Error: -T argument given but no topic filter specified.", 1)
do_test(['-U'], "Error: -U argument given but no unsubscribe topic specified.", 1)
do_test(['-W'], "Error: -W argument given but no timeout specified.", 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.", 1)
# No -t or -U
do_test([], "Error: You must specify a topic to subscribe to (-t) or unsubscribe from (-U).\n" + helps, 1)
do_test([], "Error: You must specify a topic to subscribe to (-t) or unsubscribe from (-U).", 1)
# Invalid combinations
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)
do_test(['-I', 'id-prefix', '-i', 'id'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.", 1)
do_test(['-I', 'id-prefix', '-i', 'id'], "Error: -i and -I argument cannot be used together.", 1)
# Duplicate options
do_test(['-o', 'file1', '-o', 'file2'], "Error: Duplicate -o argument given.\n\n" + helps, 1)
do_test(['-o', 'file1', '-o', 'file2'], "Error: Duplicate -o argument given.", 1)
# Invalid output format
do_test(['-F', '%'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%0'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%-'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%1'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%.'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%.1'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%Z'], "Error: Invalid format specifier 'Z'.\n" + helps, 1)
do_test(['-F', '@'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '\\'], "Error: Incomplete escape specifier.\n" + helps, 1)
do_test(['-F', '\\Z'], "Error: Invalid escape specifier 'Z'.\n" + helps, 1)
do_test(['-F', '%'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%0'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%-'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%1'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%.'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%.1'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%Z'], "Error: Invalid format specifier 'Z'.", 1)
do_test(['-F', '@'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '\\'], "Error: Incomplete escape specifier.", 1)
do_test(['-F', '\\Z'], "Error: Invalid escape specifier 'Z'.", 1)
# Invalid values
do_test(['-k', '-1'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n" + helps, 1)
do_test(['-k', '65536'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n" + helps, 1)
do_test(['-M', '0'], "Error: Maximum inflight messages must be greater than 0.\n\n" + helps, 1)
do_test(['-p', '-1'], "Error: Invalid port given: -1\n" + helps, 1)
do_test(['-p', '65536'], "Error: Invalid port given: 65536\n" + helps, 1)
do_test(['-q', '-1'], "Error: Invalid QoS given: -1\n" + helps, 1)
do_test(['-q', '3'], "Error: Invalid QoS given: 3\n" + helps, 1)
do_test(['-C', '0'], "Error: Invalid message count \"0\".\n\n" + helps, 1)
do_test(['-L', 'invalid://'], "Error: Unsupported URL scheme.\n\n" + helps, 1)
do_test(['-L', 'mqtt://localhost'], "Error: Invalid URL for -L argument specified - topic missing.\n" + helps, 1)
do_test(['-L', 'ws://localhost'], "Error: Invalid URL for -L argument specified - topic missing.\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '-1'], "Error: Property value (-1) out of range for property request-problem-information.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '256'], "Error: Property value (256) out of range for property request-problem-information.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '-1'], "Error: Property value (-1) out of range for property receive-maximum.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '-1'], "Error: Property value (-1) out of range for property subscription-identifier.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '4294967296'], "Error: Property value (4294967296) out of range for property subscription-identifier.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'subscribe', 'topic-alias', '1'], "Error: topic-alias property not allowed for subscribe in --property argument.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'auth', 'authentication-method', '1'], "Error: authentication-method property not supported for auth in --property argument.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'puback', 'reason-string', '1'], "Error: reason-string property not supported for puback in --property argument.\n\n" + helps, 1)
do_test(['-t', '++'], "Error: Invalid subscription topic '++', are all '+' and '#' wildcards correct?\n" + helps, 1)
do_test(['-T', '++'], "Error: Invalid filter topic '++', are all '+' and '#' wildcards correct?\n" + helps, 1)
do_test(['-U', '++'], "Error: Invalid unsubscribe topic '++', are all '+' and '#' wildcards correct?\n" + helps, 1)
do_test(['-V', '0'], "Error: Invalid protocol version argument given.\n\n" + helps, 1)
do_test(['-W', '0'], "Error: Invalid timeout \"0\".\n\n" + helps, 1)
do_test(['--will-qos', '-1'], "Error: Invalid will QoS -1.\n\n" + helps, 1)
do_test(['--will-qos', '3'], "Error: Invalid will QoS 3.\n\n" + helps, 1)
do_test(['--will-topic', '+'], "Error: Invalid will topic '+', does it contain '+' or '#'?\n" + helps, 1)
do_test(['-x', 'A'], "Error: session-expiry-interval not a number.\n\n" + helps, 1)
do_test(['-x', '-2'], "Error: session-expiry-interval out of range.\n\n" + helps, 1)
do_test(['-x', '4294967296'], "Error: session-expiry-interval out of range.\n\n" + helps, 1)
do_test(['--retain-handling', 'invalid'], "Error: Unknown value 'invalid' for --retain-handling.\n\n" + helps, 1)
do_test(['-k', '-1'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.", 1)
do_test(['-k', '65536'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.", 1)
do_test(['-M', '0'], "Error: Maximum inflight messages must be greater than 0.", 1)
do_test(['-p', '-1'], "Error: Invalid port given: -1", 1)
do_test(['-p', '65536'], "Error: Invalid port given: 65536", 1)
do_test(['-q', '-1'], "Error: Invalid QoS given: -1", 1)
do_test(['-q', '3'], "Error: Invalid QoS given: 3", 1)
do_test(['-C', '0'], "Error: Invalid message count \"0\".", 1)
do_test(['-L', 'invalid://'], "Error: Unsupported URL scheme.", 1)
do_test(['-L', 'mqtt://localhost'], "Error: Invalid URL for -L argument specified - topic missing.", 1)
do_test(['-L', 'ws://localhost'], "Error: Invalid URL for -L argument specified - topic missing.", 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '-1'], "Error: Property value (-1) out of range for property request-problem-information.", 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '256'], "Error: Property value (256) out of range for property request-problem-information.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '-1'], "Error: Property value (-1) out of range for property receive-maximum.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.", 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.", 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.", 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '-1'], "Error: Property value (-1) out of range for property subscription-identifier.", 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '4294967296'], "Error: Property value (4294967296) out of range for property subscription-identifier.", 1)
do_test(['-V', '5', '-D', 'subscribe', 'topic-alias', '1'], "Error: topic-alias property not allowed for subscribe in --property argument.", 1)
do_test(['-V', '5', '-D', 'auth', 'authentication-method', '1'], "Error: authentication-method property not supported for auth in --property argument.", 1)
do_test(['-V', '5', '-D', 'puback', 'reason-string', '1'], "Error: reason-string property not supported for puback in --property argument.", 1)
do_test(['-t', '++'], "Error: Invalid subscription topic '++', are all '+' and '#' wildcards correct?", 1)
do_test(['-T', '++'], "Error: Invalid filter topic '++', are all '+' and '#' wildcards correct?", 1)
do_test(['-U', '++'], "Error: Invalid unsubscribe topic '++', are all '+' and '#' wildcards correct?", 1)
do_test(['-V', '0'], "Error: Invalid protocol version argument given.", 1)
do_test(['-W', '0'], "Error: Invalid timeout \"0\".", 1)
do_test(['--will-qos', '-1'], "Error: Invalid will QoS -1.", 1)
do_test(['--will-qos', '3'], "Error: Invalid will QoS 3.", 1)
do_test(['--will-topic', '+'], "Error: Invalid will topic '+', does it contain '+' or '#'?", 1)
do_test(['-x', 'A'], "Error: session-expiry-interval not a number.", 1)
do_test(['-x', '-2'], "Error: session-expiry-interval out of range.", 1)
do_test(['-x', '4294967296'], "Error: session-expiry-interval out of range.", 1)
do_test(['--retain-handling', 'invalid'], "Error: Unknown value 'invalid' for --retain-handling.", 1)
# Unknown options
do_test(['--unknown'], "Error: Unknown option '--unknown'.\n" + helps, 1)
do_test(['-l'], "Error: Unknown option '-l'.\n" + helps, 1)
do_test(['-m'], "Error: Unknown option '-m'.\n" + helps, 1)
do_test(['-n'], "Error: Unknown option '-n'.\n" + helps, 1)
do_test(['-r'], "Error: Unknown option '-r'.\n" + helps, 1)
do_test(['--repeat'], "Error: Unknown option '--repeat'.\n" + helps, 1)
do_test(['--repeat-delay'], "Error: Unknown option '--repeat-delay'.\n" + helps, 1)
do_test(['-s'], "Error: Unknown option '-s'.\n" + helps, 1)
do_test(['--unknown'], "Error: Unknown option '--unknown'.", 1)
do_test(['-l'], "Error: Unknown option '-l'.", 1)
do_test(['-m'], "Error: Unknown option '-m'.", 1)
do_test(['-n'], "Error: Unknown option '-n'.", 1)
do_test(['-r'], "Error: Unknown option '-r'.", 1)
do_test(['--repeat'], "Error: Unknown option '--repeat'.", 1)
do_test(['--repeat-delay'], "Error: Unknown option '--repeat-delay'.", 1)
do_test(['-s'], "Error: Unknown option '-s'.", 1)
@@ -24,19 +24,17 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = pub.communicate()
if pub.returncode != rc_expected:
raise mosq_test.TestError(pub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_pub --help' to see usage.\n"
# Missing args
do_test(['--psk'], "Error: --psk argument given but no key specified.\n\n" + helps, 1)
do_test(['--psk-identity'], "Error: --psk-identity argument given but no identity specified.\n\n" + helps, 1)
do_test(['--psk'], "Error: --psk argument given but no key specified.", 1)
do_test(['--psk-identity'], "Error: --psk-identity argument given but no identity specified.", 1)
# Invalid combinations
do_test(['--cafile', 'file', '--psk', 'key'], "Error: Only one of --psk or --cafile/--capath may be used at once.\n" + helps, 1)
do_test(['--capath', 'dir', '--psk', 'key'], "Error: Only one of --psk or --cafile/--capath may be used at once.\n" + helps, 1)
do_test(['--psk', 'key'], "Error: --psk-identity required if --psk used.\n" + helps, 1)
do_test(['--cafile', 'file', '--psk', 'key'], "Error: Only one of --psk or --cafile/--capath may be used at once.", 1)
do_test(['--capath', 'dir', '--psk', 'key'], "Error: Only one of --psk or --cafile/--capath may be used at once.", 1)
do_test(['--psk', 'key'], "Error: --psk-identity required if --psk used.", 1)
+16 -18
View File
@@ -24,31 +24,29 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = pub.communicate()
if pub.returncode != rc_expected:
raise mosq_test.TestError(pub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde.decode('utf-8'))
if __name__ == '__main__':
helps = "\nUse 'mosquitto_pub --help' to see usage.\n"
# Missing args
do_test(['--cafile'], "Error: --cafile argument given but no file specified.\n\n" + helps, 1)
do_test(['--capath'], "Error: --capath argument given but no directory specified.\n\n" + helps, 1)
do_test(['--cert'], "Error: --cert argument given but no file specified.\n\n" + helps, 1)
do_test(['--ciphers'], "Error: --ciphers argument given but no ciphers specified.\n\n" + helps, 1)
do_test(['--key'], "Error: --key argument given but no file specified.\n\n" + helps, 1)
do_test(['--keyform'], "Error: --keyform argument given but no keyform specified.\n\n" + helps, 1)
do_test(['--tls-alpn'], "Error: --tls-alpn argument given but no protocol specified.\n\n" + helps, 1)
do_test(['--tls-engine'], "Error: --tls-engine argument given but no engine_id specified.\n\n" + helps, 1)
do_test(['--tls-engine-kpass-sha1'], "Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.\n\n" + helps, 1)
do_test(['--tls-version'], "Error: --tls-version argument given but no version specified.\n\n" + helps, 1)
do_test(['--cafile'], "Error: --cafile argument given but no file specified.", 1)
do_test(['--capath'], "Error: --capath argument given but no directory specified.", 1)
do_test(['--cert'], "Error: --cert argument given but no file specified.", 1)
do_test(['--ciphers'], "Error: --ciphers argument given but no ciphers specified.", 1)
do_test(['--key'], "Error: --key argument given but no file specified.", 1)
do_test(['--keyform'], "Error: --keyform argument given but no keyform specified.", 1)
do_test(['--tls-alpn'], "Error: --tls-alpn argument given but no protocol specified.", 1)
do_test(['--tls-engine'], "Error: --tls-engine argument given but no engine_id specified.", 1)
do_test(['--tls-engine-kpass-sha1'], "Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.", 1)
do_test(['--tls-version'], "Error: --tls-version argument given but no version specified.", 1)
# Invalid combinations
do_test(['--cert', 'file'], "Error: Both certfile and keyfile must be provided if one of them is set.\n" + helps, 1)
do_test(['--key', 'file'], "Error: Both certfile and keyfile must be provided if one of them is set.\n" + helps, 1)
do_test(['--keyform', 'file'], "Error: If keyform is set, keyfile must be also specified.\n" + helps, 1)
do_test(['--tls-engine-kpass-sha1', 'hash'], "Error: when using tls-engine-kpass-sha1, both tls-engine and keyform must also be provided.\n" + helps, 1)
do_test(['--cert', 'file'], "Error: Both certfile and keyfile must be provided if one of them is set.", 1)
do_test(['--key', 'file'], "Error: Both certfile and keyfile must be provided if one of them is set.", 1)
do_test(['--keyform', 'file'], "Error: If keyform is set, keyfile must be also specified.", 1)
do_test(['--tls-engine-kpass-sha1', 'hash'], "Error: when using tls-engine-kpass-sha1, both tls-engine and keyform must also be provided.", 1)
# Invalid values
do_test(['--tls-keylog', 'keylog', '-t','topic','-m','1', '--cafile', 'missing'], "Error: Problem setting TLS options: File not found.\n", 1)
do_test(['--tls-keylog', 'keylog', '-t','topic','-m','1', '--cafile', 'missing'], "Error: Problem setting TLS options: File not found.", 1)
@@ -22,107 +22,105 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = pub.communicate()
if pub.returncode != rc_expected:
raise mosq_test.TestError(pub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_pub --help' to see usage.\n"
# Usage, version, ignore actual text though.
do_test(['--help'], None, 1)
do_test(['--version'], None, 1)
# Missing args
do_test(['-A'], "Error: -A argument given but no address specified.\n\n" + helps, 1)
do_test(['-f'], "Error: -f argument given but no file specified.\n\n" + helps, 1)
do_test(['-h'], "Error: -h argument given but no host specified.\n\n" + helps, 1)
do_test(['-i'], "Error: -i argument given but no id specified.\n\n" + helps, 1)
do_test(['-I'], "Error: -I argument given but no id prefix specified.\n\n" + helps, 1)
do_test(['-k'], "Error: -k argument given but no keepalive specified.\n\n" + helps, 1)
do_test(['-L'], "Error: -L argument given but no URL specified.\n\n" + helps, 1)
do_test(['-M'], "Error: -M argument given but max_inflight not specified.\n\n" + helps, 1)
do_test(['-m'], "Error: -m argument given but no message specified.\n\n" + helps, 1)
do_test(['-o'], "Error: -o argument given but no options file specified.\n\n" + helps, 1)
do_test(['-p'], "Error: -p argument given but no port specified.\n\n" + helps, 1)
do_test(['-P'], "Error: -P argument given but no password specified.\n\n" + helps, 1)
do_test(['-A'], "Error: -A argument given but no address specified.", 1)
do_test(['-f'], "Error: -f argument given but no file specified.", 1)
do_test(['-h'], "Error: -h argument given but no host specified.", 1)
do_test(['-i'], "Error: -i argument given but no id specified.", 1)
do_test(['-I'], "Error: -I argument given but no id prefix specified.", 1)
do_test(['-k'], "Error: -k argument given but no keepalive specified.", 1)
do_test(['-L'], "Error: -L argument given but no URL specified.", 1)
do_test(['-M'], "Error: -M argument given but max_inflight not specified.", 1)
do_test(['-m'], "Error: -m argument given but no message specified.", 1)
do_test(['-o'], "Error: -o argument given but no options file specified.", 1)
do_test(['-p'], "Error: -p argument given but no port specified.", 1)
do_test(['-P'], "Error: -P argument given but no password specified.", 1)
if mosq_test.check_features(["WITH_SOCKS"]):
do_test(['--proxy'], "Error: --proxy argument given but no proxy url specified.\n\n" + helps, 1)
do_test(['--proxy'], "Error: --proxy argument given but no proxy url specified.", 1)
else:
do_test(['--proxy'], "Error: Unknown option '--proxy'.\n" + helps, 1)
do_test(['-q'], "Error: -q argument given but no QoS specified.\n\n" + helps, 1)
do_test(['--repeat'], "Error: --repeat argument given but no count specified.\n\n" + helps, 1)
do_test(['--repeat-delay'], "Error: --repeat-delay argument given but no time specified.\n\n" + helps, 1)
do_test(['-t'], "Error: -t argument given but no topic specified.\n\n" + helps, 1)
do_test(['-u'], "Error: -u argument given but no username specified.\n\n" + helps, 1)
do_test(['--unix'], "Error: --unix argument given but no socket path specified.\n\n" + helps, 1)
do_test(['-V'], "Error: --protocol-version argument given but no version specified.\n\n" + helps, 1)
do_test(['--will-payload'], "Error: --will-payload argument given but no will payload specified.\n\n" + helps, 1)
do_test(['--will-qos'], "Error: --will-qos argument given but no will QoS specified.\n\n" + helps, 1)
do_test(['--will-topic'], "Error: --will-topic argument given but no will topic specified.\n\n" + helps, 1)
do_test(['-x'], "Error: -x argument given but no session expiry interval specified.\n\n" + helps, 1)
do_test(['--proxy'], "Error: Unknown option '--proxy'.", 1)
do_test(['-q'], "Error: -q argument given but no QoS specified.", 1)
do_test(['--repeat'], "Error: --repeat argument given but no count specified.", 1)
do_test(['--repeat-delay'], "Error: --repeat-delay argument given but no time specified.", 1)
do_test(['-t'], "Error: -t argument given but no topic specified.", 1)
do_test(['-u'], "Error: -u argument given but no username specified.", 1)
do_test(['--unix'], "Error: --unix argument given but no socket path specified.", 1)
do_test(['-V'], "Error: --protocol-version argument given but no version specified.", 1)
do_test(['--will-payload'], "Error: --will-payload argument given but no will payload specified.", 1)
do_test(['--will-qos'], "Error: --will-qos argument given but no will QoS specified.", 1)
do_test(['--will-topic'], "Error: --will-topic argument given but no will topic specified.", 1)
do_test(['-x'], "Error: -x argument given but no session expiry interval specified.", 1)
do_test(['-V', '5', '-D'], "Error: --property argument given but not enough arguments specified.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect'], "Error: --property argument given but not enough arguments specified.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum'], "Error: --property argument given but not enough arguments specified.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'invalid', 'receive-maximum', '1'], "Error: Invalid command invalid given in --property argument.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'invalid', '1'], "Error: Invalid property name invalid given in --property argument.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'will-delay-interval', '1'], "Error: will-delay-interval property not allowed for connect in --property argument.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'user-property', 'key'], "Error: --property argument given but not enough arguments specified.\n\n" + helps, 1)
do_test(['-V', '5', '-D'], "Error: --property argument given but not enough arguments specified.", 1)
do_test(['-V', '5', '-D', 'connect'], "Error: --property argument given but not enough arguments specified.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum'], "Error: --property argument given but not enough arguments specified.", 1)
do_test(['-V', '5', '-D', 'invalid', 'receive-maximum', '1'], "Error: Invalid command invalid given in --property argument.", 1)
do_test(['-V', '5', '-D', 'connect', 'invalid', '1'], "Error: Invalid property name invalid given in --property argument.", 1)
do_test(['-V', '5', '-D', 'connect', 'will-delay-interval', '1'], "Error: will-delay-interval property not allowed for connect in --property argument.", 1)
do_test(['-V', '5', '-D', 'connect', 'user-property', 'key'], "Error: --property argument given but not enough arguments specified.", 1)
# Invalid combinations
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)
do_test(['-I', 'id-prefix', '-i', 'id'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.\n" + helps, 1)
do_test(['--will-retain'], "Error: Will retain given, but no will topic given.\n" + helps, 1)
do_test(['-V', 'mqttv5', '-x', '-1'], "Error: You must provide a client id if you are using an infinite session expiry interval.\n" + helps, 1)
do_test(['-V', 'mqttv311', '-c'], "Error: You must provide a client id if you are using the -c option.\n" + helps, 1)
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.", 1)
do_test(['-I', 'id-prefix', '-i', 'id'], "Error: -i and -I argument cannot be used together.", 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.", 1)
do_test(['--will-retain'], "Error: Will retain given, but no will topic given.", 1)
do_test(['-V', 'mqttv5', '-x', '-1'], "Error: You must provide a client id if you are using an infinite session expiry interval.", 1)
do_test(['-V', 'mqttv311', '-c'], "Error: You must provide a client id if you are using the -c option.", 1)
# Mixed message types
do_test(['-m', 'message', '-f', 'file'], "Error: Only one type of message can be sent at once.\n\n" + helps, 1)
do_test(['-m', 'message', '-l'], "Error: Only one type of message can be sent at once.\n\n" + helps, 1)
do_test(['-l', '-m', 'message'], "Error: Only one type of message can be sent at once.\n\n" + helps, 1)
do_test(['-l', '-n'], "Error: Only one type of message can be sent at once.\n\n" + helps, 1)
do_test(['-l', '-s'], "Error: Only one type of message can be sent at once.\n\n" + helps, 1)
do_test(['-m', 'message', '-f', 'file'], "Error: Only one type of message can be sent at once.", 1)
do_test(['-m', 'message', '-l'], "Error: Only one type of message can be sent at once.", 1)
do_test(['-l', '-m', 'message'], "Error: Only one type of message can be sent at once.", 1)
do_test(['-l', '-n'], "Error: Only one type of message can be sent at once.", 1)
do_test(['-l', '-s'], "Error: Only one type of message can be sent at once.", 1)
# Invalid values
do_test(['-t', 'topic', '-f', 'missing'], "Error: Unable to read file \"missing\": No such file or directory.\nError loading input file \"missing\".\n", 1)
do_test(['-k', '-1'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n" + helps, 1)
do_test(['-k', '65536'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n" + helps, 1)
do_test(['-M', '0'], "Error: Maximum inflight messages must be greater than 0.\n\n" + helps, 1)
do_test(['-p', '-1'], "Error: Invalid port given: -1\n" + helps, 1)
do_test(['-p', '65536'], "Error: Invalid port given: 65536\n" + helps, 1)
do_test(['-q', '-1'], "Error: Invalid QoS given: -1\n" + helps, 1)
do_test(['-q', '3'], "Error: Invalid QoS given: 3\n" + helps, 1)
do_test(['--repeat-delay', '-1'], "Error: --repeat-delay argument must be >=0.0.\n\n" + helps, 1)
do_test(['-t', 'topic/+'], "Error: Invalid publish topic 'topic/+', does it contain '+' or '#'?\n" + helps, 1)
do_test(['-t', 'topic/#'], "Error: Invalid publish topic 'topic/#', does it contain '+' or '#'?\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '-1'], "Error: Property value (-1) out of range for property request-problem-information.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '256'], "Error: Property value (256) out of range for property request-problem-information.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '-1'], "Error: Property value (-1) out of range for property receive-maximum.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'subscription-identifier', '1'], "Error: subscription-identifier property not allowed for connect in --property argument.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'publish', 'subscription-identifier', '1'], "Error: subscription-identifier property not supported for publish in --property argument.\n\n" + helps, 1)
do_test(['-k', '-1'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.", 1)
do_test(['-k', '65536'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.", 1)
do_test(['-M', '0'], "Error: Maximum inflight messages must be greater than 0.", 1)
do_test(['-p', '-1'], "Error: Invalid port given: -1", 1)
do_test(['-p', '65536'], "Error: Invalid port given: 65536", 1)
do_test(['-q', '-1'], "Error: Invalid QoS given: -1", 1)
do_test(['-q', '3'], "Error: Invalid QoS given: 3", 1)
do_test(['--repeat-delay', '-1'], "Error: --repeat-delay argument must be >=0.0.", 1)
do_test(['-t', 'topic/+'], "Error: Invalid publish topic 'topic/+', does it contain '+' or '#'?", 1)
do_test(['-t', 'topic/#'], "Error: Invalid publish topic 'topic/#', does it contain '+' or '#'?", 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '-1'], "Error: Property value (-1) out of range for property request-problem-information.", 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '256'], "Error: Property value (256) out of range for property request-problem-information.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '-1'], "Error: Property value (-1) out of range for property receive-maximum.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.", 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.", 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.", 1)
do_test(['-V', '5', '-D', 'connect', 'subscription-identifier', '1'], "Error: subscription-identifier property not allowed for connect in --property argument.", 1)
do_test(['-V', '5', '-D', 'publish', 'subscription-identifier', '1'], "Error: subscription-identifier property not supported for publish in --property argument.", 1)
# Unknown options
do_test(['--unknown'], "Error: Unknown option '--unknown'.\n" + helps, 1)
do_test(['-C', '1'], "Error: Unknown option '-C'.\n" + helps, 1)
do_test(['-e', 'response-topic'], "Error: Unknown option '-e'.\n" + helps, 1)
do_test(['-E'], "Error: Unknown option '-E'.\n" + helps, 1)
do_test(['-F', '%p'], "Error: Unknown option '-F'.\n" + helps, 1)
do_test(['-N'], "Error: Unknown option '-N'.\n" + helps, 1)
do_test(['--pretty'], "Error: Unknown option '--pretty'.\n" + helps, 1)
do_test(['-R'], "Error: Unknown option '-R'.\n" + helps, 1)
do_test(['--random-filter'], "Error: Unknown option '--random-filter'.\n" + helps, 1)
do_test(['--remove-retained'], "Error: Unknown option '--remove-retained'.\n" + helps, 1)
do_test(['--retain-as-published'], "Error: Unknown option '--retain-as-published'.\n" + helps, 1)
do_test(['--retain-handling', 'invalid'], "Error: Unknown option '--retain-handling'.\n" + helps, 1)
do_test(['--retained-only'], "Error: Unknown option '--retained-only'.\n" + helps, 1)
do_test(['-T'], "Error: Unknown option '-T'.\n" + helps, 1)
do_test(['-U'], "Error: Unknown option '-U'.\n" + helps, 1)
do_test(['-v'], "Error: Unknown option '-v'.\n" + helps, 1)
do_test(['-W'], "Error: Unknown option '-W'.\n" + helps, 1)
do_test(['-w'], "Error: Unknown option '-w'.\n" + helps, 1)
do_test(['--unknown'], "Error: Unknown option '--unknown'.", 1)
do_test(['-C', '1'], "Error: Unknown option '-C'.", 1)
do_test(['-e', 'response-topic'], "Error: Unknown option '-e'.", 1)
do_test(['-E'], "Error: Unknown option '-E'.", 1)
do_test(['-F', '%p'], "Error: Unknown option '-F'.", 1)
do_test(['-N'], "Error: Unknown option '-N'.", 1)
do_test(['--pretty'], "Error: Unknown option '--pretty'.", 1)
do_test(['-R'], "Error: Unknown option '-R'.", 1)
do_test(['--random-filter'], "Error: Unknown option '--random-filter'.", 1)
do_test(['--remove-retained'], "Error: Unknown option '--remove-retained'.", 1)
do_test(['--retain-as-published'], "Error: Unknown option '--retain-as-published'.", 1)
do_test(['--retain-handling', 'invalid'], "Error: Unknown option '--retain-handling'.", 1)
do_test(['--retained-only'], "Error: Unknown option '--retained-only'.", 1)
do_test(['-T'], "Error: Unknown option '-T'.", 1)
do_test(['-U'], "Error: Unknown option '-U'.", 1)
do_test(['-v'], "Error: Unknown option '-v'.", 1)
do_test(['-W'], "Error: Unknown option '-W'.", 1)
do_test(['-w'], "Error: Unknown option '-w'.", 1)
+3 -5
View File
@@ -23,13 +23,11 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = sub.communicate()
if sub.returncode != rc_expected:
raise mosq_test.TestError(sub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_rr --help' to see usage.\n"
# Missing args for TLS-PSK related options
do_test(['--psk'], "Error: --psk argument given but no key specified.\n\n" + helps, 1)
do_test(['--psk-identity'], "Error: --psk-identity argument given but no identity specified.\n\n" + helps, 1)
do_test(['--psk'], "Error: --psk argument given but no key specified.", 1)
do_test(['--psk-identity'], "Error: --psk-identity argument given but no identity specified.", 1)
+11 -13
View File
@@ -22,21 +22,19 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = sub.communicate()
if sub.returncode != rc_expected:
raise mosq_test.TestError(sub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_rr --help' to see usage.\n"
# Missing args for TLS related options
do_test(['--cafile'], "Error: --cafile argument given but no file specified.\n\n" + helps, 1)
do_test(['--capath'], "Error: --capath argument given but no directory specified.\n\n" + helps, 1)
do_test(['--cert'], "Error: --cert argument given but no file specified.\n\n" + helps, 1)
do_test(['--ciphers'], "Error: --ciphers argument given but no ciphers specified.\n\n" + helps, 1)
do_test(['--key'], "Error: --key argument given but no file specified.\n\n" + helps, 1)
do_test(['--keyform'], "Error: --keyform argument given but no keyform specified.\n\n" + helps, 1)
do_test(['--tls-alpn'], "Error: --tls-alpn argument given but no protocol specified.\n\n" + helps, 1)
do_test(['--tls-engine'], "Error: --tls-engine argument given but no engine_id specified.\n\n" + helps, 1)
do_test(['--tls-engine-kpass-sha1'], "Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.\n\n" + helps, 1)
do_test(['--tls-version'], "Error: --tls-version argument given but no version specified.\n\n" + helps, 1)
do_test(['--cafile'], "Error: --cafile argument given but no file specified.", 1)
do_test(['--capath'], "Error: --capath argument given but no directory specified.", 1)
do_test(['--cert'], "Error: --cert argument given but no file specified.", 1)
do_test(['--ciphers'], "Error: --ciphers argument given but no ciphers specified.", 1)
do_test(['--key'], "Error: --key argument given but no file specified.", 1)
do_test(['--keyform'], "Error: --keyform argument given but no keyform specified.", 1)
do_test(['--tls-alpn'], "Error: --tls-alpn argument given but no protocol specified.", 1)
do_test(['--tls-engine'], "Error: --tls-engine argument given but no engine_id specified.", 1)
do_test(['--tls-engine-kpass-sha1'], "Error: --tls-engine-kpass-sha1 argument given but no kpass sha1 specified.", 1)
do_test(['--tls-version'], "Error: --tls-version argument given but no version specified.", 1)
+75 -77
View File
@@ -20,102 +20,100 @@ def do_test(args, stderr_expected, rc_expected):
(stdo, stde) = sub.communicate()
if sub.returncode != rc_expected:
raise mosq_test.TestError(sub.returncode)
if stderr_expected is not None and stde.decode('utf-8') != stderr_expected:
if stderr_expected is not None and stderr_expected not in stde.decode('utf-8'):
raise mosq_test.TestError(stde)
if __name__ == '__main__':
helps = "\nUse 'mosquitto_rr --help' to see usage.\n"
# Usage, version, ignore actual text though.
do_test(['--help'], None, 1)
do_test(['--version'], None, 1)
# Missing args
do_test(['-A'], "Error: -A argument given but no address specified.\n\n" + helps, 1)
do_test(['-e'], "Error: -e argument given but no response topic specified.\n\n" + helps, 1)
do_test(['-h'], "Error: -h argument given but no host specified.\n\n" + helps, 1)
do_test(['-i'], "Error: -i argument given but no id specified.\n\n" + helps, 1)
do_test(['-I'], "Error: -I argument given but no id prefix specified.\n\n" + helps, 1)
do_test(['-k'], "Error: -k argument given but no keepalive specified.\n\n" + helps, 1)
do_test(['-L'], "Error: -L argument given but no URL specified.\n\n" + helps, 1)
do_test(['-M'], "Error: -M argument given but max_inflight not specified.\n\n" + helps, 1)
do_test(['-m'], "Error: -m argument given but no message specified.\n\n" + helps, 1)
do_test(['-o'], "Error: -o argument given but no options file specified.\n\n" + helps, 1)
do_test(['-p'], "Error: -p argument given but no port specified.\n\n" + helps, 1)
do_test(['-P'], "Error: -P argument given but no password specified.\n\n" + helps, 1)
do_test(['-A'], "Error: -A argument given but no address specified.", 1)
do_test(['-e'], "Error: -e argument given but no response topic specified.", 1)
do_test(['-h'], "Error: -h argument given but no host specified.", 1)
do_test(['-i'], "Error: -i argument given but no id specified.", 1)
do_test(['-I'], "Error: -I argument given but no id prefix specified.", 1)
do_test(['-k'], "Error: -k argument given but no keepalive specified.", 1)
do_test(['-L'], "Error: -L argument given but no URL specified.", 1)
do_test(['-M'], "Error: -M argument given but max_inflight not specified.", 1)
do_test(['-m'], "Error: -m argument given but no message specified.", 1)
do_test(['-o'], "Error: -o argument given but no options file specified.", 1)
do_test(['-p'], "Error: -p argument given but no port specified.", 1)
do_test(['-P'], "Error: -P argument given but no password specified.", 1)
if mosq_test.check_features(["WITH_SOCKS"]):
do_test(['--proxy'], "Error: --proxy argument given but no proxy url specified.\n\n" + helps, 1)
do_test(['--proxy'], "Error: --proxy argument given but no proxy url specified.", 1)
else:
do_test(['--proxy'], "Error: Unknown option '--proxy'.\n" + helps, 1)
do_test(['-q'], "Error: -q argument given but no QoS specified.\n\n" + helps, 1)
do_test(['-t'], "Error: -t argument given but no topic specified.\n\n" + helps, 1)
do_test(['-u'], "Error: -u argument given but no username specified.\n\n" + helps, 1)
do_test(['--unix'], "Error: --unix argument given but no socket path specified.\n\n" + helps, 1)
do_test(['-V'], "Error: --protocol-version argument given but no version specified.\n\n" + helps, 1)
do_test(['--will-payload'], "Error: --will-payload argument given but no will payload specified.\n\n" + helps, 1)
do_test(['--will-qos'], "Error: --will-qos argument given but no will QoS specified.\n\n" + helps, 1)
do_test(['--will-topic'], "Error: --will-topic argument given but no will topic specified.\n\n" + helps, 1)
do_test(['-x'], "Error: -x argument given but no session expiry interval specified.\n\n" + helps, 1)
do_test(['-F'], "Error: -F argument given but no format specified.\n\n" + helps, 1)
do_test(['-o'], "Error: -o argument given but no options file specified.\n\n" + helps, 1)
do_test(['-W'], "Error: -W argument given but no timeout specified.\n\n" + helps, 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.\n" + helps, 1)
do_test(['--proxy'], "Error: Unknown option '--proxy'.", 1)
do_test(['-q'], "Error: -q argument given but no QoS specified.", 1)
do_test(['-t'], "Error: -t argument given but no topic specified.", 1)
do_test(['-u'], "Error: -u argument given but no username specified.", 1)
do_test(['--unix'], "Error: --unix argument given but no socket path specified.", 1)
do_test(['-V'], "Error: --protocol-version argument given but no version specified.", 1)
do_test(['--will-payload'], "Error: --will-payload argument given but no will payload specified.", 1)
do_test(['--will-qos'], "Error: --will-qos argument given but no will QoS specified.", 1)
do_test(['--will-topic'], "Error: --will-topic argument given but no will topic specified.", 1)
do_test(['-x'], "Error: -x argument given but no session expiry interval specified.", 1)
do_test(['-F'], "Error: -F argument given but no format specified.", 1)
do_test(['-o'], "Error: -o argument given but no options file specified.", 1)
do_test(['-W'], "Error: -W argument given but no timeout specified.", 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.", 1)
# No -t or -U
do_test([], "Error: All of topic, message, and response topic must be supplied.\n" + helps, 1)
do_test([], "Error: All of topic, message, and response topic must be supplied.", 1)
# Invalid combinations
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)
do_test(['-I', 'id-prefix', '-i', 'id'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.", 1)
do_test(['-I', 'id-prefix', '-i', 'id'], "Error: -i and -I argument cannot be used together.", 1)
# Invalid output format
do_test(['-F', '%'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%0'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%-'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%1'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%.'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%.1'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '%Z'], "Error: Invalid format specifier 'Z'.\n" + helps, 1)
do_test(['-F', '@'], "Error: Incomplete format specifier.\n" + helps, 1)
do_test(['-F', '\\'], "Error: Incomplete escape specifier.\n" + helps, 1)
do_test(['-F', '\\Z'], "Error: Invalid escape specifier 'Z'.\n" + helps, 1)
do_test(['-F', '%'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%0'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%-'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%1'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%.'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%.1'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '%Z'], "Error: Invalid format specifier 'Z'.", 1)
do_test(['-F', '@'], "Error: Incomplete format specifier.", 1)
do_test(['-F', '\\'], "Error: Incomplete escape specifier.", 1)
do_test(['-F', '\\Z'], "Error: Invalid escape specifier 'Z'.", 1)
# Invalid values
do_test(['-e', 'topic/+'], "Error: Invalid response topic 'topic/+', does it contain '+' or '#'?\n" + helps, 1)
do_test(['-k', '-1'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n" + helps, 1)
do_test(['-k', '65536'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n" + helps, 1)
do_test(['-M', '0'], "Error: Maximum inflight messages must be greater than 0.\n\n" + helps, 1)
do_test(['-p', '-1'], "Error: Invalid port given: -1\n" + helps, 1)
do_test(['-p', '65536'], "Error: Invalid port given: 65536\n" + helps, 1)
do_test(['-q', '-1'], "Error: Invalid QoS given: -1\n" + helps, 1)
do_test(['-q', '3'], "Error: Invalid QoS given: 3\n" + helps, 1)
do_test(['-L', 'invalid://'], "Error: Unsupported URL scheme.\n\n" + helps, 1)
do_test(['-L', 'mqtt://localhost'], "Error: Invalid URL for -L argument specified - topic missing.\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '-1'], "Error: Property value (-1) out of range for property request-problem-information.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '256'], "Error: Property value (256) out of range for property request-problem-information.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '-1'], "Error: Property value (-1) out of range for property receive-maximum.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '-1'], "Error: Property value (-1) out of range for property subscription-identifier.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '4294967296'], "Error: Property value (4294967296) out of range for property subscription-identifier.\n\n" + helps, 1)
do_test(['-V', '5', '-D', 'subscribe', 'topic-alias', '1'], "Error: topic-alias property not allowed for subscribe in --property argument.\n\n" + helps, 1)
do_test(['-V', '0'], "Error: Invalid protocol version argument given.\n\n" + helps, 1)
do_test(['-W', '0'], "Error: Invalid timeout \"0\".\n\n" + helps, 1)
do_test(['--will-qos', '-1'], "Error: Invalid will QoS -1.\n\n" + helps, 1)
do_test(['--will-qos', '3'], "Error: Invalid will QoS 3.\n\n" + helps, 1)
do_test(['--will-topic', '+'], "Error: Invalid will topic '+', does it contain '+' or '#'?\n" + helps, 1)
do_test(['-x', 'A'], "Error: session-expiry-interval not a number.\n\n" + helps, 1)
do_test(['-x', '-2'], "Error: session-expiry-interval out of range.\n\n" + helps, 1)
do_test(['-x', '4294967296'], "Error: session-expiry-interval out of range.\n\n" + helps, 1)
do_test(['--retain-handling', 'invalid'], "Error: Unknown value 'invalid' for --retain-handling.\n\n" + helps, 1)
do_test(['-e', 'topic/+'], "Error: Invalid response topic 'topic/+', does it contain '+' or '#'?", 1)
do_test(['-k', '-1'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.", 1)
do_test(['-k', '65536'], "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.", 1)
do_test(['-M', '0'], "Error: Maximum inflight messages must be greater than 0.", 1)
do_test(['-p', '-1'], "Error: Invalid port given: -1", 1)
do_test(['-p', '65536'], "Error: Invalid port given: 65536", 1)
do_test(['-q', '-1'], "Error: Invalid QoS given: -1", 1)
do_test(['-q', '3'], "Error: Invalid QoS given: 3", 1)
do_test(['-L', 'invalid://'], "Error: Unsupported URL scheme.", 1)
do_test(['-L', 'mqtt://localhost'], "Error: Invalid URL for -L argument specified - topic missing.", 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '-1'], "Error: Property value (-1) out of range for property request-problem-information.", 1)
do_test(['-V', '5', '-D', 'connect', 'request-problem-information', '256'], "Error: Property value (256) out of range for property request-problem-information.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '-1'], "Error: Property value (-1) out of range for property receive-maximum.", 1)
do_test(['-V', '5', '-D', 'connect', 'receive-maximum', '65536'], "Error: Property value (65536) out of range for property receive-maximum.", 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '-1'], "Error: Property value (-1) out of range for property session-expiry-interval.", 1)
do_test(['-V', '5', '-D', 'connect', 'session-expiry-interval', '4294967296'], "Error: Property value (4294967296) out of range for property session-expiry-interval.", 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '-1'], "Error: Property value (-1) out of range for property subscription-identifier.", 1)
do_test(['-V', '5', '-D', 'subscribe', 'subscription-identifier', '4294967296'], "Error: Property value (4294967296) out of range for property subscription-identifier.", 1)
do_test(['-V', '5', '-D', 'subscribe', 'topic-alias', '1'], "Error: topic-alias property not allowed for subscribe in --property argument.", 1)
do_test(['-V', '0'], "Error: Invalid protocol version argument given.", 1)
do_test(['-W', '0'], "Error: Invalid timeout \"0\".", 1)
do_test(['--will-qos', '-1'], "Error: Invalid will QoS -1.", 1)
do_test(['--will-qos', '3'], "Error: Invalid will QoS 3.", 1)
do_test(['--will-topic', '+'], "Error: Invalid will topic '+', does it contain '+' or '#'?", 1)
do_test(['-x', 'A'], "Error: session-expiry-interval not a number.", 1)
do_test(['-x', '-2'], "Error: session-expiry-interval out of range.", 1)
do_test(['-x', '4294967296'], "Error: session-expiry-interval out of range.", 1)
do_test(['--retain-handling', 'invalid'], "Error: Unknown value 'invalid' for --retain-handling.", 1)
# Mixed message types
do_test(['-m', 'message', '-f', 'file'], "Error: Only one type of message can be sent at once.\n\n" + helps, 1)
do_test(['-m', 'message', '-f', 'file'], "Error: Only one type of message can be sent at once.", 1)
# Unknown options
do_test(['--unknown'], "Error: Unknown option '--unknown'.\n" + helps, 1)
do_test(['-l'], "Error: Unknown option '-l'.\n" + helps, 1)
do_test(['-r'], "Error: Unknown option '-r'.\n" + helps, 1)
do_test(['--repeat'], "Error: Unknown option '--repeat'.\n" + helps, 1)
do_test(['--repeat-delay'], "Error: Unknown option '--repeat-delay'.\n" + helps, 1)
do_test(['--unknown'], "Error: Unknown option '--unknown'.", 1)
do_test(['-l'], "Error: Unknown option '-l'.", 1)
do_test(['-r'], "Error: Unknown option '-r'.", 1)
do_test(['--repeat'], "Error: Unknown option '--repeat'.", 1)
do_test(['--repeat-delay'], "Error: Unknown option '--repeat-delay'.", 1)
+1 -1
View File
@@ -61,7 +61,7 @@ def do_test(proto_ver):
print("rr not terminated")
rr_terminate_rc = 1
(stdo, stde) = rr.communicate()
if stdo.decode('utf-8') == payload + '\n':
if payload in stdo.decode('utf-8'):
rc = rr_terminate_rc
sock.close()
except mosq_test.TestError: