From fdb0479e68cbbea4e5be8cb34fbd835b3eb8cbf5 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 3 Feb 2016 22:21:59 -0800 Subject: [PATCH 1/2] Add a simple test that checks the wocky session managers getters and setters --- tests/wocky-xmpp-connection-test.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/wocky-xmpp-connection-test.c b/tests/wocky-xmpp-connection-test.c index 0e83764..3e4a370 100644 --- a/tests/wocky-xmpp-connection-test.c +++ b/tests/wocky-xmpp-connection-test.c @@ -37,6 +37,33 @@ test_instantiation (void) g_object_unref (stream); } +static void +test_sm_instantiation (void) +{ + WockyXmppConnection *connection; + WockyTestStream *stream; + guint pending_messages; + + stream = g_object_new (WOCKY_TYPE_TEST_STREAM, NULL); + connection = wocky_xmpp_connection_new (stream->stream0); + + g_assert (connection != NULL); + + g_assert_false (wocky_xmpp_connection_get_sm_enabled (connection)); + g_assert_cmpint (wocky_xmpp_connection_get_stanza_recv_count (connection), ==, 0); + + wocky_xmpp_connection_set_sm_enabled (connection, TRUE); + g_assert (wocky_xmpp_connection_get_sm_enabled (connection)); + g_assert (wocky_xmpp_connection_get_stanza_recv_count (connection) == 0); + + pending_messages = g_test_rand_int (); + wocky_xmpp_connection_set_stanza_recv_count (connection, pending_messages); + g_assert_cmpint (wocky_xmpp_connection_get_stanza_recv_count (connection), ==, pending_messages); + + g_object_unref (connection); + g_object_unref (stream); +} + /* Simple message test */ static void stanza_received_cb (GObject *source, GAsyncResult *res, gpointer user_data) @@ -912,6 +939,7 @@ main (int argc, char **argv) test_init (argc, argv); g_test_add_func ("/xmpp-connection/initiation", test_instantiation); + g_test_add_func ("/xmpp-connection/initiation+session-management", test_sm_instantiation); g_test_add_func ("/xmpp-connection/recv-simple-message", test_recv_simple_message); g_test_add_func ("/xmpp-connection/send-simple-message", -- 2.7.0 From 9921288968dc7f3321c909bf85ff7020c3b40a80 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 3 Feb 2016 22:41:08 -0800 Subject: [PATCH 2/2] Test that the stream management negotiation works. This adds implements the basic server side component and adds a way to indicate that the test should not have succeeded (Say for instance the connection was closed before the stream management negotiation finished). Future work would be to test different ways the negotation could fail and to make sure that the r and a stanzas are sent correctly. --- tests/wocky-connector-test.c | 33 ++++++++++++++++++++++++--------- tests/wocky-test-connector-server.c | 25 +++++++++++++++++++++++++ tests/wocky-test-connector-server.h | 8 ++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/tests/wocky-connector-test.c b/tests/wocky-connector-test.c index e2622b4..6bd5805 100644 --- a/tests/wocky-connector-test.c +++ b/tests/wocky-connector-test.c @@ -1366,7 +1366,8 @@ test_t tests[] = WOCKY_CONNECTOR_ERROR_REGISTRATION_EMPTY, -1 }, { { TLS, NULL }, { SERVER_PROBLEM_NO_PROBLEM, - { OK, OK, OK, OK, OK, XEP77_PROBLEM_NO_ARGS } }, + { OK, OK, OK, OK, OK, XEP77_PROBLEM_NO_ARGS, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1544,7 +1545,9 @@ test_t tests[] = NOISY, { S_NO_ERROR, }, { { TLS, NULL }, - { SERVER_PROBLEM_NO_PROBLEM, CONNECTOR_OK }, + { SERVER_PROBLEM_NO_PROBLEM, + { OK, OK, OK, OK, OK, OK, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1600,7 +1603,8 @@ test_t tests[] = { S_NO_ERROR, }, { { TLS, NULL }, { SERVER_PROBLEM_NO_PROBLEM, - { OK, OK, OK, OK, OK, XEP77_PROBLEM_CANCEL_STREAM } }, + { OK, OK, OK, OK, OK, XEP77_PROBLEM_CANCEL_STREAM, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1616,7 +1620,8 @@ test_t tests[] = { S_NO_ERROR, }, { { TLS, NULL }, { SERVER_PROBLEM_NO_PROBLEM, - { XMPP_PROBLEM_OLD_SERVER, OK, OK, OK, OK } }, + { XMPP_PROBLEM_OLD_SERVER, OK, OK, OK, OK, OK, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1736,7 +1741,8 @@ test_t tests[] = { S_NO_ERROR, }, { { TLS, "password" }, { SERVER_PROBLEM_NO_PROBLEM, - { XMPP_PROBLEM_OLD_SERVER, OK, OK, OK, OK } }, + { XMPP_PROBLEM_OLD_SERVER, OK, OK, OK, OK, OK, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1788,7 +1794,8 @@ test_t tests[] = { S_NO_ERROR, }, { { TLS, NULL }, { SERVER_PROBLEM_NO_SASL, - { XMPP_PROBLEM_OLD_AUTH_FEATURE, OK, OK, OK, OK } }, + { XMPP_PROBLEM_OLD_AUTH_FEATURE, OK, OK, OK, OK, OK, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1803,7 +1810,8 @@ test_t tests[] = { S_NO_ERROR, }, { { TLS, NULL }, { SERVER_PROBLEM_NO_PROBLEM, - { XMPP_PROBLEM_OLD_SERVER|XMPP_PROBLEM_OLD_SSL, OK, OK, OK, OK } }, + { XMPP_PROBLEM_OLD_SERVER|XMPP_PROBLEM_OLD_SSL, OK, OK, OK, OK, + OK, STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1926,7 +1934,8 @@ test_t tests[] = { S_NO_ERROR, }, { { TLS, "password" }, { SERVER_PROBLEM_NO_PROBLEM, - { XMPP_PROBLEM_OLD_SERVER|XMPP_PROBLEM_OLD_SSL, OK, OK, OK, OK } }, + { XMPP_PROBLEM_OLD_SERVER|XMPP_PROBLEM_OLD_SSL, OK, OK, OK, OK, + OK, STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -1982,7 +1991,7 @@ test_t tests[] = { { TLS, NULL }, { SERVER_PROBLEM_NO_SASL, { XMPP_PROBLEM_OLD_AUTH_FEATURE|XMPP_PROBLEM_OLD_SSL, - OK, OK, OK, OK } }, + OK, OK, OK, OK, OK, STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE } }, { "moose", "something" }, PORT_XMPP }, { NULL, 0, "weasel-juice.org", REACHABLE, NULL }, @@ -3661,6 +3670,12 @@ run_test (gpointer data) g_object_unref (tmp); } + + if (!(test->server_parameters.problem.conn.sm)) + { + g_assert_true (wocky_xmpp_connection_get_sm_enabled ( + test->result.xmpp)); + } } else { diff --git a/tests/wocky-test-connector-server.c b/tests/wocky-test-connector-server.c index 919fa86..27851ef 100644 --- a/tests/wocky-test-connector-server.c +++ b/tests/wocky-test-connector-server.c @@ -197,6 +197,8 @@ static void handle_auth (TestConnectorServer *self, WockyStanza *xml); static void handle_starttls (TestConnectorServer *self, WockyStanza *xml); +static void handle_enable (TestConnectorServer *self, + WockyStanza *xml); static void after_auth (GObject *source, @@ -235,6 +237,7 @@ static stanza_handler handlers[] = { HANDLER (SASL_AUTH, auth), HANDLER (TLS, starttls), + HANDLER (STREAM_MANAGEMENT, enable), { NULL, NULL, NULL } }; @@ -1031,6 +1034,25 @@ handle_starttls (TestConnectorServer *self, } static void +handle_enable (TestConnectorServer *self, + WockyStanza *xml) +{ + TestConnectorServerPrivate *priv = self->priv; + WockyXmppConnection *conn = priv->conn; + WockyStanza *reply = NULL; + GAsyncReadyCallback cb = iq_sent; + + DEBUG (""); + + reply = wocky_stanza_new ("enabled", WOCKY_XMPP_NS_STREAM_MANAGEMENT); + + server_enc_outstanding (self); + wocky_xmpp_connection_send_stanza_async (conn, reply, NULL, cb, self); + g_object_unref (reply); + g_object_unref (xml); +} + +static void finished (GObject *source, GAsyncResult *result, gpointer data) @@ -1266,6 +1288,9 @@ after_auth (GObject *source, if (!(priv->problem.connector->xmpp & XMPP_PROBLEM_CANNOT_BIND)) wocky_node_add_child_ns (node, "bind", WOCKY_XMPP_NS_BIND); + if (!(priv->problem.connector->sm & STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE)) + wocky_node_add_child_ns (node, "sm", WOCKY_XMPP_NS_STREAM_MANAGEMENT); + priv->state = SERVER_STATE_FEATURES_SENT; server_enc_outstanding (tcs); diff --git a/tests/wocky-test-connector-server.h b/tests/wocky-test-connector-server.h index 15169d4..2737cca 100644 --- a/tests/wocky-test-connector-server.h +++ b/tests/wocky-test-connector-server.h @@ -114,6 +114,13 @@ typedef enum typedef enum { + STREAM_MANAGEMENT_PROBLEM_NONE = 0, + STREAM_MANAGEMENT_PROBLEM_NOT_AVAILABLE = CONNPROBLEM(0), + STREAM_MANAGEMENT_PROBLEM_FAILED = CONNPROBLEM(1), +} StreamManagementProblem; + +typedef enum +{ CERT_STANDARD, CERT_EXPIRED, CERT_NOT_YET, @@ -133,6 +140,7 @@ typedef struct ServerDeath death; JabberProblem jabber; XEP77Problem xep77; + StreamManagementProblem sm; } ConnectorProblem; typedef struct _TestConnectorServer TestConnectorServer; -- 2.7.0