Fix JSON output from --json (#4134)

This commit is contained in:
Mitchell Grenier 2018-02-16 15:41:44 -08:00 committed by GitHub
parent f89392bdb4
commit 94b48ea87f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -137,7 +137,6 @@ void jsonPrint(const QueryData& q) {
std::string row_string;
if (serializeRowJSON(q[i], row_string).ok()) {
row_string.pop_back();
printf(" %s", row_string.c_str());
if (i < q.size() - 1) {
printf(",\n");

View File

@ -181,6 +181,24 @@ class OsqueryiTest(unittest.TestCase):
result = self.osqueryi.run_command(command)
pass
def test_json_output(self):
'''Test that the output of --json is valid json'''
proc = test_base.TimeoutRunner([
self.binary,
"select 0",
"--disable_extensions",
"--json",
],
SHELL_TIMEOUT
)
if os.name == "nt":
self.assertEqual(proc.stdout, "[\r\n {\"0\":\"0\"}\r\n]\r\n")
else:
self.assertEqual(proc.stdout, "[\n {\"0\":\"0\"}\n]\n")
print(proc.stdout)
print(proc.stderr)
self.assertEqual(proc.proc.poll(), 0)
@test_base.flaky
def test_time(self):
'''Demonstrating basic usage of OsqueryWrapper with the time table'''