mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
confserver: Send an error response if JSON request is malformatted
This commit is contained in:
parent
ec4c75b692
commit
2f2f0fbcbd
@ -79,7 +79,13 @@ def run_server(kconfig, sdkconfig, default_version=MAX_PROTOCOL_VERSION):
|
||||
line = sys.stdin.readline()
|
||||
if not line:
|
||||
break
|
||||
req = json.loads(line)
|
||||
try:
|
||||
req = json.loads(line)
|
||||
except ValueError as e: # json module throws JSONDecodeError (sublcass of ValueError) on Py3 but ValueError on Py2
|
||||
response = {"version": default_version, "error": ["JSON formatting error: %s" % e]}
|
||||
json.dump(response, sys.stdout)
|
||||
print("\n")
|
||||
continue
|
||||
before = confgen.get_json_values(config)
|
||||
before_ranges = get_ranges(config)
|
||||
before_visible = get_visible(config)
|
||||
|
@ -64,6 +64,8 @@ def main():
|
||||
|
||||
test_load_save(p, temp_sdkconfig_path)
|
||||
|
||||
test_invalid_json(p)
|
||||
|
||||
print("Done. All passed.")
|
||||
|
||||
finally:
|
||||
@ -143,5 +145,21 @@ def test_load_save(p, temp_sdkconfig_path):
|
||||
assert len(load_result["ranges"]) > 0
|
||||
|
||||
|
||||
def test_invalid_json(p):
|
||||
print("Testing invalid JSON formatting...")
|
||||
|
||||
bad_escaping = r'{ "version" : 2, "load" : "c:\some\path\not\escaped\as\json" }'
|
||||
p.send("%s\n" % bad_escaping)
|
||||
readback = expect_json(p)
|
||||
print(readback)
|
||||
assert "json" in readback["error"][0].lower()
|
||||
|
||||
not_really_json = 'Hello world!!'
|
||||
p.send("%s\n" % not_really_json)
|
||||
readback = expect_json(p)
|
||||
print(readback)
|
||||
assert "json" in readback["error"][0].lower()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user