Compare commits
4 Commits
test/autop
...
58dd89be40
| Author | SHA1 | Date | |
|---|---|---|---|
|
58dd89be40
|
|||
|
b2ce06923e
|
|||
|
9b292a6100
|
|||
|
a9c21ce487
|
3
.github/workflows/ci-code.yml
vendored
3
.github/workflows/ci-code.yml
vendored
@@ -50,9 +50,6 @@ jobs:
|
||||
run: |
|
||||
grep -P 'auto_(char|gchar|gcharv|guchar|jid|sqlite|gfd|FILE)[\w *]*;$' -r src && exit -1 || true
|
||||
|
||||
- name: Check CWE-134 format string vulnerabilities
|
||||
run: ./check-cwe134.sh
|
||||
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
sudo apt-get update
|
||||
|
||||
@@ -144,16 +144,6 @@ scan-build make
|
||||
scan-view ...
|
||||
```
|
||||
|
||||
### Security checks
|
||||
|
||||
We have a static analyzer `check-cwe134.sh` that detects CWE-134 format string vulnerabilities. It runs automatically in CI but you can also run it locally:
|
||||
|
||||
```bash
|
||||
./check-cwe134.sh
|
||||
```
|
||||
|
||||
This checks for unsafe patterns where data could be passed directly as a format string to functions like `printf`, `cons_show`, etc. Never pass a raw string for formatting; use `"%s"` format specifier instead.
|
||||
|
||||
### Finding typos
|
||||
|
||||
We include a `.codespellrc` configuration file for `codespell` in the root directory.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -185,9 +185,6 @@ functionaltest_sources = \
|
||||
tests/functionaltests/test_software.c tests/functionaltests/test_software.h \
|
||||
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
|
||||
|
||||
main_source = src/main.c
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
#!/bin/bash
|
||||
# check-cwe134.sh - Static analysis for CWE-134 format string vulnerabilities
|
||||
#
|
||||
# This script detects potentially unsafe usage of format string functions
|
||||
# where user-controlled data may be passed without "%s" wrapper.
|
||||
#
|
||||
# Usage: ./check-cwe134.sh [directory]
|
||||
|
||||
set -e
|
||||
|
||||
DIR="${1:-src}"
|
||||
|
||||
echo "=== CWE-134 Format String Vulnerability Check ==="
|
||||
echo "Scanning: $DIR"
|
||||
echo ""
|
||||
|
||||
# Functions that accept format strings
|
||||
FORMAT_FUNCS="cons_show|cons_debug|cons_show_error|log_info|log_error|log_warning|log_debug|win_println|win_print"
|
||||
|
||||
ERRORS=0
|
||||
|
||||
echo "Checking for unsafe format string usage..."
|
||||
echo ""
|
||||
|
||||
# Pattern 1: function call with single variable argument (no format string)
|
||||
# Example: cons_show(variable); - BAD
|
||||
# Example: cons_show("%s", variable); - OK
|
||||
# Matches: func(identifier) or func(identifier->member) or func(identifier[index])
|
||||
RESULTS=$(grep -rn --include="*.c" -P "($FORMAT_FUNCS)\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*(\s*->\s*\w+|\s*\[\s*\w+\s*\])?\s*\)\s*;" "$DIR" 2>/dev/null || true)
|
||||
|
||||
# Filter out function definitions, declarations, and safe api_* wrappers
|
||||
RESULTS=$(echo "$RESULTS" | grep -v "const char\|void \|^[^:]*:[0-9]*:[a-z_]*(\|api_cons_show\|api_log_" || true)
|
||||
|
||||
if [ -n "$RESULTS" ]; then
|
||||
echo "❌ POTENTIAL CWE-134 VULNERABILITIES FOUND:"
|
||||
echo ""
|
||||
echo "$RESULTS"
|
||||
echo ""
|
||||
ERRORS=$(echo "$RESULTS" | wc -l)
|
||||
else
|
||||
echo "✅ No obvious CWE-134 issues found."
|
||||
fi
|
||||
|
||||
# Additional check: GString->str passed directly (not as %s argument)
|
||||
echo ""
|
||||
echo "Checking for GString->str passed to format functions..."
|
||||
|
||||
GSTRING_RESULTS=$(grep -rn --include="*.c" -P "($FORMAT_FUNCS)\s*\([^)]*->str\s*\)" "$DIR" 2>/dev/null | grep -v '"%s"' || true)
|
||||
|
||||
if [ -n "$GSTRING_RESULTS" ]; then
|
||||
echo "⚠️ GString->str passed without \"%s\" (review manually):"
|
||||
echo ""
|
||||
echo "$GSTRING_RESULTS"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Summary ==="
|
||||
echo "Critical issues: $ERRORS"
|
||||
|
||||
if [ "$ERRORS" -gt 0 ]; then
|
||||
echo ""
|
||||
echo "Fix by adding \"%s\" format specifier:"
|
||||
echo " BAD: cons_show(variable);"
|
||||
echo " GOOD: cons_show(\"%s\", variable);"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -4970,8 +4970,8 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
||||
alt_scheme = OMEMO_AESGCM_URL_SCHEME;
|
||||
alt_fragment = _add_omemo_stream(&fd, &fh, &err);
|
||||
if (err != NULL) {
|
||||
cons_show_error("%s", err);
|
||||
win_println(window, THEME_ERROR, "-", "%s", err);
|
||||
cons_show_error(err);
|
||||
win_println(window, THEME_ERROR, "-", err);
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -143,7 +143,7 @@ auto_close_gfd(gint* fd)
|
||||
return;
|
||||
|
||||
if (close(*fd) == EOF)
|
||||
log_error("%s", g_strerror(errno));
|
||||
log_error(g_strerror(errno));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +158,7 @@ auto_close_FILE(FILE** fd)
|
||||
return;
|
||||
|
||||
if (fclose(*fd) == EOF)
|
||||
log_error("%s", g_strerror(errno));
|
||||
log_error(g_strerror(errno));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
||||
@@ -77,8 +77,6 @@ _db_teardown(const char* ctx)
|
||||
}
|
||||
g_chatlog_database = NULL;
|
||||
}
|
||||
// Safe to call unconditionally; no-op if not initialized.
|
||||
// See: https://www.sqlite.org/c3ref/initialize.html
|
||||
sqlite3_shutdown();
|
||||
}
|
||||
|
||||
|
||||
@@ -887,8 +887,8 @@ _python_undefined_error(ProfPlugin* plugin, char* hook, char* type)
|
||||
g_string_append(err_msg, hook);
|
||||
g_string_append(err_msg, "(): return value undefined, expected ");
|
||||
g_string_append(err_msg, type);
|
||||
log_error("%s", err_msg->str);
|
||||
cons_show_error("%s", err_msg->str);
|
||||
log_error(err_msg->str);
|
||||
cons_show_error(err_msg->str);
|
||||
g_string_free(err_msg, TRUE);
|
||||
}
|
||||
|
||||
@@ -901,8 +901,8 @@ _python_type_error(ProfPlugin* plugin, char* hook, char* type)
|
||||
g_string_append(err_msg, hook);
|
||||
g_string_append(err_msg, "(): incorrect return type, expected ");
|
||||
g_string_append(err_msg, type);
|
||||
log_error("%s", err_msg->str);
|
||||
cons_show_error("%s", err_msg->str);
|
||||
log_error(err_msg->str);
|
||||
cons_show_error(err_msg->str);
|
||||
g_string_free(err_msg, TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_f
|
||||
*/
|
||||
min_runtime += waittime;
|
||||
} else {
|
||||
log_error("%s", err_msg);
|
||||
log_error(err_msg);
|
||||
g_free(err_msg);
|
||||
commands = NULL;
|
||||
}
|
||||
@@ -245,7 +245,7 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
if (prof_log_level == PROF_LEVEL_DEBUG) {
|
||||
ProfWin* console = wins_get_console();
|
||||
win_println(console, THEME_DEFAULT, "-", "Debug mode enabled! Logging to: ");
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", get_log_file_location());
|
||||
win_println(console, THEME_DEFAULT, "-", get_log_file_location());
|
||||
}
|
||||
session_init();
|
||||
cmd_init();
|
||||
|
||||
@@ -311,7 +311,7 @@ http_file_put(void* userdata)
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, err_msg);
|
||||
}
|
||||
cons_show_error("%s", err_msg);
|
||||
cons_show_error(err_msg);
|
||||
} else {
|
||||
if (!upload->cancel) {
|
||||
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
|
||||
@@ -327,7 +327,7 @@ http_file_put(void* userdata)
|
||||
if (!fail_msg) {
|
||||
fail_msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
cons_show_error("%s", fail_msg);
|
||||
cons_show_error(fail_msg);
|
||||
} else {
|
||||
switch (upload->window->type) {
|
||||
case WIN_CHAT:
|
||||
|
||||
@@ -938,7 +938,7 @@ cons_show_account_list(gchar** accounts)
|
||||
theme_item_t presence_colour = theme_main_presence_attrs(string_from_resource_presence(presence));
|
||||
win_println(console, presence_colour, "-", "%s", accounts[i]);
|
||||
} else {
|
||||
cons_show("%s", accounts[i]);
|
||||
cons_show(accounts[i]);
|
||||
}
|
||||
}
|
||||
cons_show("");
|
||||
|
||||
@@ -445,7 +445,7 @@ ui_handle_error(const char* const err_msg)
|
||||
GString* msg = g_string_new("");
|
||||
g_string_printf(msg, "Error %s", err_msg);
|
||||
|
||||
cons_show_error("%s", msg->str);
|
||||
cons_show_error(msg->str);
|
||||
|
||||
g_string_free(msg, TRUE);
|
||||
}
|
||||
|
||||
@@ -148,8 +148,7 @@ create_input_window(void)
|
||||
* Fail gracefully instead of aborting in production.
|
||||
*/
|
||||
if (MB_CUR_MAX > PROF_MB_CUR_MAX) {
|
||||
log_error("Locale MB_CUR_MAX (%zu) exceeds compiled limit (%d)", (size_t)MB_CUR_MAX, PROF_MB_CUR_MAX);
|
||||
cons_show_error("Unsupported locale. Before running, execute in terminal: export LC_ALL=C.UTF-8");
|
||||
cons_show_error("Your locale's MB_CUR_MAX (%zu) exceeds PROF_MB_CUR_MAX (%d); input window disabled.", (size_t)MB_CUR_MAX, PROF_MB_CUR_MAX);
|
||||
return;
|
||||
}
|
||||
#ifdef NCURSES_REENTRANT
|
||||
@@ -168,7 +167,7 @@ create_input_window(void)
|
||||
|
||||
inp_win = newpad(1, INP_WIN_MAX);
|
||||
if (!inp_win) {
|
||||
log_error("Failed to allocate input window pad");
|
||||
// Failed to allocate input pad; leave inp_win NULL and avoid further use
|
||||
return;
|
||||
}
|
||||
wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));
|
||||
|
||||
@@ -40,8 +40,6 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#ifdef HAVE_NCURSESW_NCURSES_H
|
||||
#include <ncursesw/ncurses.h>
|
||||
#elif HAVE_NCURSES_H
|
||||
@@ -114,7 +112,6 @@ status_bar_init(void)
|
||||
int row = screen_statusbar_row();
|
||||
int cols = getmaxx(stdscr);
|
||||
if (cols <= 0) {
|
||||
log_warning("status_bar_init: invalid cols %d, defaulting to 1", cols);
|
||||
cols = 1;
|
||||
}
|
||||
statusbar_win = newwin(1, cols, row, 0);
|
||||
@@ -160,7 +157,6 @@ status_bar_resize(void)
|
||||
}
|
||||
int cols = getmaxx(stdscr);
|
||||
if (cols <= 0) {
|
||||
log_warning("status_bar_resize: invalid cols %d, defaulting to 1", cols);
|
||||
cols = 1;
|
||||
}
|
||||
werase(statusbar_win);
|
||||
|
||||
@@ -79,7 +79,15 @@ static void _win_print_wrapped(WINDOW* win, const char* const message, size_t in
|
||||
static int
|
||||
_check_subwin_width(int cols, int width)
|
||||
{
|
||||
return cols <= 1 ? 1 : CLAMP(width, 1, cols - 1);
|
||||
if (cols > 1) {
|
||||
if (width < 1)
|
||||
width = 1;
|
||||
if (width >= cols)
|
||||
width = cols - 1;
|
||||
} else {
|
||||
width = 1;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -2289,7 +2297,7 @@ void
|
||||
win_handle_command_exec_result_note(ProfWin* window, const char* const type, const char* const value)
|
||||
{
|
||||
assert(window != NULL);
|
||||
win_println(window, THEME_DEFAULT, "!", "%s", value);
|
||||
win_println(window, THEME_DEFAULT, "!", value);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -2532,6 +2532,9 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
|
||||
xmpp_stanza_t* child = xmpp_stanza_get_children(query);
|
||||
if (child == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (child) {
|
||||
const char* stanza_name = xmpp_stanza_get_name(child);
|
||||
|
||||
@@ -868,7 +868,7 @@ _handle_error(xmpp_stanza_t* const stanza)
|
||||
g_string_append(log_msg, " error=");
|
||||
g_string_append(log_msg, err_msg);
|
||||
|
||||
log_info("%s", log_msg->str);
|
||||
log_info(log_msg->str);
|
||||
|
||||
g_string_free(log_msg, TRUE);
|
||||
|
||||
|
||||
@@ -455,7 +455,7 @@ _presence_error_handler(xmpp_stanza_t* const stanza)
|
||||
g_string_append(log_msg, " error=");
|
||||
g_string_append(log_msg, err_msg);
|
||||
|
||||
log_info("%s", log_msg->str);
|
||||
log_info(log_msg->str);
|
||||
|
||||
g_string_free(log_msg, TRUE);
|
||||
|
||||
|
||||
@@ -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:
|
||||
@@ -52,9 +52,6 @@
|
||||
#include "test_software.h"
|
||||
#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 */
|
||||
#define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test)
|
||||
@@ -107,20 +104,6 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(display_software_version_result_when_from_domainpart),
|
||||
PROF_FUNC_TEST(show_message_in_chat_window_when_no_resource),
|
||||
PROF_FUNC_TEST(display_software_version_result_in_chat),
|
||||
|
||||
/* 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),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
@@ -155,7 +138,7 @@ main(int argc, char* argv[])
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 3: Presence, Disconnect, Disco
|
||||
* GROUP 3: Presence, Disconnect
|
||||
* Online/away/xa/dnd/chat status management
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group3_tests[] = {
|
||||
@@ -177,22 +160,6 @@ main(int argc, char* argv[])
|
||||
|
||||
/* Disconnect - clean session termination */
|
||||
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),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
@@ -221,10 +188,6 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(shows_first_message_in_console_when_window_not_focussed),
|
||||
PROF_FUNC_TEST(shows_no_message_in_console_when_window_not_focussed),
|
||||
|
||||
/* MUC moderation - XEP-0045 room admin */
|
||||
PROF_FUNC_TEST(sends_affiliation_list_request),
|
||||
PROF_FUNC_TEST(sends_kick_request),
|
||||
|
||||
/* Message Carbons - XEP-0280 (message sync across devices) */
|
||||
PROF_FUNC_TEST(send_enable_carbons),
|
||||
PROF_FUNC_TEST(connect_with_carbons_enabled),
|
||||
@@ -240,9 +203,9 @@ 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 3: Presence/Disconnect", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 4: MUC/Carbons", group4_tests, ARRAY_SIZE(group4_tests) },
|
||||
};
|
||||
const int num_groups = ARRAY_SIZE(groups);
|
||||
|
||||
@@ -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,420 +0,0 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
void
|
||||
disco_info_shows_identity(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.
|
||||
*/
|
||||
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'>"
|
||||
"<error type='cancel'>"
|
||||
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
|
||||
"</error>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info offline.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_regex("Service discovery failed.*service-unavailable"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/* 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);
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* test_lastactivity.c
|
||||
* Functional tests for Last Activity (XEP-0012)
|
||||
*/
|
||||
#include <glib.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
void
|
||||
responds_to_last_activity_request(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
// Send incoming last activity request
|
||||
stbbr_send(
|
||||
"<iq id='last1' type='get' to='stabber@localhost/profanity' from='buddy1@localhost/mobile'>"
|
||||
"<query xmlns='jabber:iq:last'/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
// Verify that CProof responds with last activity info
|
||||
// The 'seconds' attribute indicates idle time
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='last1' type='result' to='buddy1@localhost/mobile'>"
|
||||
"<query xmlns='jabber:iq:last' seconds='*'/>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
last_activity_request_to_contact(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_send(
|
||||
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
|
||||
"<priority>10</priority>"
|
||||
"<status>I'm here</status>"
|
||||
"</presence>"
|
||||
);
|
||||
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
|
||||
|
||||
// Register response for last activity query
|
||||
stbbr_for_query("jabber:iq:last",
|
||||
"<iq id='*' type='result' from='buddy1@localhost/mobile' to='stabber@localhost/profanity'>"
|
||||
"<query xmlns='jabber:iq:last' seconds='120'/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/lastactivity get buddy1@localhost/mobile");
|
||||
|
||||
// Verify the request was sent
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='buddy1@localhost/mobile' type='get'>"
|
||||
"<query xmlns='jabber:iq:last'/>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
/*
|
||||
* test_lastactivity.h
|
||||
* Header for Last Activity tests (XEP-0012)
|
||||
*/
|
||||
|
||||
void responds_to_last_activity_request(void **state);
|
||||
void last_activity_request_to_contact(void **state);
|
||||
@@ -393,83 +393,3 @@ shows_no_message_in_console_when_window_not_focussed(void **state)
|
||||
assert_false(prof_output_regex("testroom@conference\\.localhost \\(win 2\\)"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
sends_affiliation_list_request(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='moderator' jid='stabber@localhost/profanity' affiliation='owner'/>"
|
||||
"</x>"
|
||||
"<status code='110'/>"
|
||||
"</presence>"
|
||||
);
|
||||
|
||||
prof_input("/join testroom@conference.localhost");
|
||||
assert_true(prof_output_regex("-> You have joined the room as stabber, role: moderator, affiliation: owner"));
|
||||
|
||||
prof_input("/affiliation owner list");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='testroom@conference.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/muc#admin'>"
|
||||
"<item affiliation='owner'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
sends_kick_request(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
// Enable MUC presence messages to see occupant join/leave
|
||||
prof_input("/presence room all");
|
||||
assert_true(prof_output_regex("All presence updates will appear"));
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='moderator' jid='stabber@localhost/profanity' affiliation='admin'/>"
|
||||
"</x>"
|
||||
"<status code='110'/>"
|
||||
"</presence>"
|
||||
);
|
||||
|
||||
prof_input("/join testroom@conference.localhost");
|
||||
assert_true(prof_output_regex("-> You have joined the room as stabber, role: moderator, affiliation: admin"));
|
||||
|
||||
// Simulate another user in the room
|
||||
stbbr_send(
|
||||
"<presence to='stabber@localhost/profanity' from='testroom@conference.localhost/baduser'>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='baduser@localhost/phone' affiliation='none'/>"
|
||||
"</x>"
|
||||
"</presence>"
|
||||
);
|
||||
sleep(1);
|
||||
assert_true(prof_output_regex("baduser has joined"));
|
||||
|
||||
// Register success response for kick
|
||||
stbbr_for_query("http://jabber.org/protocol/muc#admin",
|
||||
"<iq id='*' type='result' from='testroom@conference.localhost'/>"
|
||||
);
|
||||
|
||||
prof_input("/kick baduser \"spamming\"");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='testroom@conference.localhost' type='set'>"
|
||||
"<query xmlns='http://jabber.org/protocol/muc#admin'>"
|
||||
"<item nick='baduser' role='none'>"
|
||||
"<reason>spamming</reason>"
|
||||
"</item>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -12,5 +12,3 @@ void shows_me_message_from_self(void **state);
|
||||
void shows_all_messages_in_console_when_window_not_focussed(void **state);
|
||||
void shows_first_message_in_console_when_window_not_focussed(void **state);
|
||||
void shows_no_message_in_console_when_window_not_focussed(void **state);
|
||||
void sends_affiliation_list_request(void **state);
|
||||
void sends_kick_request(void **state);
|
||||
|
||||
Reference in New Issue
Block a user