diff options
author | Dan Winship <danw@gnome.org> | 2012-08-06 14:28:00 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2012-08-06 14:28:00 -0400 |
commit | 909850a4945fb9f37c8005a31f501861df9b3942 (patch) | |
tree | de1e65d76df0cd7c1c69303b7be265d095328fc4 /tests | |
parent | 1ce7f05e303cda7e53cf7d8e7797f0340e10fd14 (diff) | |
download | libsoup-909850a4945fb9f37c8005a31f501861df9b3942.tar.gz libsoup-909850a4945fb9f37c8005a31f501861df9b3942.tar.bz2 libsoup-909850a4945fb9f37c8005a31f501861df9b3942.zip |
soup-xmlrpc: fix parsing of <methodCall> without <params>
If a method takes no parameters, you can leave out the <params>
section of <methodCall>, but soup_xmlrpc_parse_method_call() was
requiring it anyway.
Fix that and add some tests of parameter-less methods.
https://bugzilla.gnome.org/show_bug.cgi?id=671661
Diffstat (limited to 'tests')
-rw-r--r-- | tests/xmlrpc-server-test.c | 12 | ||||
-rw-r--r-- | tests/xmlrpc-server.php | 17 | ||||
-rw-r--r-- | tests/xmlrpc-test.c | 94 |
3 files changed, 104 insertions, 19 deletions
diff --git a/tests/xmlrpc-server-test.c b/tests/xmlrpc-server-test.c index 8ad2187b..75f6c911 100644 --- a/tests/xmlrpc-server-test.c +++ b/tests/xmlrpc-server-test.c @@ -180,7 +180,17 @@ do_echo (SoupMessage *msg, GValueArray *params) soup_xmlrpc_set_response (msg, G_TYPE_VALUE_ARRAY, out); g_value_array_free (out); +} + +static void +do_ping (SoupMessage *msg, GValueArray *params) +{ + if (params->n_values) { + args_error (msg, params, 0); + return; + } + soup_xmlrpc_set_response (msg, G_TYPE_STRING, "pong"); } static void @@ -216,6 +226,8 @@ server_callback (SoupServer *server, SoupMessage *msg, do_dateChange (msg, params); else if (!strcmp (method_name, "echo")) do_echo (msg, params); + else if (!strcmp (method_name, "ping")) + do_ping (msg, params); else { soup_xmlrpc_set_fault (msg, SOUP_XMLRPC_FAULT_SERVER_ERROR_REQUESTED_METHOD_NOT_FOUND, "Unknown method %s", method_name); diff --git a/tests/xmlrpc-server.php b/tests/xmlrpc-server.php index 2e3dd381..66cb2be7 100644 --- a/tests/xmlrpc-server.php +++ b/tests/xmlrpc-server.php @@ -2,13 +2,13 @@ function paramfault () { - # xmlrpc-epi-php translates this into a real <fault> + # xmlrpc-php translates this into a real <fault> $fault["faultCode"] = -32602; $fault["faultString"] = "bad parameter"; return $fault; } -# We only check the params in sum(), because that's the one that +# We only check the params in sum(), because that is the one that # xmlrpc-test tests will fail if given bad args function sum ($method_name, $params, $app_data) @@ -69,8 +69,16 @@ function echo_ ($method_name, $params, $app_data) return $params[0]; } -# Work around xmlrpc-epi-php lossage; otherwise the datetime values -# we return will sometimes get a DST adjustment we don't want. +function ping ($method_name, $params, $app_data) +{ + if (count ($params) == 0) + return "pong"; + else + return paramfault (); +} + +# Work around xmlrpc-php lossage; otherwise the datetime values +# we return will sometimes get a DST adjustment we do not want. putenv ("TZ="); $xmlrpc_server = xmlrpc_server_create (); @@ -79,6 +87,7 @@ xmlrpc_server_register_method($xmlrpc_server, "countBools", "countBools"); xmlrpc_server_register_method($xmlrpc_server, "md5sum", "md5sum"); xmlrpc_server_register_method($xmlrpc_server, "dateChange", "dateChange"); xmlrpc_server_register_method($xmlrpc_server, "echo", "echo_"); +xmlrpc_server_register_method($xmlrpc_server, "ping", "ping"); $response = xmlrpc_server_call_method ($xmlrpc_server, implode("\r\n", file('php://input')), diff --git a/tests/xmlrpc-test.c b/tests/xmlrpc-test.c index ec67e4d1..7a29d0e9 100644 --- a/tests/xmlrpc-test.c +++ b/tests/xmlrpc-test.c @@ -27,26 +27,13 @@ static const char *const value_type[] = { }; static gboolean -do_xmlrpc (const char *method, GValue *retval, ...) +send_xmlrpc (const char *body, GValue *retval) { SoupMessage *msg; - va_list args; - GValueArray *params; GError *err = NULL; - char *body; - - va_start (args, retval); - params = soup_value_array_from_args (args); - va_end (args); - - body = soup_xmlrpc_build_method_call (method, params->values, - params->n_values); - g_value_array_free (params); - if (!body) - return FALSE; msg = soup_message_new ("POST", uri); - soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE, + soup_message_set_request (msg, "text/xml", SOUP_MEMORY_COPY, body, strlen (body)); soup_session_send_message (session, msg); @@ -74,6 +61,30 @@ do_xmlrpc (const char *method, GValue *retval, ...) } static gboolean +do_xmlrpc (const char *method, GValue *retval, ...) +{ + va_list args; + GValueArray *params; + char *body; + gboolean ret; + + va_start (args, retval); + params = soup_value_array_from_args (args); + va_end (args); + + body = soup_xmlrpc_build_method_call (method, params->values, + params->n_values); + g_value_array_free (params); + if (!body) + return FALSE; + + ret = send_xmlrpc (body, retval); + g_free (body); + + return ret; +} + +static gboolean check_xmlrpc (GValue *value, GType type, ...) { va_list args; @@ -386,6 +397,55 @@ test_echo (void) } static gboolean +test_ping (gboolean include_params) +{ + GValueArray *params; + GValue retval; + char *request; + char *out; + gboolean ret; + + debug_printf (1, "ping (void (%s) -> string): ", + include_params ? "empty <params>" : "no <params>"); + + params = soup_value_array_new (); + request = soup_xmlrpc_build_method_call ("ping", params->values, + params->n_values); + g_value_array_free (params); + if (!request) + return FALSE; + + if (!include_params) { + char *params, *end; + + params = strstr (request, "<params/>"); + if (!params) { + debug_printf (1, "ERROR: XML did not contain <params/>!"); + return FALSE; + } + end = params + strlen ("<params/>"); + memmove (params, end, strlen (end) + 1); + } + + ret = send_xmlrpc (request, &retval); + g_free (request); + + if (!ret || !check_xmlrpc (&retval, G_TYPE_STRING, &out)) + return FALSE; + + if (!strcmp (out, "pong")) { + debug_printf (1, "OK!\n"); + ret = TRUE; + } else { + debug_printf (1, "WRONG! Bad response '%s'", out); + ret = FALSE; + } + + g_free (out); + return ret; +} + +static gboolean do_bad_xmlrpc (const char *body) { SoupMessage *msg; @@ -476,6 +536,10 @@ main (int argc, char **argv) errors++; if (!test_echo ()) errors++; + if (!test_ping (TRUE)) + errors++; + if (!test_ping (FALSE)) + errors++; if (!test_fault_malformed ()) errors++; if (!test_fault_method ()) |