Compare commits
2 Commits
test/autop
...
fix/xep-00
| Author | SHA1 | Date | |
|---|---|---|---|
|
a2a2db7c45
|
|||
|
4b45f9cf58
|
@@ -1,10 +1,9 @@
|
||||
FROM archlinux:latest
|
||||
FROM archlinux
|
||||
|
||||
ENV TERM=xterm
|
||||
ENV CC="ccache gcc"
|
||||
|
||||
RUN pacman -Syyu --noconfirm
|
||||
|
||||
RUN pacman -Syu --noconfirm
|
||||
# reflector is optional - if it fails due to network issues, continue with default mirrorlist
|
||||
RUN pacman -S --needed --noconfirm reflector && \
|
||||
(reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist || true)
|
||||
|
||||
@@ -186,7 +186,6 @@ functionaltest_sources = \
|
||||
tests/functionaltests/test_muc.c tests/functionaltests/test_muc.h \
|
||||
tests/functionaltests/test_disconnect.c tests/functionaltests/test_disconnect.h \
|
||||
tests/functionaltests/test_lastactivity.c tests/functionaltests/test_lastactivity.h \
|
||||
tests/functionaltests/test_autoping.c tests/functionaltests/test_autoping.h \
|
||||
tests/functionaltests/test_disco.c tests/functionaltests/test_disco.h \
|
||||
tests/functionaltests/functionaltests.c
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ static void _ping_get_handler(xmpp_stanza_t* const stanza);
|
||||
static int _version_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_items_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _http_upload_response_id_handler(xmpp_stanza_t* const stanza, void* const upload_ctx);
|
||||
static int _last_activity_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
@@ -203,7 +204,11 @@ _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const us
|
||||
_disco_items_get_handler(stanza);
|
||||
}
|
||||
if (discoitems && (g_strcmp0(type, STANZA_TYPE_RESULT) == 0)) {
|
||||
_disco_items_result_handler(stanza);
|
||||
// Only handle onconnect here, user requests use id_handler
|
||||
const char* id = xmpp_stanza_get_id(stanza);
|
||||
if (g_strcmp0(id, "discoitemsreq_onconnect") == 0) {
|
||||
_disco_items_result_handler(stanza);
|
||||
}
|
||||
}
|
||||
|
||||
xmpp_stanza_t* lastactivity = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_LASTACTIVITY);
|
||||
@@ -637,7 +642,11 @@ void
|
||||
iq_disco_items_request(const char* jid)
|
||||
{
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t* iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid, NULL);
|
||||
auto_char char* id = connection_create_stanza_id();
|
||||
xmpp_stanza_t* iq = stanza_create_disco_items_iq(ctx, id, jid, NULL);
|
||||
|
||||
iq_id_handler_add(id, _disco_items_response_id_handler, NULL, NULL);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
@@ -2514,13 +2523,12 @@ _http_upload_response_id_handler(xmpp_stanza_t* const stanza, void* const userda
|
||||
static void
|
||||
_disco_items_result_handler(xmpp_stanza_t* const stanza)
|
||||
{
|
||||
log_debug("Received disco#items response");
|
||||
// This handler is only for onconnect disco#items requests
|
||||
log_debug("Received disco#items response (onconnect)");
|
||||
const char* id = xmpp_stanza_get_id(stanza);
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
GSList* items = NULL;
|
||||
|
||||
if ((g_strcmp0(id, "discoitemsreq") != 0) && (g_strcmp0(id, "discoitemsreq_onconnect") != 0)) {
|
||||
log_warning("_disco_items_result_handler: Received unexpected disco id: %s", id);
|
||||
if (g_strcmp0(id, "discoitemsreq_onconnect") != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2555,23 +2563,80 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
|
||||
if (g_strcmp0(id, "discoitemsreq") == 0) {
|
||||
cons_show_disco_items(items, from);
|
||||
} else if (g_strcmp0(id, "discoitemsreq_onconnect") == 0) {
|
||||
connection_set_disco_items(items);
|
||||
connection_set_disco_items(items);
|
||||
|
||||
while (late_delivery_windows) {
|
||||
LateDeliveryUserdata* del_data = late_delivery_windows->data;
|
||||
_iq_mam_request(del_data->win, del_data->startdate, del_data->enddate);
|
||||
free(del_data);
|
||||
late_delivery_windows = g_slist_delete_link(late_delivery_windows,
|
||||
late_delivery_windows);
|
||||
}
|
||||
while (late_delivery_windows) {
|
||||
LateDeliveryUserdata* del_data = late_delivery_windows->data;
|
||||
_iq_mam_request(del_data->win, del_data->startdate, del_data->enddate);
|
||||
free(del_data);
|
||||
late_delivery_windows = g_slist_delete_link(late_delivery_windows,
|
||||
late_delivery_windows);
|
||||
}
|
||||
|
||||
g_slist_free_full(items, (GDestroyNotify)_item_destroy);
|
||||
}
|
||||
|
||||
static int
|
||||
_disco_items_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
{
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
const char* type = xmpp_stanza_get_type(stanza);
|
||||
|
||||
if (from) {
|
||||
log_debug("Received disco#items response from: %s", from);
|
||||
} else {
|
||||
log_debug("Received disco#items response");
|
||||
}
|
||||
|
||||
// Handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
auto_char char* error_message = stanza_get_error_message(stanza);
|
||||
if (from) {
|
||||
cons_show_error("Service discovery failed for %s: %s", from, error_message);
|
||||
} else {
|
||||
cons_show_error("Service discovery failed: %s", error_message);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Handle result responses
|
||||
xmpp_stanza_t* query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||
if (query == NULL) {
|
||||
cons_show_disco_items(NULL, from);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSList* items = NULL;
|
||||
xmpp_stanza_t* child = xmpp_stanza_get_children(query);
|
||||
|
||||
while (child) {
|
||||
const char* stanza_name = xmpp_stanza_get_name(child);
|
||||
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
|
||||
const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
|
||||
if (item_jid) {
|
||||
DiscoItem* item = malloc(sizeof(struct disco_item_t));
|
||||
if (item) {
|
||||
item->jid = strdup(item_jid);
|
||||
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
|
||||
if (item_name) {
|
||||
item->name = strdup(item_name);
|
||||
} else {
|
||||
item->name = NULL;
|
||||
}
|
||||
items = g_slist_append(items, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
|
||||
cons_show_disco_items(items, from);
|
||||
g_slist_free_full(items, (GDestroyNotify)_item_destroy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
iq_feature_retrieval_complete_handler(void)
|
||||
{
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
* functional tests run less frequently than unit tests.
|
||||
*
|
||||
* Tests are organized into groups for better maintainability and parallel execution:
|
||||
* Group 1: Connect, Ping, Autoping (fast), Rooms, Software, Last Activity
|
||||
* Group 1: Connect, Ping, Rooms, Software
|
||||
* Group 2: Message, Receipts, Roster, Chat Session
|
||||
* Group 3: Presence, Disconnect, Autoping (slow)
|
||||
* Group 3: Presence, Disconnect
|
||||
* Group 4: MUC, Carbons
|
||||
*
|
||||
* Parallel execution:
|
||||
@@ -53,7 +53,6 @@
|
||||
#include "test_muc.h"
|
||||
#include "test_disconnect.h"
|
||||
#include "test_lastactivity.h"
|
||||
#include "test_autoping.h"
|
||||
#include "test_disco.h"
|
||||
|
||||
/* Macro to wrap each test with setup/teardown functions */
|
||||
@@ -111,16 +110,6 @@ main(int argc, char* argv[])
|
||||
/* Last Activity - XEP-0012 */
|
||||
PROF_FUNC_TEST(responds_to_last_activity_request),
|
||||
PROF_FUNC_TEST(last_activity_request_to_contact),
|
||||
|
||||
/* Autoping command tests - fast, no waiting */
|
||||
PROF_FUNC_TEST(autoping_set_interval),
|
||||
PROF_FUNC_TEST(autoping_set_zero_disables),
|
||||
PROF_FUNC_TEST(autoping_timeout_set),
|
||||
PROF_FUNC_TEST(autoping_timeout_zero_disables),
|
||||
|
||||
/* Autoping slow tests - require sleep for timer triggers (~2s each) */
|
||||
PROF_FUNC_TEST(autoping_sends_ping_after_interval),
|
||||
PROF_FUNC_TEST(autoping_server_not_supporting_ping),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
@@ -179,20 +168,7 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(disconnect_ends_session),
|
||||
|
||||
/* Service Discovery - XEP-0030 */
|
||||
PROF_FUNC_TEST(disco_info_shows_identity),
|
||||
PROF_FUNC_TEST(disco_info_shows_features),
|
||||
PROF_FUNC_TEST(disco_info_to_server),
|
||||
PROF_FUNC_TEST(disco_info_to_jid),
|
||||
PROF_FUNC_TEST(disco_info_not_found),
|
||||
PROF_FUNC_TEST(disco_items_shows_items),
|
||||
PROF_FUNC_TEST(disco_items_empty_result),
|
||||
PROF_FUNC_TEST(disco_requires_connection),
|
||||
PROF_FUNC_TEST(disco_items_to_jid),
|
||||
PROF_FUNC_TEST(disco_info_empty_result),
|
||||
PROF_FUNC_TEST(disco_info_multiple_identities),
|
||||
PROF_FUNC_TEST(disco_info_without_name),
|
||||
PROF_FUNC_TEST(disco_items_without_name),
|
||||
PROF_FUNC_TEST(disco_info_service_unavailable),
|
||||
PROF_FUNC_TEST(disco_items_error_handling),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
@@ -240,7 +216,7 @@ main(int argc, char* argv[])
|
||||
const struct CMUnitTest* tests;
|
||||
size_t count;
|
||||
} groups[] = {
|
||||
{ "Group 1: Connect/Ping/Rooms/Software/Autoping", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 1: Connect/Ping/Rooms/Software", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: Message/Receipts/Roster/Session", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Presence/Disconnect/Disco", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 4: MUC/Carbons", group4_tests, ARRAY_SIZE(group4_tests) },
|
||||
|
||||
@@ -362,6 +362,7 @@ close_prof_test(void **state)
|
||||
fd = 0;
|
||||
child_pid = 0;
|
||||
}
|
||||
_cleanup_dirs();
|
||||
|
||||
if (config_orig) {
|
||||
setenv("XDG_CONFIG_HOME", config_orig, 1);
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
#include <glib.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
void
|
||||
autoping_set_interval(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping set 60");
|
||||
assert_true(prof_output_exact("Autoping interval set to 60 seconds."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_set_zero_disables(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_timeout_set(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping timeout 30");
|
||||
assert_true(prof_output_exact("Autoping timeout set to 30 seconds."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_timeout_zero_disables(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping timeout 0");
|
||||
assert_true(prof_output_exact("Autoping timeout disabled."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_sends_ping_after_interval(void** state)
|
||||
{
|
||||
/*
|
||||
* This test verifies that autoping sends a ping IQ after the configured
|
||||
* interval. We set a short interval (1 second) and verify the ping is sent.
|
||||
*/
|
||||
|
||||
// Register disco#info response with ping support
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Stabber'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
// Register ping response
|
||||
stbbr_for_query("urn:xmpp:ping",
|
||||
"<iq from='localhost' to='stabber@localhost/profanity' type='result'/>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
// Set short autoping interval
|
||||
prof_input("/autoping set 1");
|
||||
assert_true(prof_output_exact("Autoping interval set to 1 seconds."));
|
||||
|
||||
// Wait for autoping to trigger (interval + some buffer)
|
||||
sleep(2);
|
||||
|
||||
// Verify ping was sent (no 'to' attribute means server ping)
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' type='get'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_server_not_supporting_ping(void** state)
|
||||
{
|
||||
/*
|
||||
* When server doesn't support ping, autoping should show error.
|
||||
*/
|
||||
|
||||
// Register disco#info response WITHOUT ping support
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Stabber'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
// Set short autoping interval
|
||||
prof_input("/autoping set 1");
|
||||
assert_true(prof_output_exact("Autoping interval set to 1 seconds."));
|
||||
|
||||
// Wait for autoping to trigger
|
||||
sleep(2);
|
||||
|
||||
// Should show error about ping not being supported
|
||||
assert_true(prof_output_regex("Server ping not supported"));
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
void autoping_set_interval(void** state);
|
||||
void autoping_set_zero_disables(void** state);
|
||||
void autoping_timeout_set(void** state);
|
||||
void autoping_timeout_zero_disables(void** state);
|
||||
void autoping_sends_ping_after_interval(void** state);
|
||||
void autoping_server_not_supporting_ping(void** state);
|
||||
@@ -1,409 +1,24 @@
|
||||
/*
|
||||
* test_disco.c
|
||||
*
|
||||
* Functional tests for /disco command (XEP-0030 Service Discovery).
|
||||
* Tests cover:
|
||||
* - /disco info [jid] - query entity capabilities and features
|
||||
* - /disco items [jid] - query entity items/services
|
||||
*
|
||||
* XEP-0030: https://xmpp.org/extensions/xep-0030.html
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
void
|
||||
disco_info_shows_identity(void **state)
|
||||
disco_items_error_handling(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info displays identity information correctly.
|
||||
* Identity includes: name, type, category
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Prosody'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery info for localhost"));
|
||||
assert_true(prof_output_exact("Identities"));
|
||||
assert_true(prof_output_regex("Prosody.*im.*server"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_shows_features(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info displays feature list.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='TestServer'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"<feature var='http://jabber.org/protocol/disco#info'/>"
|
||||
"<feature var='http://jabber.org/protocol/disco#items'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Features:"));
|
||||
assert_true(prof_output_exact("urn:xmpp:ping"));
|
||||
assert_true(prof_output_exact("http://jabber.org/protocol/disco#info"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_to_server(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info without arguments queries the server (domainpart).
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='LocalServer'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
/* Verify request was sent to server (localhost) */
|
||||
prof_timeout(10);
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_to_jid(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info <jid> queries the specified JID.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='conference.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='conference' type='text' name='MUC Service'/>"
|
||||
"<feature var='http://jabber.org/protocol/muc'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info conference.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Verify request was sent to specified JID */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='conference.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
||||
assert_true(prof_output_exact("Service discovery info for conference.localhost"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_not_found(void **state)
|
||||
{
|
||||
/*
|
||||
* Test error handling when disco info returns item-not-found.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='error' from='unknown.localhost'>"
|
||||
"<error type='cancel'>"
|
||||
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
|
||||
"</error>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info unknown.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_regex("Service discovery failed.*item-not-found"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_shows_items(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items displays items list with JID and name.
|
||||
* Test that /disco items displays error responses to user.
|
||||
* Per XEP-0030 Section 7: errors like service-unavailable must be shown.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'>"
|
||||
"<item jid='conference.localhost' name='Chat Rooms'/>"
|
||||
"<item jid='pubsub.localhost' name='Publish-Subscribe'/>"
|
||||
"<item jid='proxy.localhost' name='SOCKS5 Bytestreams'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery items for localhost:"));
|
||||
assert_true(prof_output_regex("conference.localhost.*Chat Rooms"));
|
||||
assert_true(prof_output_regex("pubsub.localhost.*Publish-Subscribe"));
|
||||
assert_true(prof_output_regex("proxy.localhost.*SOCKS5 Bytestreams"));
|
||||
|
||||
/* Verify IQ was sent with correct id */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='discoitemsreq' to='localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||||
"</iq>"
|
||||
));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_empty_result(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items handles empty result gracefully.
|
||||
* Per XEP-0030: "if an entity has no associated items, it MUST return
|
||||
* an empty <query/> element (rather than an error)"
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("No service discovery items for localhost"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_requires_connection(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info and /disco items require an active connection.
|
||||
* First test without any connection, then after connect/disconnect.
|
||||
*/
|
||||
|
||||
/* Without connection */
|
||||
prof_input("/disconnect");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
prof_input("/disco info");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
prof_input("/disco items");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
/* After connect and disconnect */
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disconnect");
|
||||
assert_true(prof_output_exact("stabber@localhost logged out successfully."));
|
||||
|
||||
prof_input("/disco info");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
prof_input("/disco items");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_to_jid(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items <jid> queries the specified JID.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='conference.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'>"
|
||||
"<item jid='room1@conference.localhost' name='General Chat'/>"
|
||||
"<item jid='room2@conference.localhost' name='Support'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items conference.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Verify request was sent to specified JID */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='discoitemsreq' to='conference.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
||||
assert_true(prof_output_exact("Service discovery items for conference.localhost:"));
|
||||
assert_true(prof_output_regex("room1@conference.localhost.*General Chat"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_empty_result(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info handles empty result (no identities/features).
|
||||
* This can happen with minimal server configurations.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='minimal.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info minimal.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Verify request was sent */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='minimal.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
));
|
||||
/* Empty result should not crash and should not show "Service discovery info" */
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_multiple_identities(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info displays multiple identities correctly.
|
||||
* Entities can have multiple identities (e.g., server + gateway).
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='gateway.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='gateway' type='irc' name='IRC Gateway'/>"
|
||||
"<identity category='directory' type='chatroom' name='Room Directory'/>"
|
||||
"<identity category='automation' type='command-node' name='Ad-Hoc Commands'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info gateway.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery info for gateway.localhost"));
|
||||
assert_true(prof_output_exact("Identities"));
|
||||
assert_true(prof_output_regex("IRC Gateway.*irc.*gateway"));
|
||||
assert_true(prof_output_regex("Room Directory.*chatroom.*directory"));
|
||||
assert_true(prof_output_regex("Ad-Hoc Commands.*command-node.*automation"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_without_name(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info handles identity without name attribute.
|
||||
* Per XEP-0030: name is OPTIONAL, only category and type are REQUIRED.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery info for localhost"));
|
||||
assert_true(prof_output_exact("Identities"));
|
||||
/* Should show type and category even without name */
|
||||
assert_true(prof_output_regex("im.*server"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_without_name(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items handles items without name attribute.
|
||||
* Per XEP-0030: name is OPTIONAL for items, only jid is REQUIRED.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'>"
|
||||
"<item jid='conference.localhost'/>"
|
||||
"<item jid='pubsub.localhost' name='PubSub Service'/>"
|
||||
"<item jid='upload.localhost'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery items for localhost:"));
|
||||
/* Items without name should still display their JID */
|
||||
assert_true(prof_output_exact("conference.localhost"));
|
||||
assert_true(prof_output_regex("pubsub.localhost.*PubSub Service"));
|
||||
assert_true(prof_output_exact("upload.localhost"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_service_unavailable(void **state)
|
||||
{
|
||||
/*
|
||||
* Test error handling when disco info returns service-unavailable.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='error' from='offline.localhost'>"
|
||||
"<iq to='stabber@localhost/profanity' type='error' from='broken.localhost'>"
|
||||
"<error type='cancel'>"
|
||||
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
|
||||
"</error>"
|
||||
@@ -412,9 +27,10 @@ disco_info_service_unavailable(void **state)
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info offline.localhost");
|
||||
prof_input("/disco items broken.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Per XEP-0030, error should be displayed to user */
|
||||
assert_true(prof_output_regex("Service discovery failed.*service-unavailable"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
@@ -1,19 +1 @@
|
||||
/* test_disco.h
|
||||
*
|
||||
* Functional tests for /disco command (XEP-0030 Service Discovery)
|
||||
*/
|
||||
|
||||
void disco_info_shows_identity(void **state);
|
||||
void disco_info_shows_features(void **state);
|
||||
void disco_info_to_server(void **state);
|
||||
void disco_info_to_jid(void **state);
|
||||
void disco_info_not_found(void **state);
|
||||
void disco_items_shows_items(void **state);
|
||||
void disco_items_empty_result(void **state);
|
||||
void disco_requires_connection(void **state);
|
||||
void disco_items_to_jid(void **state);
|
||||
void disco_info_empty_result(void **state);
|
||||
void disco_info_multiple_identities(void **state);
|
||||
void disco_info_without_name(void **state);
|
||||
void disco_items_without_name(void **state);
|
||||
void disco_info_service_unavailable(void **state);
|
||||
void disco_items_error_handling(void** state);
|
||||
|
||||
Reference in New Issue
Block a user