summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2014-07-01 03:13:16 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2014-07-01 03:13:16 +0000
commit5ab82d972d1b300af56a680950726b810133cd89 (patch)
tree72c2afde82d1003dc22cc24a19951a5d5a87380e
parent0e07f3b3f6df0f56bc5b23820977864828616845 (diff)
Add HTTP transport tests with XHR client emulation
These tests don't pass currently but I ran them against a hacked version of the HTTP server which never calls server_delete_session and they passed.
-rw-r--r--src/transport/Makefile.am22
-rw-r--r--src/transport/plugin_transport_http_client.c59
-rw-r--r--src/transport/test_transport_api_reliability_http_xhr_peer1.conf34
-rw-r--r--src/transport/test_transport_api_reliability_http_xhr_peer2.conf30
-rw-r--r--src/transport/test_transport_api_reliability_https_xhr_peer1.conf28
-rw-r--r--src/transport/test_transport_api_reliability_https_xhr_peer2.conf31
6 files changed, 198 insertions, 6 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index f198b5a6b..8367fb1b1 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -30,13 +30,15 @@ if HAVE_LIBGNURL
HTTP_API_TEST = test_transport_api_http
HTTP_REVERSE_API_TEST = test_transport_api_http_reverse
HTTP_API_TIMEOUT_TEST = test_transport_api_timeout_http
- HTTP_REL_TEST = test_transport_api_reliability_http
+ HTTP_REL_TEST = test_transport_api_reliability_http \
+ test_transport_api_reliability_http_xhr
HTTP_QUOTA_TEST = test_quota_compliance_http \
test_quota_compliance_http_asymmetric
HTTP_SWITCH = test_transport_address_switch_http
HTTPS_API_TEST = test_transport_api_https
HTTPS_API_TIMEOUT_TEST = test_transport_api_timeout_https
- HTTPS_REL_TEST = test_transport_api_reliability_https
+ HTTPS_REL_TEST = test_transport_api_reliability_https \
+ test_transport_api_reliability_https_xhr
HTTPS_QUOTA_TEST = test_quota_compliance_https \
test_quota_compliance_https_asymmetric
HTTPS_SWITCH = test_transport_address_switch_https
@@ -933,6 +935,14 @@ test_transport_api_reliability_http_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/transport/libgnunettransporttesting.la
+test_transport_api_reliability_http_xhr_SOURCES = \
+ test_transport_api_reliability.c
+test_transport_api_reliability_http_xhr_LDADD = \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/transport/libgnunettransporttesting.la
+
test_quota_compliance_http_SOURCES = \
test_quota_compliance.c
test_quota_compliance_http_LDADD = \
@@ -991,6 +1001,14 @@ test_transport_api_reliability_https_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/transport/libgnunettransporttesting.la
+test_transport_api_reliability_https_xhr_SOURCES = \
+ test_transport_api_reliability.c
+test_transport_api_reliability_https_xhr_LDADD = \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/transport/libgnunettransporttesting.la
+
test_transport_api_reliability_unix_SOURCES = \
test_transport_api_reliability.c
test_transport_api_reliability_unix_LDADD = \
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 81ab4d5da..cf75ec5d7 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -353,6 +353,10 @@ struct HTTP_Client_Plugin
*/
uint16_t use_ipv4;
+ /**
+ * Should we emulate an XHR client for testing?
+ */
+ int emulate_xhr;
};
@@ -649,6 +653,16 @@ client_log (CURL *curl,
/**
+ * Connect GET connection for a session
+ *
+ * @param s the session to connect
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+client_connect_get (struct Session *s);
+
+
+/**
* Connect a HTTP put connection
*
* @param s the session to connect
@@ -983,6 +997,15 @@ client_send_cb (void *stream,
if (NULL == msg)
{
+ if (GNUNET_YES == plugin->emulate_xhr)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %p/connection %p: PUT request finished\n",
+ s, s->put.easyhandle);
+ s->put_tmp_disconnecting = GNUNET_YES;
+ return 0;
+ }
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p/connection %p: nothing to send, suspending\n",
s, s->put.easyhandle);
@@ -1343,7 +1366,15 @@ curl_easy_getinfo (easy_h,
/* FIXME: who calls curl_multi_remove on 'easy_h' now!? */
GNUNET_assert (plugin->cur_connections > 0);
plugin->cur_connections--;
- http_client_plugin_session_disconnect (plugin, s);
+ /* If we are emulating an XHR client we need to make another GET
+ * request.
+ */
+ if (GNUNET_YES == plugin->emulate_xhr)
+ {
+ if (GNUNET_SYSERR == client_connect_get (s))
+ http_client_plugin_session_disconnect (plugin, s);
+ } else
+ http_client_plugin_session_disconnect (plugin, s);
}
}
}
@@ -1413,7 +1444,15 @@ client_connect_get (struct Session *s)
s->plugin->proxy_use_httpproxytunnel);
}
- curl_easy_setopt (s->get.easyhandle, CURLOPT_URL, s->url);
+ if (GNUNET_YES == s->plugin->emulate_xhr)
+ {
+ char *url;
+
+ GNUNET_asprintf(&url, "%s,1", s->url);
+ curl_easy_setopt (s->get.easyhandle, CURLOPT_URL, url);
+ GNUNET_free(url);
+ } else
+ curl_easy_setopt (s->get.easyhandle, CURLOPT_URL, s->url);
//curl_easy_setopt (s->get.easyhandle, CURLOPT_HEADERFUNCTION, &curl_get_header_cb);
//curl_easy_setopt (s->get.easyhandle, CURLOPT_WRITEHEADER, ps);
curl_easy_setopt (s->get.easyhandle, CURLOPT_READFUNCTION, client_send_cb);
@@ -1583,8 +1622,14 @@ client_connect (struct Session *s)
"Initiating outbound session peer `%s' using address `%s'\n",
GNUNET_i2s (&s->address->peer), s->url);
- if ((GNUNET_SYSERR == client_connect_get (s)) ||
- (GNUNET_SYSERR == client_connect_put (s)))
+ if (GNUNET_SYSERR == client_connect_get (s))
+ return GNUNET_SYSERR;
+ /* If we are emulating an XHR client then delay sending a PUT request until
+ * there is something to send.
+ */
+ if (GNUNET_YES == plugin->emulate_xhr)
+ s->put_tmp_disconnected = GNUNET_YES;
+ else if (GNUNET_SYSERR == client_connect_put (s))
return GNUNET_SYSERR;
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1970,6 +2015,12 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin)
GNUNET_free_non_null (proxy_type);
}
+
+ /* Should we emulate an XHR client for testing? */
+ plugin->emulate_xhr
+ = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
+ plugin->name,
+ "EMULATE_XHR");
return GNUNET_OK;
}
diff --git a/src/transport/test_transport_api_reliability_http_xhr_peer1.conf b/src/transport/test_transport_api_reliability_http_xhr_peer1.conf
new file mode 100644
index 000000000..c0cd835a5
--- /dev/null
+++ b/src/transport/test_transport_api_reliability_http_xhr_peer1.conf
@@ -0,0 +1,34 @@
+@INLINE@ template_cfg_peer1.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-http-p1/
+
+[transport-http_client]
+EMULATE_XHR = YES
+
+[transport-tcp]
+TIMEOUT = 5 s
+
+[transport-http]
+PORT = 12180
+
+[arm]
+PORT = 12185
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-arm.sock
+
+[statistics]
+PORT = 12184
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-statistics.sock
+
+[resolver]
+PORT = 12183
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-resolver.sock
+
+[peerinfo]
+PORT = 12182
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-peerinfo.sock
+
+[transport]
+PORT = 12181
+PLUGINS = http_client
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-transport.sock
+
diff --git a/src/transport/test_transport_api_reliability_http_xhr_peer2.conf b/src/transport/test_transport_api_reliability_http_xhr_peer2.conf
new file mode 100644
index 000000000..8d85cf7b1
--- /dev/null
+++ b/src/transport/test_transport_api_reliability_http_xhr_peer2.conf
@@ -0,0 +1,30 @@
+@INLINE@ template_cfg_peer2.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-http-p2/
+
+[transport-http_server]
+PORT = 12090
+USE_IPv6 = NO
+BINDTO = 127.0.0.1
+
+[arm]
+PORT = 12195
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-arm.sock
+
+[statistics]
+PORT = 12194
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-statistics.sock
+
+[resolver]
+PORT = 12193
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-resolver.sock
+
+[peerinfo]
+PORT = 12192
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-peerinfo.sock
+
+[transport]
+PORT = 12191
+PLUGINS = http_server
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-transport.sock
+
diff --git a/src/transport/test_transport_api_reliability_https_xhr_peer1.conf b/src/transport/test_transport_api_reliability_https_xhr_peer1.conf
new file mode 100644
index 000000000..614e371da
--- /dev/null
+++ b/src/transport/test_transport_api_reliability_https_xhr_peer1.conf
@@ -0,0 +1,28 @@
+@INLINE@ template_cfg_peer1.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-https-p1/
+
+[transport-https_client]
+EMULATE_XHR = YES
+
+[arm]
+PORT = 12305
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-arm.sock
+
+[statistics]
+PORT = 12304
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-statistics.sock
+
+[resolver]
+PORT = 12303
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-resolver.sock
+
+[peerinfo]
+PORT = 12302
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-peerinfo.sock
+
+[transport]
+PORT = 12301
+PLUGINS = https_client
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-transport.sock
+
diff --git a/src/transport/test_transport_api_reliability_https_xhr_peer2.conf b/src/transport/test_transport_api_reliability_https_xhr_peer2.conf
new file mode 100644
index 000000000..7f7f80778
--- /dev/null
+++ b/src/transport/test_transport_api_reliability_https_xhr_peer2.conf
@@ -0,0 +1,31 @@
+@INLINE@ template_cfg_peer2.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-https-p2/
+
+[transport-https_server]
+PORT = 12310
+KEY_FILE = $GNUNET_TEST_HOME/https_key_p2.key
+CERT_FILE = $GNUNET_TEST_HOME/https_cert_p2.crt
+
+[arm]
+PORT = 12315
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-arm.sock
+
+[statistics]
+PORT = 12314
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-statistics.sock
+
+[resolver]
+PORT = 12313
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-resolver.sock
+
+[peerinfo]
+PORT = 12312
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-peerinfo.sock
+
+[transport]
+PORT = 12311
+PLUGINS = https_server
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-transport.sock
+
+