Compare commits

..

4 Commits

Author SHA1 Message Date
d081993c90 fix: address PR #98 review feedback
All checks were successful
CI Code / Check spelling (pull_request) Successful in 23s
CI Code / Check coding style (pull_request) Successful in 34s
CI Code / Code Coverage (pull_request) Successful in 4m48s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m14s
CI Code / Linux (debian) (pull_request) Successful in 6m15s
CI Code / Linux (arch) (pull_request) Successful in 6m35s
- check-cwe134.sh: match gchar* in addition to char* in variadic pattern
- rosterwin.c: merge duplicated if/else into single condition
- omemo.c: remove unnecessary scope block and goto, use early return
2026-03-07 13:32:02 +03:00
4ef3bc8e46 Add low-impact warning flags, fix warnings found by new flags
All checks were successful
CI Code / Check spelling (pull_request) Successful in 16s
CI Code / Check coding style (pull_request) Successful in 33s
CI Code / Code Coverage (pull_request) Successful in 4m48s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m20s
CI Code / Linux (debian) (pull_request) Successful in 6m22s
CI Code / Linux (arch) (pull_request) Successful in 11m47s
Add compiler flags: -Wundef, -Wfloat-equal, -Wredundant-decls, -Walloc-zero.

Fix -Wredundant-decls warnings:
- Remove stale cons_show_desktop_prefs declaration (ui.h)
- Remove duplicate connection_set_priority prototype (connection.h)
- Remove stale omemo_devicelist_configure_and_request declaration (omemo.h)

Fix potential buffer overflow in stanza.c:
- Increase pri_str and idle_str buffers from 10 to 12 bytes
  (INT_MIN = -2147483648 needs 12 bytes including NUL)
2026-03-04 22:28:16 +03:00
bb6d29a060 Harden compiler flags, simplify CWE-134 script, fix bugs found by new warnings
configure.ac:
- Replace basic -Wformat/-Wformat-nonliteral with -Wformat=2
- Add -Wextra, -Wnull-dereference, -Wpointer-arith, -Wimplicit-function-declaration
- Add -fstack-protector-strong, -fno-common, -D_FORTIFY_SOURCE=2
- Add GCC-specific flags via AC_COMPILE_IFELSE: -Wlogical-op, -Wduplicated-cond,
  -Wduplicated-branches, -Wstringop-overflow
- Add linker hardening via AC_LINK_IFELSE: -Wl,-z,relro -Wl,-z,now
- Suppress noisy -Wextra sub-warnings: -Wno-unused-parameter,
  -Wno-missing-field-initializers, -Wno-sign-compare, -Wno-cast-function-type
- Remove AM_CFLAGS/CFLAGS duplication line

check-cwe134.sh:
- Reduce from 5 checks to 2 (checks 1-3 are now redundant with -Wformat=2)
- Check 1: verify known wrappers have G_GNUC_PRINTF attribute
- Check 2: auto-detect unannotated variadic printf-like functions

Bug fixes found by -Wduplicated-branches:
- chatlog.c: non-MUCPM redact path passed resourcepart instead of NULL
- rosterwin.c: two instances of if/else with identical branches in roster count
- omemo.c: redundant else-if branch in omemo_automatic_start

Other fixes for new warnings:
- console.c: pointer compared to integer 0 instead of NULL (2 instances)
- vcard.c: NULL guard for filename before g_file_set_contents
- files.c: refactor to early return, eliminating NULL logfile path
- database.c: const-correctness for type, query, sort variables
- form.c/xmpp.h: const-correctness for form_set_value parameter
- muc.c/muc.h: remove meaningless top-level const on return type
- common.c: const-correctness for URL string literal
- xmpp/omemo.c: scope block for declarations after goto, move from decl
  before goto, replace goto with direct return
- http_common.h: add G_GNUC_PRINTF attributes for http_print_transfer*
- test_common.c: add currb NULL check to silence -Wnull-dereference
2026-03-04 21:18:35 +03:00
92953099e1 fix: CWE-134 format string vulnerability audit
All checks were successful
CI Code / Check spelling (pull_request) Successful in 21s
CI Code / Check coding style (pull_request) Successful in 38s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m25s
CI Code / Linux (debian) (pull_request) Successful in 9m11s
CI Code / Code Coverage (pull_request) Successful in 9m13s
CI Code / Linux (arch) (pull_request) Successful in 11m27s
Security:
- Fix CWE-134 in iq.c: user-controlled string passed as format arg

