From a2a2db7c45c36b7888885060798bb6eed8e2ecef Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Mon, 16 Feb 2026 11:16:01 +0300 Subject: [PATCH] test(disco): add functional test for disco#items error handling Verifies that /disco items displays error responses (e.g. service-unavailable) to the user, per XEP-0030 Section 7. --- Makefile.am | 1 + tests/functionaltests/functionaltests.c | 8 ++++-- tests/functionaltests/test_disco.c | 36 +++++++++++++++++++++++++ tests/functionaltests/test_disco.h | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/functionaltests/test_disco.c create mode 100644 tests/functionaltests/test_disco.h diff --git a/Makefile.am b/Makefile.am index 60ff0f33..935f86b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,6 +186,7 @@ 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_disco.c tests/functionaltests/test_disco.h \ tests/functionaltests/functionaltests.c main_source = src/main.c diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 46d1a7d2..912e2faf 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -53,6 +53,7 @@ #include "test_muc.h" #include "test_disconnect.h" #include "test_lastactivity.h" +#include "test_disco.h" /* Macro to wrap each test with setup/teardown functions */ #define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test) @@ -143,7 +144,7 @@ main(int argc, char* argv[]) }; /* ============================================================ - * GROUP 3: Presence, Disconnect + * GROUP 3: Presence, Disconnect, Disco * Online/away/xa/dnd/chat status management * ============================================================ */ const struct CMUnitTest group3_tests[] = { @@ -165,6 +166,9 @@ main(int argc, char* argv[]) /* Disconnect - clean session termination */ PROF_FUNC_TEST(disconnect_ends_session), + + /* Service Discovery - XEP-0030 */ + PROF_FUNC_TEST(disco_items_error_handling), }; /* ============================================================ @@ -214,7 +218,7 @@ main(int argc, char* argv[]) } groups[] = { { "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", group3_tests, ARRAY_SIZE(group3_tests) }, + { "Group 3: Presence/Disconnect/Disco", group3_tests, ARRAY_SIZE(group3_tests) }, { "Group 4: MUC/Carbons", group4_tests, ARRAY_SIZE(group4_tests) }, }; const int num_groups = ARRAY_SIZE(groups); diff --git a/tests/functionaltests/test_disco.c b/tests/functionaltests/test_disco.c new file mode 100644 index 00000000..ebb98acc --- /dev/null +++ b/tests/functionaltests/test_disco.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "proftest.h" + +void +disco_items_error_handling(void **state) +{ + /* + * 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", + "" + "" + "" + "" + "" + ); + + prof_connect(); + + 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(); +} diff --git a/tests/functionaltests/test_disco.h b/tests/functionaltests/test_disco.h new file mode 100644 index 00000000..8a82cbaa --- /dev/null +++ b/tests/functionaltests/test_disco.h @@ -0,0 +1 @@ +void disco_items_error_handling(void** state);