Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lavabit/magma.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpadkins <jacobpadkins@gmail.com>2017-04-08 03:51:06 +0300
committerjpadkins <jacobpadkins@gmail.com>2017-04-08 03:51:06 +0300
commit61a3312c43620993b8910dd3d5a178c5f6e394da (patch)
treed5465a6542fb1ab674514eda8fb6bd7306662709 /check/magma
parente2796089eddcff7e67c2427ff29c0ffebbde6174 (diff)
Dirty Commit: Progress on camel basic test.
Diffstat (limited to 'check/magma')
-rw-r--r--check/magma/servers/camel/camel_check_network.c412
1 files changed, 315 insertions, 97 deletions
diff --git a/check/magma/servers/camel/camel_check_network.c b/check/magma/servers/camel/camel_check_network.c
index 3a402c80..46cad72e 100644
--- a/check/magma/servers/camel/camel_check_network.c
+++ b/check/magma/servers/camel/camel_check_network.c
@@ -82,7 +82,7 @@ stringer_t * check_camel_json_read(client_t *client, size_t length) {
bool_t check_camel_json_write(client_t *client, stringer_t *json, stringer_t *cookie, bool_t keep_alive) {
chr_t *message = "POST /portal/camel HTTP/1.1\r\nHost: localhost:10000\r\nAccept: */*\r\nContent-Length: %u\r\n" \
- "Content-Type: application/x-www-form-urlencoded\r\nCookie: portal=%.*s;\r\nConnection: %s\r\n\r\n%.*s";
+ "Content-Type: application/x-www-form-urlencoded\r\nCookie: portal=%.*s;\r\nConnection: %s\r\n\r\n%.*s\r\n\r\n";
if (client_print(client, message, st_length_get(json), st_length_int(cookie), (cookie ? st_char_get(cookie) : ""),
(keep_alive ? "keep-alive" : "close"), st_length_int(json), st_char_get(json)) != (ns_length_get(message) - 10 +
@@ -111,7 +111,7 @@ bool_t check_camel_login(client_t *client, uint32_t id, stringer_t *user, string
json_error_t json_err;
size_t content_length = 0;
- json_t *parsed_json = NULL, *result = NULL, *session = NULL;
+ json_t *json_root = NULL, *json_result = NULL, *json_key = NULL;
uint32_t length = 62 + ns_length_get(user) + ns_length_get(pass) + uint32_digits(id);
stringer_t *json = NULL, *message = NULLER("POST /portal/camel HTTP/1.1\r\nHost: localhost:10000\r\nAccept: */*\r\n" \
"Content-Length: %u\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"id\":%u,\"method\":\"auth\"," \
@@ -124,28 +124,23 @@ bool_t check_camel_login(client_t *client, uint32_t id, stringer_t *user, string
return false;
}
- else if (!(parsed_json = json_loads_d(st_char_get(json), 0, &json_err)) || !(result = json_object_get_d(parsed_json, "result")) ||
- !(session = json_object_get_d(result, "session"))) {
+ else if (!(json_root = json_loads_d(st_char_get(json), 0, &json_err)) || !(json_result = json_object_get_d(json_root, "result")) ||
+ !(json_key = json_object_get_d(json_result, "session"))) {
+
+ st_free(json);
+ mm_cleanup(json_root, json_result, json_key);
- st_cleanup(json);
- if (result) mm_free(result);
- if (session) mm_free(session);
- if (parsed_json) mm_free(parsed_json);
return false;
}
- else if (cookie && st_sprint(cookie, "%s", json_string_value_d(session)) == -1) {
+ else if (cookie && st_sprint(cookie, "%s", json_string_value_d(json_key)) == -1) {
st_free(json);
- mm_free(result);
- mm_free(session);
- mm_free(parsed_json);
+ mm_cleanup(json_root, json_result, json_key);
return false;
}
st_free(json);
- mm_free(result);
- mm_free(session);
- mm_free(parsed_json);
+ mm_cleanup(json_root, json_result, json_key);
return true;
}
@@ -172,68 +167,73 @@ bool_t check_camel_auth_sthread(bool_t secure, stringer_t *errmsg) {
bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
+ json_error_t json_err;
client_t *client = NULL;
- uint32_t content_length = 0, folderid = 0, folderid_buff = 0;
- stringer_t *cookie = MANAGEDBUF(1024), *json = NULL, *commands[] = {
- NULLER("{\"id\":2,\"method\":\"config.edit\",\"params\":{\"key\":\"value\"}}"),
- NULLER("{\"id\":3,\"method\":\"config.load\"}"),
- NULLER("{\"id\":4,\"method\":\"config.edit\",\"params\":{\"key\":null}}"),
- NULLER("{\"id\":5,\"method\":\"config.load\"}"),
- NULLER("{\"id\":6,\"method\":\"config.edit\",\"params\":{\"key.3943\":\"18346\"}"),
- NULLER("{\"id\":7,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"Flight Crew\"}}"),
- NULLER("{\"id\":8,\"method\":\"folders.list\",\"params\":{\"context\":\"contacts\"}}"),
- NULLER("{\"id\":9,\"method\":\"contacts.add\",\"params\":{\"folderID\":37, \"contact\":{\"name\":\"Jenna\", \"email\":\"jenna@jameson.com\"}}}"),
- NULLER("{\"id\":10,\"method\":\"contacts.copy\",\"params\":{\"sourceFolderID\":37, \"targetFolderID\":37, \"contactID\": 1 }}"),
- NULLER("{\"id\":11,\"method\":\"contacts.list\",\"params\":{\"folderID\":37 }}"),
- NULLER("{\"id\":12,\"method\":\"contacts.edit\",\"params\":{\"folderID\":37, \"contactID\":1, \"contact\":{\"name\":\"Jenna Marie Massoli\", \"email\":\"jenna+private-chats@jameson.com\"}}}"),
- NULLER("{\"id\":13,\"method\":\"contacts.load\",\"params\":{\"folderID\":37, \"contactID\":2 }}"),
- NULLER("{\"id\":14,\"method\":\"contacts.edit\",\"params\":{\"folderID\":37, \"contactID\":1, \"contact\":{\"name\":\"Jenna\", \"email\":\"jenna@jameson.com\", \"phone\":\"2145551212\", \"notes\":\"The Tuesday night hottie!\"}}}"),
- NULLER("{\"id\":15,\"method\":\"contacts.load\",\"params\":{\"folderID\":37, \"contactID\":2 }}"),
- NULLER("{\"id\":16,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"Lovers\"}}"),
- NULLER("{\"id\":17,\"method\":\"contacts.move\",\"params\":{ \"contactID\":1, \"sourceFolderID\":37, \"targetFolderID\": }}"),
- NULLER("{\"id\":18,\"method\":\"contacts.list\",\"params\":{\"folderID\":37 }}"),
- NULLER("{\"id\":19,\"method\":\"contacts.list\",\"params\":{\"folderID\": }}"),
- NULLER("{\"id\":20,\"method\":\"contacts.remove\",\"params\":{\"folderID\":37, \"contactID\":1 }}"),
- NULLER("{\"id\":21,\"method\":\"contacts.remove\",\"params\":{\"folderID\":, \"contactID\": }}"),
- NULLER("{\"id\":22,\"method\":\"contacts.list\",\"params\":{\"folderID\": }}"),
- NULLER("{\"id\":23,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":37 }}"),
- NULLER("{\"id\":24,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\": }}"),
- NULLER("{\"id\":25,\"method\":\"cookies\"}"),
- NULLER("{\"id\":26,\"method\":\"alert.list\"}"),
- NULLER("{\"id\":27,\"method\":\"alert.acknowledge\",\"params\":[1,7,13]}"),
- NULLER("{\"id\":28,\"method\":\"alert.list\"}"),
- NULLER("{\"id\":29,\"method\":\"folders.list\",\"params\":{\"context\":\"mail\"}}"),
- NULLER("{\"id\":30,\"method\":\"folders.list\",\"params\":{\"context\":\"settings\"}}"),
- NULLER("{\"id\":31,\"method\":\"folders.list\",\"params\":{\"context\":\"help\"}}"),
- NULLER("{\"id\":32,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Camel\"}}"),
- NULLER("{\"id\":33,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"Toe\"}}"),
- NULLER("{\"id\":34,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"Rocks\"}}"),
- NULLER("{\"id\":35,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"Dames.Rock\"}}"),
- NULLER("{\"id\":36,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"Clams\"}}"),
- NULLER("{\"id\":37,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":38,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":39,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":40,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":41,\"method\":\"aliases\"}"),
- NULLER("{\"id\":42,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Duplicate\"}}"),
- NULLER("{\"id\":43,\"method\":\"messages.copy\",\"params\":{\"messageIDs\": [], \"sourceFolderID\":1, \"targetFolderID\": }}"),
- NULLER("{\"id\":44,\"method\":\"messages.copy\",\"params\":{\"messageIDs\": [], \"sourceFolderID\":1, \"targetFolderID\": }}"),
- NULLER("{\"id\":45,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":46,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Duplicate\"}}"),
- NULLER("{\"id\":47,\"method\":\"messages.load\",\"params\":{\"messageID\": , \"folderID\":1, \"sections\": [\"meta\", \"source\", \"security\", \"server\", \"header\", \"body\", \"attachments\" ]}}"),
- NULLER("{\"id\":48,\"method\":\"messages.copy\",\"params\":{\"messageIDs\": [], \"sourceFolderID\":1, \"targetFolderID\": }}"),
- NULLER("{\"id\":49,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":50,\"method\":\"messages.flag\",\"params\":{\"action\":\"add\", \"flags\":[\"flagged\"], \"messageIDs\": [], \"folderID\":1 }}"),
- NULLER("{\"id\":51,\"method\":\"messages.tags\",\"params\":{\"action\":\"add\", \"tags\":[\"girlie\",\"girlie-6169\"], \"messageIDs\": [], \"folderID\":1 }}"),
- NULLER("{\"id\":52,\"method\":\"messages.flag\",\"params\":{\"action\":\"list\", \"messageIDs\": [], \"folderID\":1 }}"),
- NULLER("{\"id\":53,\"method\":\"messages.tags\",\"params\":{\"action\":\"list\", \"messageIDs\": [], \"folderID\":1 }}"),
- NULLER("{\"id\":54,\"method\":\"messages.list\",\"params\":{\"folderID\":1 }}"),
- NULLER("{\"id\":55,\"method\":\"folders.tags\",\"params\":{\"context\":\"mail\",\"folderID\":1 }}"),
- NULLER("{\"id\":56,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Mover\"}}"),
- NULLER("{\"id\":57,\"method\":\"messages.move\",\"params\":{\"messageIDs\": [], \"sourceFolderID\": 1, \"targetFolderID\": }}"),
- NULLER("{\"id\":58,\"method\":\"messages.remove\",\"params\":{\"folderID\":,\"messageIDs\":[]}}"),
- NULLER("{\"id\":59,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\": }}"),
- NULLER("{\"id\":60,\"method\":\"logout\"}")
+ const chr_t *json_value = NULL;
+ uint32_t content_length = 0;//, folderids[];
+ json_t *json_objs[4] = { NULL, NULL, NULL, NULL };
+ chr_t *choices = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ stringer_t *cookie = MANAGEDBUF(1024), *command = NULL, *rand_strs[2] = { NULL, NULL }, *json = NULL,
+ *commands[] = {
+ PLACER("{\"id\":2,\"method\":\"config.edit\",\"params\":{\"%.*s\":\"%.*s\"}}", 68),
+ PLACER("{\"id\":3,\"method\":\"config.load\"}", 37),
+ PLACER("{\"id\":4,\"method\":\"config.edit\",\"params\":{\"%.*s\":null}}", 64),
+ PLACER("{\"id\":5,\"method\":\"config.load\"}", 37),
+ PLACER("{\"id\":6,\"method\":\"config.edit\",\"params\":{\"%.*s\":\"%.*s\"}}", 68),
+ PLACER("{\"id\":7,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"%.*s\"}}", 93),
+ PLACER("{\"id\":8,\"method\":\"folders.list\",\"params\":{\"context\":\"contacts\"}}", 76),
+ PLACER("{\"id\":9,\"method\":\"contacts.add\",\"params\":{\"folderID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\"}}}", 120),
+ PLACER("{\"id\":10,\"method\":\"contacts.copy\",\"params\":{\"sourceFolderID\":%u, \"targetFolderID\":%u, \"contactID\":%u}}", 116),
+ PLACER("{\"id\":11,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69),
+ PLACER("{\"id\":12,\"method\":\"contacts.edit\",\"params\":{\"folderID\":%u, \"contactID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\"}}}", 140),
+ PLACER("{\"id\":13,\"method\":\"contacts.load\",\"params\":{\"folderID\":%u, \"contactID\":%u }}", 88),
+ PLACER("{\"id\":14,\"method\":\"contacts.edit\",\"params\":{\"folderID\":%u, \"contactID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\", \"phone\":\"%u\", \"notes\":\"%.*s\"}}}", 178),
+ PLACER("{\"id\":15,\"method\":\"contacts.load\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", 87),
+ PLACER("{\"id\":16,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"%.*s\"}}", 94),
+ PLACER("{\"id\":17,\"method\":\"contacts.move\",\"params\":{ \"contactID\":%u, \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 117),
+ PLACER("{\"id\":18,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69),
+ PLACER("{\"id\":19,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69),
+ PLACER("{\"id\":20,\"method\":\"contacts.remove\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", 89),
+ PLACER("{\"id\":21,\"method\":\"contacts.remove\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", 89),
+ PLACER("{\"id\":22,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69),
+ PLACER("{\"id\":23,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":%u}}", 95),
+ PLACER("{\"id\":24,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":%u}}", 95),
+ PLACER("{\"id\":25,\"method\":\"cookies\"}", 34),
+ PLACER("{\"id\":26,\"method\":\"alert.list\"}", 37),
+ PLACER("{\"id\":27,\"method\":\"alert.acknowledge\",\"params\":[1,7,13]}", 64),
+ PLACER("{\"id\":28,\"method\":\"alert.list\"}", 37),
+ PLACER("{\"id\":29,\"method\":\"folders.list\",\"params\":{\"context\":\"mail\"}}", 73),
+ PLACER("{\"id\":30,\"method\":\"folders.list\",\"params\":{\"context\":\"settings\"}}", 77),
+ PLACER("{\"id\":31,\"method\":\"folders.list\",\"params\":{\"context\":\"help\"}}", 73),
+ PLACER("{\"id\":32,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", 90),
+ PLACER("{\"id\":33,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"%.*s\"}}", 104),
+ PLACER("{\"id\":34,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"%.*s\"}}", 104),
+ PLACER("{\"id\":35,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"%.*s\"}}", 107),
+ PLACER("{\"id\":36,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"%.*s\"}}", 107),
+ PLACER("{\"id\":37,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":38,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":39,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":40,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":41,\"method\":\"aliases\"}", 34),
+ PLACER("{\"id\":42,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", 90),
+ PLACER("{\"id\":43,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119),
+ PLACER("{\"id\":44,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119),
+ PLACER("{\"id\":45,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":46,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", 90),
+ PLACER("{\"id\":47,\"method\":\"messages.load\",\"params\":{\"messageID\":%u, \"folderID\":%u, \"sections\": [\"meta\", \"source\", \"security\", \"server\", \"header\", \"body\", \"attachments\"]}}", 190),
+ PLACER("{\"id\":48,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119),
+ PLACER("{\"id\":49,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":50,\"method\":\"messages.flag\",\"params\":{\"action\":\"add\", \"flags\":[\"flagged\"], \"messageIDs\": [%u], \"folderID\":%u}}", 136),
+ PLACER("{\"id\":51,\"method\":\"messages.tags\",\"params\":{\"action\":\"add\", \"tags\":[\"girlie\",\"girlie-6169\"], \"messageIDs\": [%u], \"folderID\":%u}}", 150),
+ PLACER("{\"id\":52,\"method\":\"messages.flag\",\"params\":{\"action\":\"list\", \"messageIDs\":[%u], \"folderID\":%u}}", 111),
+ PLACER("{\"id\":53,\"method\":\"messages.tags\",\"params\":{\"action\":\"list\", \"messageIDs\":[%u], \"folderID\":%u}}", 111),
+ PLACER("{\"id\":54,\"method\":\"messages.list\",\"params\":{\"folderID\":%u}}", 69),
+ PLACER("{\"id\":55,\"method\":\"folders.tags\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 89),
+ PLACER("{\"id\":56,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Mover\"}}", 91),
+ PLACER("{\"id\":57,\"method\":\"messages.move\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119),
+ PLACER("{\"id\":58,\"method\":\"messages.remove\",\"params\":{\"folderID\":%u,\"messageIDs\":[%u]}}", 91),
+ PLACER("{\"id\":59,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91),
+ PLACER("{\"id\":60,\"method\":\"logout\"}", 33)
};
if (!(client = check_camel_connect(secure))) {
@@ -246,21 +246,230 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
return false;
}
- // Test config.edit { key = "key", value = "value" }
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Test config.edit : commands[0]
+ // JSON Command : {"id":2,"method":"config.edit","params":{<rand_strs[0]>:<rand_strs[1]}}"
+ // Expected Response : {"jsonrpc":"2.0","result":{"config.edit":"success"},"id":2}
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // Generate the random inputs for "key" and "value".
+ if (!(rand_strs[0] = rand_choices(choices, 64, NULL)) || !(rand_strs[1] = rand_choices(choices, 64, NULL))) {
+
+ st_sprint(errmsg, "Failed to create random inputs. { command = \"%.*s\" }", st_length_int(commands[0]), st_char_get(commands[0]));
+ st_cleanup(rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Construct the command string.
+ else if (!(command = st_alloc(st_length_get(commands[0]) - 8 + st_length_get(rand_strs[0]) + st_length_get(rand_strs[1]))) ||
+ !(st_quick(command, st_char_get(commands[0]), st_length_int(rand_strs[0]), st_char_get(rand_strs[0]), st_length_int(rand_strs[1]),
+ st_char_get(rand_strs[1])))) {
+
+ st_sprint(errmsg, "Failed to create command string. { command = \"%.*s\" }", st_length_int(command), st_char_get(command));
+ st_cleanup(command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Submit the command and check the status of the response.
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, command, cookie, true) ||
+ client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) ||
+ !(json = check_camel_json_read(client, content_length))) {
+
+ st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", st_length_int(command), st_char_get(command));
+ st_cleanup(json, command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Parse the returned JSON.
+ else if (!(json_objs[0] = json_loads_d(st_char_get(json), 0, &json_err)) || !(json_objs[1] = json_object_get_d(json_objs[0], "result")) ||
+ !(json_objs[2] = json_object_get_d(json_objs[1], "config.edit")) || !(json_value = json_string_value_d(json_objs[2]))) {
+
+ st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command),
+ st_length_int(json), st_char_get(json));
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+ st_cleanup(json, command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Check if the returned JSON is correct.
+ else if (st_cmp_cs_eq(PLACER((chr_t*)json_value, ns_length_get(json_value)), PLACER("success", 7))) {
+
+ st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command),
+ st_length_int(json), st_char_get(json));
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+ st_cleanup(json, command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Clean up before the next check.
+ st_cleanup(json, command);
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+
+ json = NULL;
+ command = NULL;
+
+ for (size_t i = 0; i < sizeof(json_objs)/sizeof(json_t *); i++) {
+ json_objs[i] = NULL;
+ }
+
+ client_close(client);
+ client = NULL;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Test config.edit : commands[1]
+ // JSON Command : {"id":3,"method":"config.load"}
+ // Expected Response : {"jsonrpc":"2.0","result":{<rand_strs[0]>:{"value":<rand_strs[1]>, "flags":[]}, ...}, "id":3}
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // Submit the command and check the status of the response.
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[1], cookie, true) ||
+ client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) ||
+ !(json = check_camel_json_read(client, content_length))) {
+
+ st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", st_length_int(commands[1]), st_char_get(commands[1]));
+ st_cleanup(json, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Parse the returned JSON.
+ else if (!(json_objs[0] = json_loads_d(st_char_get(json), 0, &json_err)) || !(json_objs[1] = json_object_get_d(json_objs[0], "result")) ||
+ !(json_objs[2] = json_object_get_d(json_objs[1], st_char_get(rand_strs[0]))) ||
+ !(json_objs[3] = json_object_get_d(json_objs[2], "value")) ||
+ !(json_value = json_string_value_d(json_objs[3]))) {
+
+ st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(commands[0]), st_char_get(commands[0]),
+ st_length_int(json), st_char_get(json));
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+ st_cleanup(json, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Check if the returned JSON is correct.
+ else if (st_cmp_cs_eq(PLACER((chr_t*)json_value, ns_length_get(json_value)), rand_strs[1])) {
+
+ st_sprint(errmsg, "Failed to return a successful JSON response. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(commands[0]), st_char_get(commands[0]),
+ st_length_int(json), st_char_get(json));
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+ st_cleanup(json, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Clean up before the next check.
+ st_cleanup(json, command, rand_strs[1]);
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+
+ json = NULL;
+ command = NULL;
+ rand_strs[1] = NULL;
+
+ for (size_t i = 0; i < sizeof(json_objs)/sizeof(json_t *); i++) {
+ json_objs[i] = NULL;
+ }
+
+ client_close(client);
+ client = NULL;
+
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Test config.edit : commands[2]
+ // JSON Command : {"id":4,"method":"config.edit","params":{<rand_strs[0]>:null}}"
+ // Expected Response : {"jsonrpc":"2.0","result":{"config.edit":"success"},"id":4}
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // Construct the command string.
+ if (!(command = st_alloc(st_length_get(commands[0]) - 4 + st_length_get(rand_strs[0]))) || !(st_quick(command, st_char_get(commands[0]),
+ st_length_int(rand_strs[0]), st_char_get(rand_strs[0])))) {
+
+ st_sprint(errmsg, "Failed to create command string. { command = \"%.*s\" }", st_length_int(command), st_char_get(command));
+ st_cleanup(command, rand_strs[0]);
+ client_close(client);
+ return false;
+ }
+
+ // Submit the command and check the status of the response.
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, command, cookie, true) ||
+ client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) ||
+ !(json = check_camel_json_read(client, content_length))) {
+
+ st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", st_length_int(command), st_char_get(command));
+ st_cleanup(json, command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Parse the returned JSON.
+ else if (!(json_objs[0] = json_loads_d(st_char_get(json), 0, &json_err)) || !(json_objs[1] = json_object_get_d(json_objs[0], "result")) ||
+ !(json_objs[2] = json_object_get_d(json_objs[1], "config.edit")) || !(json_value = json_string_value_d(json_objs[2]))) {
+
+ st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command),
+ st_length_int(json), st_char_get(json));
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+ st_cleanup(json, command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Check if the returned JSON is correct.
+ else if (st_cmp_cs_eq(PLACER((chr_t*)json_value, ns_length_get(json_value)), PLACER("success", 7))) {
+
+ st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command),
+ st_length_int(json), st_char_get(json));
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+ st_cleanup(json, command, rand_strs[0], rand_strs[1]);
+ client_close(client);
+ return false;
+ }
+
+ // Clean up before the next check.
+ st_cleanup(json, command, rand_strs[0]);
+ mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]);
+
+ json = NULL;
+ command = NULL;
+ rand_strs[0] = NULL;
+
+ for (size_t i = 0; i < sizeof(json_objs)/sizeof(json_t *); i++) {
+ json_objs[i] = NULL;
+ }
+
+ client_close(client);
+ client = NULL;
+
+ //
+ return true;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Test config.load (commands[1] "{\"id\":3,\"method\":\"config.load\"}"
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /*
if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[0], cookie, true) ||
client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) ||
!(json = check_camel_json_read(client, content_length))) {
- st_sprint(errmsg, "Failed to return successful response after config.edit.");
+ st_sprint(errmsg, "Failed to return a successful response. { command = 0 }");
+ st_cleanup(rand_strs[0], rand_strs[1]);
client_close(client);
return false;
}
+ */
- st_free(json);
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ /*
// Test config.load
- if (!check_camel_json_write(client, commands[1], cookie, true) || client_status(client) != 1 || !check_camel_status(client) ||
- !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[1], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) ||
+ !(json = check_camel_json_read(client, content_length))) {
st_sprint(errmsg, "Failed to return successful response after config.load.");
client_close(client);
@@ -269,9 +478,9 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
st_free(json);
- // Test config.edit { key = "key", "value" = null }
- if (!check_camel_json_write(client, commands[2], cookie, true) || client_status(client) != 1 || !check_camel_status(client) ||
- !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
+ // Test config.edit { key: "key", value: null }
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[2], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
st_sprint(errmsg, "Failed to return successful response after config.edit.");
client_close(client);
@@ -281,8 +490,8 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
st_free(json);
// Test config.load
- if (!check_camel_json_write(client, commands[3], cookie, true) || client_status(client) != 1 || !check_camel_status(client) ||
- !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[3], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
st_sprint(errmsg, "Failed to return successful response after config.load.");
client_close(client);
@@ -291,9 +500,9 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
st_free(json);
- // Test config.edit { key = "key.3943", value = "18346" }
- if (!check_camel_json_write(client, commands[4], cookie, true) || client_status(client) != 1 || !check_camel_status(client) ||
- !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
+ // Test config.edit { key: "key.3943", value: "18346" }
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[4], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
st_sprint(errmsg, "Failed to return successful response after config.edit.");
client_close(client);
@@ -302,9 +511,9 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
st_free(json);
- // Test folders.add { context = "contacts", name = "Flight Crew" }
- if (!check_camel_json_write(client, commands[5], cookie, true) || client_status(client) != 1 || !check_camel_status(client) ||
- !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length)) ||
+ // Test folders.add { context: "contacts", name: "Flight Crew" }
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[5], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length)) ||
json_unpack_d(json, "{s:{s:i}}", "result", "folderID", &folderid)) {
st_sprint(errmsg, "Failed to return successful response after folders.add.");
@@ -314,9 +523,9 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
st_free(json);
- // Test folders.list { context = "contacts" }
- if (!check_camel_json_write(client, commands[6], cookie, true) || client_status(client) != 1 || !check_camel_status(client) ||
- !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length)) ||
+ // Test folders.list { context: "contacts" }
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[6], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length)) ||
json_unpack_d(json, "{s:[{s:i}]}", "result", "folderID", &folderid_buff) || folderid != folderid_buff) {
st_sprint(errmsg, "Failed to return successful response after folders.list.");
@@ -325,7 +534,16 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) {
}
st_free(json);
- client_close(client);
- return true;
+ // Test contacts.add { folderID: %u, contact: { name: "Jenna", email: "jenna@jameson.com" }}
+ if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[7], cookie, true) || client_status(client) != 1 ||
+ !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) {
+
+ st_sprint(errmsg, "Failed to return successful response after contacts.add.");
+ client_close(client);
+ return false;
+ }
+
+ st_free(json);
+ */
}