diff options
author | jpadkins <jacobpadkins@gmail.com> | 2017-04-03 20:00:55 +0300 |
---|---|---|
committer | jpadkins <jacobpadkins@gmail.com> | 2017-04-03 20:00:55 +0300 |
commit | 629c94ff079176dd7f124e2ba519b72ce1ca6361 (patch) | |
tree | 1d237942f1779b8287196aa3a3eb32e9978e6047 /check/magma | |
parent | 8a70541a696f5c41f6f21758879e43ddefb13290 (diff) |
Adding more camelface tests
Diffstat (limited to 'check/magma')
-rw-r--r-- | check/magma/servers/camel/camel_check.h | 5 | ||||
-rw-r--r-- | check/magma/servers/camel/camel_check_network.c | 61 |
2 files changed, 44 insertions, 22 deletions
diff --git a/check/magma/servers/camel/camel_check.h b/check/magma/servers/camel/camel_check.h index 50322c4f..fa4495dd 100644 --- a/check/magma/servers/camel/camel_check.h +++ b/check/magma/servers/camel/camel_check.h @@ -8,8 +8,9 @@ #define CAMEL_CHECK_H /// camel_check_network.c -bool_t check_camel_response_status(client_t *client); -bool_t check_camel_response_read_end(client_t *client); +bool_t check_camel_status(client_t *client); +bool_t check_camel_read_end(client_t *client); +bool_t check_camel_login(client_t *client, uint32_t id, chr_t *user, chr_t *pass, stringer_t *cookie); bool_t check_camel_login_sthread(client_t *client, stringer_t *errmsg); /// pop_check.c diff --git a/check/magma/servers/camel/camel_check_network.c b/check/magma/servers/camel/camel_check_network.c index 37f1e397..7e69e7dc 100644 --- a/check/magma/servers/camel/camel_check_network.c +++ b/check/magma/servers/camel/camel_check_network.c @@ -11,14 +11,15 @@ * @brief Reads lines from the client until the end of the HTTP response is reached. * * @param client A client_t* to read lines from. An HTTP request should have been submitted - * from the client before this function is called. + * from the client before this function is called. + * * @return True if the end of the HTTP response was reached, false if client_read_line reads - * a 0 length line before the last line is reached. + * a 0 length line before the last line is reached. */ -bool_t check_camel_response_read_end(client_t *client) { +bool_t check_camel_read_end(client_t *client) { while (client_read_line(client) >= 0) { - if (st_cmp_cs_starts(&(client->line), NULLER("\r\n")) == 0) return true; + if (st_cmp_cs_starts(&(client->line), NULLER("{\"jsonrpc\":\"2.0\",")) == 0) return true; } return false; } @@ -27,10 +28,11 @@ bool_t check_camel_response_read_end(client_t *client) { * @brief Reads lines from the client until the HTTP response status code is found, which it checks. * * @param client A client_t* to read lines from. An HTTP request should have been submitted - * from the client before this function is called. + * from the client before this function is called. + * * @return True if the HTTP status code of the response begins with a '2', false otherwise. */ -bool_t check_camel_response_status(client_t *client) { +bool_t check_camel_status(client_t *client) { while (st_cmp_cs_starts(&(client->line), NULLER("HTTP/1.1"))) { if (client_read_line(client) <= 0) return false; @@ -39,26 +41,45 @@ bool_t check_camel_response_status(client_t *client) { return ((*(pl_char_get(client->line)+9) == '2') ? true : false); } -bool_t check_camel_login_sthread(client_t *client, stringer_t *errmsg) { +/** + * @brief Submits an auth request to /portal/camel, setting *cookie to the session cookie in the response. + * + * @param client should be connected to an HTTP server. + * @param id the value to place in the "id" field of the json request. + * @param user the username of the account to issue the auth request for. + * @param pass the password of the account to issue the auth request for. + * @param cookie if not NULL, will be set to the value of Set-Cookie in the response. + * + * @return True if the request was successful, false otherwise. + */ +bool_t check_camel_login(client_t *client, uint32_t id, chr_t *user, chr_t *pass, stringer_t *cookie) { - chr_t *message = \ - "POST /json HTTP/1.1\r\n"\ - "Host: localhost:10000\r\n"\ - "Accept: */*\r\n"\ - "Content-Length: 79\r\n"\ - "Content-Type: application/x-www-form-urlencoded\r\n\r\n"\ - "{\"id\":1,\"method\":\"auth\",\"params\":{\"username\":\"princess\",\"password\":\"password\"}}\r\n"; + uint32_t content_length = 62 + ns_length_get(user) + ns_length_get(pass) + uint32_digits(id); + chr_t *message = "POST /portal/camel HTTP/1.1\r\n" \ + "Host: localhost:10000\r\n" \ + "Accept: */*\r\n" \ + "Content-Length: %u\r\n" \ + "Content-Type: application/x-www-form-urlencoded\r\n" \ + "\r\n" + "{\"id\":%u,\"method\":\"auth\",\"params\":{\"username\":\"%s\",\"password\":\"%s\"}}\r\n" + "\r\n"; - if (client_write(client, PLACER(message, ns_length_get(message))) != ns_length_get(message) || client_status(client) != 1) { + if (client_print(client, message, content_length, id, user, pass) != (ns_length_get(message) + uint32_digits(id) + ns_length_get(user) + ns_length_get(pass)) || client_status(client) != 1 || !check_camel_status(client) || + !check_camel_read_end(client)) { - st_sprint(errmsg, "The client failed to have a successful status after printing the request."); - client_close(client); return false; } - else if (!check_camel_response_status(client) || !check_camel_response_read_end(client)) { - st_sprint(errmsg, "Failed to return successful response to login request."); - client_close(client); + chr_t *foo = pl_char_get(client->line); + (void)foo; + return true; +} + +bool_t check_camel_login_sthread(client_t *client, stringer_t *errmsg) { + + if (!check_camel_login(client, 1, "princess", "password", NULL)) { + + st_sprint(errmsg, "Failed to return successful state after auth request."); return false; } |