Annotations:
- Add G_GNUC_PRINTF to variadic functions in ui.h and log.h

Compiler flags (configure.ac):
- Add -Wformat -Wformat-nonliteral -Wno-format-zero-length

Format mismatch fixes:
- chatwin.c: Jid* instead of char* for %s
- connection.c: %x -> %lx for long flags
- cmd_funcs.c: %d -> %zu for MB_CUR_MAX/MB_LEN_MAX (size_t)
- cmd_funcs.c: cast gpointer to (char*) for %s
- cmd_defs.c: %d -> %u for g_list_length() (guint)
- iq.c: from_jid->barejid -> from_jid->fulljid
- console.c, mucwin.c, privwin.c, account.c, omemo.c, presence.c:
  gpointer -> (char*) casts for %s

Bug fixes:
- api.c: broken log_warning() calls with extra format arg
- cmd_funcs.c: remove unused arg from cons_show()

Tooling:
- Expand check-cwe134.sh detection patterns
2026-03-03 16:29:25 +03:00
10 changed files with 95 additions and 737 deletions

View File

@@ -29,10 +29,10 @@ jobs:
name: Linux
steps:
- uses: actions/checkout@v4
- name: Build
run: docker build -f Dockerfile.${{ matrix.flavor }} -t profanity .
- name: Run tests
run: docker run profanity ./ci-build.sh
run: |
docker build -f Dockerfile.${{ matrix.flavor }} -t profanity .
docker run profanity ./ci-build.sh
code-style:
runs-on: ubuntu-latest
@@ -107,7 +107,7 @@ jobs:
name: Code Coverage
steps:
- uses: actions/checkout@v4
- name: Build
run: docker build -f Dockerfile.arch -t profanity-cov .
- name: Run coverage
run: docker run profanity-cov ./ci-build.sh --coverage-only
- name: Build and run coverage
run: |
docker build -f Dockerfile.arch -t profanity-cov .
docker run profanity-cov ./ci-build.sh --coverage-only

View File

@@ -186,8 +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
main_source = src/main.c

View File

@@ -86,6 +86,7 @@ extract_test_count() {
# and checks that the test framework reports the failure correctly
verify_test_failure_detection()
{
echo
echo "==> Verifying test failure detection..."
# Create a simple failing test
@@ -204,13 +205,6 @@ case "$ARCH" in
""
)
source /etc/profile.d/debuginfod.sh 2>/dev/null || true
if grep -q 'ID=arch' /etc/os-release 2>/dev/null && [ -f /etc/makepkg.conf ]; then
echo "--> [Parity Mode] Simulating Pikaur collision..."
set -a
source /etc/makepkg.conf
set +a
fi
;;
darwin*)
# 4 configurations for parallel CI

View File

@@ -387,11 +387,12 @@ AC_SUBST([FORKPTY_LIB])
## Default parameters
AM_CFLAGS="$AM_CFLAGS -Wall -Wextra -Wformat=2 -Wno-format-zero-length"
AM_CFLAGS="$AM_CFLAGS -Wno-deprecated-declarations -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-cast-function-type"
AM_CFLAGS="$AM_CFLAGS -Wpointer-arith"
AM_CFLAGS="$AM_CFLAGS -Wnull-dereference -Wpointer-arith"
AM_CFLAGS="$AM_CFLAGS -Wimplicit-function-declaration"
AM_CFLAGS="$AM_CFLAGS -Wundef"
AM_CFLAGS="$AM_CFLAGS -Wfloat-equal -Wredundant-decls"
AM_CFLAGS="$AM_CFLAGS -fstack-protector-strong -fno-common"
AM_CFLAGS="$AM_CFLAGS -D_FORTIFY_SOURCE=2"
AM_CFLAGS="$AM_CFLAGS -std=gnu99 -ggdb3"
# GCC-specific warnings (not supported by clang) — test each one

View File

