MXS-1354: Add JSON serialization of users

The users can now be dumped and loaded as JSON objects. This allows easier
parsing and handling of users while still retaining the possibility to
manually edit the output. Added tests for dumping and loading the JSON
form users.

Also fixed a deadlock in Users::remove() where the same lock was acquired
twice and a faulty test case where failed authentication was expected to
work.
This commit is contained in:
Markus Mäkelä
2017-08-15 15:16:50 +03:00
parent 253d6d211f
commit 3aebe0f91e
3 changed files with 136 additions and 3 deletions

View File

@ -56,7 +56,7 @@ static int test1()
ss_info_dassert(rv, "Fetch valid user must not return NULL");
rv = users_auth(users, "username", "newauth");
mxs_log_flush_sync();
ss_info_dassert(rv, "Fetch valid user must not return NULL");
ss_info_dassert(rv == 0, "Fetch invalid user must return NULL");
ss_dfprintf(stderr, "\t..done\nAdd another user");
rv = users_add(users, "username2", "authorisation2", ACCOUNT_ADMIN);
@ -66,6 +66,15 @@ static int test1()
rv = users_delete(users, "username");
mxs_log_flush_sync();
ss_info_dassert(rv, "Should delete just one user");
ss_dfprintf(stderr, "\t..done\nDump users table.");
json_t* dump = users_to_json(users);
ss_info_dassert(dump, "Users should be dumped");
USERS* loaded_users = users_from_json(dump);
ss_info_dassert(dump, "Users should be loaded");
rv = users_auth(loaded_users, "username2", "authorisation2");
ss_info_dassert(rv, "Loaded users should contain users");
ss_dfprintf(stderr, "\t..done\nFree user table.");
users_free(users);
mxs_log_flush_sync();