@@ -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,8 +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 */
#define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test)
@@ -111,16 +109,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),
};
/* ============================================================
@@ -155,7 +143,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 +165,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),
};
/* ============================================================
@@ -240,9 +212,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);

View File

@@ -12,7 +12,6 @@
#include <fcntl.h>
#include <sys/select.h>
#include <regex.h>
#include <signal.h>
#include <stabber.h>
@@ -21,41 +20,11 @@
/* Number of parallel test groups for CI builds */
#define TEST_GROUPS 4
/* Number of ports reserved per test group; allows skipping TIME_WAIT ports */
#define PORTS_PER_GROUP 50
/* Base port and fallback scan range for stabber */
#define BASE_PORT 5230
#define FALLBACK_PORT_RANGE (TEST_GROUPS * PORTS_PER_GROUP)
/* Shutdown polling: interval and maximum attempts before escalating signals */
#define MS_TO_US 1000
#define SHUTDOWN_POLL_MS 50
#define SHUTDOWN_POLL_MAX 100 /* 100 x 50ms = 5s */
#define SIGTERM_POLL_MAX 20 /* 20 x 50ms = 1s */
#define QUIT_GRACE_MS 100 /* grace for /quit to be read from pty */
#define INIT_WAIT_MS 50 /* wait for child process to initialize */
#define INPUT_DELAY_MS 10 /* let profanity process input */
#define OUTPUT_POLL_MS 50 /* polling interval for output checks */
#define READ_TIMEOUT_MS 100 /* select() timeout for pty reads */
/* Expect timeouts (seconds) */
#define EXPECT_TIMEOUT_DEFAULT 30
#define EXPECT_TIMEOUT_CONNECT 60
/* Terminal dimensions for forkpty */
#define PTY_ROWS 24
#define PTY_COLS 300
/* Preprocessor stringification (for setenv from numeric #define) */
#define STRINGIFY_(x) #x
#define STRINGIFY(x) STRINGIFY_(x)
char *config_orig;
char *data_orig;
int fd = 0;
int stub_port = BASE_PORT;
int stub_port = 5230;
pid_t child_pid = 0;
/*
@@ -75,7 +44,7 @@ static char output_buffer[OUTPUT_BUF_SIZE];
static size_t output_len = 0;
/* Timeout for expect operations in seconds */
static int expect_timeout = EXPECT_TIMEOUT_DEFAULT;
static int expect_timeout = 30;
gboolean
_create_dir(const char *name)
@@ -184,12 +153,6 @@ _cleanup_dirs(void)
}
}
static void
sleep_ms(int ms)
{
usleep(ms * MS_TO_US);
}
/*
* Read available data from fd into output_buffer with timeout.
* Returns number of bytes read, 0 on timeout, -1 on error.
@@ -203,8 +166,8 @@ _read_output(int timeout_ms)
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
tv.tv_sec = timeout_ms / MS_TO_US;
tv.tv_usec = (timeout_ms % MS_TO_US) * MS_TO_US;
tv.tv_sec = timeout_ms / 1000;
tv.tv_usec = (timeout_ms % 1000) * 1000;
int ret = select(fd + 1, &readfds, NULL, NULL, &tv);
if (ret <= 0) {
@@ -235,8 +198,8 @@ void
prof_start(void)
{
struct winsize ws;
ws.ws_row = PTY_ROWS;
ws.ws_col = PTY_COLS;
ws.ws_row = 24;
ws.ws_col = 300; /* Match COLUMNS=300 from start_profanity.sh */
ws.ws_xpixel = 0;
ws.ws_ypixel = 0;
@@ -253,7 +216,7 @@ prof_start(void)
if (child_pid == 0) {
/* Child process */
setenv("COLUMNS", STRINGIFY(PTY_COLS), 1);
setenv("COLUMNS", "300", 1);
setenv("TERM", "xterm", 1);
execl("./profanity", "./profanity", "-l", "DEBUG", NULL);
@@ -269,7 +232,7 @@ prof_start(void)
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
/* Brief wait for process to initialize */
sleep_ms(INIT_WAIT_MS);
usleep(50000); /* 50ms */
}
int
@@ -283,41 +246,38 @@ init_prof_test(void **state)
const char *build_env = getenv("PROF_BUILD_INDEX");
int build_idx = build_env ? atoi(build_env) : 0;
/* Calculate port base: each build uses a different range of
* TEST_GROUPS * PORTS_PER_GROUP ports.
* Build 0 (local/default): 5230-5429, Full: 5230-5429, Minimal: 5430-5629, etc.
* Build 0 and Full share the same range because build 0 is for local runs
* or sequential run (no parallel builds), while Full/Minimal/NoEncrypt/Default
* are used in CI where they run in parallel. */
int port_base = BASE_PORT + ((build_idx > 0 ? build_idx - 1 : 0) * TEST_GROUPS * PORTS_PER_GROUP);
/* Calculate port base: each build uses a different range of TEST_GROUPS ports.
* Build 0 (local/default): 5230-5233, Full: 5230-5233, Minimal: 5234-5237, etc.
* Build 0 and Full share the same range because build 0 is for local runs or sequential run (no parallel builds),
* while Full/Minimal/NoEncrypt/Default are used in CI where they run in parallel. */
int port_base = 5230 + ((build_idx > 0 ? build_idx - 1 : 0) * TEST_GROUPS);
/* Each group gets a dedicated range of ports for parallel execution.
* Group 1: port_base..port_base+PORTS_PER_GROUP-1
* Group 2: port_base+PORTS_PER_GROUP..port_base+2*PORTS_PER_GROUP-1, etc.
* Ports in TIME_WAIT from previous tests are skipped automatically. */
/* Static resource allocation to avoid conflicts in parallel execution.
* Group 1-4: use static port assignment.
* Group 0 (all groups): use dynamic allocation as fallback. */
gboolean started = FALSE;
if (group >= 1 && group <= TEST_GROUPS) {
int group_port_base = port_base + (group - 1) * PORTS_PER_GROUP;
for (int p = group_port_base; p < group_port_base + PORTS_PER_GROUP && !started; p++) {
if (stbbr_start(STBBR_LOGDEBUG, p, 0) == 0) {
stub_port = p;
started = TRUE;
}
}
if (!started) {
fprintf(stderr, "[PROF_TEST] Failed to start stabber on ports %d-%d\n",
group_port_base, group_port_base + PORTS_PER_GROUP - 1);
/* Static allocation: each group gets a dedicated port */
stub_port = port_base + group - 1;
printf("[PROF_TEST] Build %d, Group %d: trying port %d\n", build_idx, group, stub_port);
if (stbbr_start(STBBR_LOGDEBUG, stub_port, 0) == 0) {
started = TRUE;
printf("[PROF_TEST] Started stabber on port %d\n", stub_port);
} else {
printf("[PROF_TEST] Failed to start stabber on port %d\n", stub_port);
}
}
/* Fallback to dynamic allocation if static failed or group=0 */
if (!started) {
for (int p = port_base; p < port_base + FALLBACK_PORT_RANGE; ++p) {
printf("[PROF_TEST] Using dynamic port allocation\n");
for (int p = port_base; p < port_base + 20; ++p) {
if (stbbr_start(STBBR_LOGDEBUG, p, 0) == 0) {
stub_port = p;
started = TRUE;
printf("[PROF_TEST] Started stabber on port %d\n", stub_port);
break;
}
}
@@ -339,6 +299,9 @@ init_prof_test(void **state)
printf("[PROF_TEST] Group %d using directories: config=%s, data=%s\n",
group, xdg_config_home, xdg_data_home);
// Give stabber server thread time to start listening
usleep(100000); // 100ms
config_orig = getenv("XDG_CONFIG_HOME");
data_orig = getenv("XDG_DATA_HOME");
@@ -352,37 +315,38 @@ init_prof_test(void **state)
_create_chatlogs_dir();
_create_logs_dir();
/* Pre-write profrc with UI/notification defaults to ensure consistent,
* deterministic output across tests (no timestamps, no roster/occupants
* panels, low input-blocking delay for fast command processing). */
char profrc_path[512];
snprintf(profrc_path, sizeof(profrc_path),
"%s/profanity/profrc", xdg_config_home);
FILE* prc = fopen(profrc_path, "w");
if (prc) {
fprintf(prc,
"[ui]\n"
"inpblock=5\n"
"inpblock.dynamic=false\n"
"wrap=false\n"
"roster=false\n"
"occupants=false\n"
"time.console=off\n"
"time.chat=off\n"
"time.muc=off\n"
"time.config=off\n"
"time.private=off\n"
"time.xmlconsole=off\n"
"[notifications]\n"
"message=false\n"
"room=false\n");
fclose(prc);
}
prof_start();
int prof_started = prof_output_regex("CProof\\. Type /help for help information\\.");
assert_true(prof_started);
// set UI options to make expect assertions faster and more reliable
prof_input("/inpblock timeout 5");
assert_true(prof_output_regex("Input blocking set to 5 milliseconds"));
prof_input("/inpblock dynamic off");
assert_true(prof_output_regex("Dynamic input blocking disabled"));
prof_input("/notify chat off");
assert_true(prof_output_regex("Chat notifications disabled"));
prof_input("/notify room off");
assert_true(prof_output_regex("Room notifications disabled"));
prof_input("/wrap off");
assert_true(prof_output_regex("Word wrap disabled"));
prof_input("/roster hide");
assert_true(prof_output_regex("Roster disabled"));
prof_input("/occupants default hide");
assert_true(prof_output_regex("Occupant list disabled"));
prof_input("/time console off");
prof_input("/time console off");
assert_true(prof_output_regex("Console time display disabled\\."));
prof_input("/time chat off");
assert_true(prof_output_regex("Chat time display disabled\\."));
prof_input("/time muc off");
assert_true(prof_output_regex("MUC time display disabled\\."));
prof_input("/time config off");
assert_true(prof_output_regex("Config time display disabled\\."));
prof_input("/time private off");
assert_true(prof_output_regex("Private chat time display disabled\\."));
prof_input("/time xml off");
assert_true(prof_output_regex("XML Console time display disabled\\."));
return 0;
}
@@ -391,33 +355,14 @@ close_prof_test(void **state)
{
if (fd > 0 && child_pid > 0) {
prof_input("/quit");
/* Close pty master after brief grace — child gets SIGHUP which
* accelerates shutdown instead of waiting for XMPP disconnect
* timeout (~5s). */
sleep_ms(QUIT_GRACE_MS);
// Give profanity time to process quit command
sleep(1);
waitpid(child_pid, NULL, 0);
close(fd);
fd = 0;
int exited = 0;
for (int i = 0; i < SHUTDOWN_POLL_MAX; i++) {
if (waitpid(child_pid, NULL, WNOHANG) != 0) {
exited = 1;
break;
}
sleep_ms(SHUTDOWN_POLL_MS);
}
if (!exited) {
kill(child_pid, SIGTERM);
for (int i = 0; i < SIGTERM_POLL_MAX; i++) {
if (waitpid(child_pid, NULL, WNOHANG) != 0) { exited = 1; break; }
sleep_ms(SHUTDOWN_POLL_MS);
}
if (!exited) {
kill(child_pid, SIGKILL);
waitpid(child_pid, NULL, 0);
}
}
child_pid = 0;
}
_cleanup_dirs();
if (config_orig) {
setenv("XDG_CONFIG_HOME", config_orig, 1);
@@ -427,6 +372,13 @@ close_prof_test(void **state)
}
stbbr_stop();
/*
* TODO: Replace with proper synchronization.
* stabber doesn't provide wait_stopped() API yet, so we use delay
* to ensure the port is released before the next test starts.
* See: https://git.jabber.space/devs/stabber/issues/3
*/
usleep(100000); // 100ms
return 0;
}
@@ -440,7 +392,7 @@ prof_input(const char *input)
g_string_free(inp_str, TRUE);
/* Small delay to let profanity process input */
sleep_ms(INPUT_DELAY_MS);
usleep(10000);
}
/*
@@ -454,7 +406,7 @@ prof_output_exact(const char *text)
while (time(NULL) - start < expect_timeout) {
/* Read any available output */
while (_read_output(READ_TIMEOUT_MS) > 0) {
while (_read_output(100) > 0) {
/* Keep reading while data available */
}
@@ -463,7 +415,7 @@ prof_output_exact(const char *text)
return 1;
}
sleep_ms(OUTPUT_POLL_MS);
usleep(50000); /* 50ms */
}
return 0;
@@ -488,7 +440,7 @@ prof_output_regex(const char *pattern)
while (time(NULL) - start < expect_timeout) {
/* Read any available output */
while (_read_output(READ_TIMEOUT_MS) > 0) {
while (_read_output(100) > 0) {
/* Keep reading while data available */
}
@@ -499,7 +451,7 @@ prof_output_regex(const char *pattern)
return 1;
}
sleep_ms(OUTPUT_POLL_MS);
usleep(50000); /* 50ms */
}
/* Timeout reached - log diagnostic info */
@@ -541,12 +493,12 @@ prof_connect_with_roster(const char *roster)
assert_true(prof_output_regex("password:"));
prof_input("password");
expect_timeout = EXPECT_TIMEOUT_CONNECT;
expect_timeout = 60;
assert_true(prof_output_regex("Connecting as stabber@localhost"));
assert_true(prof_output_regex("logged in successfully"));
assert_true(prof_output_regex(".+online.+ \\(priority 0\\)\\."));
expect_timeout = EXPECT_TIMEOUT_CONNECT;
expect_timeout = 60;
// Wait for presence stanza to be sent (content-based, not ID-based)
// Match the actual attribute order from stanza_attach_caps
assert_true(stbbr_received(
@@ -565,7 +517,7 @@ prof_timeout(int timeout)
void
prof_timeout_reset(void)
{
expect_timeout = EXPECT_TIMEOUT_CONNECT;
expect_timeout = 60;
}
void

View File

@@ -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"));
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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);