All checks were successful
CI Code / Check spelling (pull_request) Successful in 15s
CI Code / Check coding style (pull_request) Successful in 30s
CI Code / Code Coverage (pull_request) Successful in 3m47s
CI Code / Linux (debian) (pull_request) Successful in 5m11s
CI Code / Linux (ubuntu) (pull_request) Successful in 5m16s
CI Code / Linux (arch) (pull_request) Successful in 7m9s
The new test verifies that disco#info responses from subdomain services (e.g., conference servers) do not trigger the autoping warning, ensuring the check is correctly restricted to the server's own domain.
256 lines
7.3 KiB
C
256 lines
7.3 KiB
C
#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"));
|
|
}
|
|
|
|
/*
|
|
* Autoping availability warning.
|
|
*
|
|
* The warning fires from the on-connect disco handler, so the three inputs
|
|
* (server ping support, autoping interval, warning preference) must all be
|
|
* set before prof_connect().
|
|
*/
|
|
|
|
/* Stable substring of the warning text emitted by iq.c. */
|
|
#define AUTOPING_WARNING_MATCH "This server supports XEP-0199"
|
|
|
|
static void
|
|
_stub_server_disco(gboolean with_ping)
|
|
{
|
|
if (with_ping) {
|
|
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>"
|
|
);
|
|
} else {
|
|
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>"
|
|
);
|
|
}
|
|
}
|
|
|
|
void
|
|
autoping_warning_shown_when_disabled(void** state)
|
|
{
|
|
// All conditions met: server supports ping, autoping off, warning on (default).
|
|
_stub_server_disco(TRUE);
|
|
|
|
prof_input("/autoping set 0");
|
|
assert_true(prof_output_exact("Autoping disabled."));
|
|
|
|
prof_connect();
|
|
|
|
assert_true(prof_output_regex(AUTOPING_WARNING_MATCH));
|
|
}
|
|
|
|
void
|
|
autoping_warning_not_shown_when_server_unsupported(void** state)
|
|
{
|
|
// Server does not advertise urn:xmpp:ping -> no warning even with autoping off.
|
|
_stub_server_disco(FALSE);
|
|
|
|
prof_input("/autoping set 0");
|
|
assert_true(prof_output_exact("Autoping disabled."));
|
|
|
|
prof_connect();
|
|
|
|
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
|
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
|
}
|
|
|
|
void
|
|
autoping_warning_not_shown_when_autoping_enabled(void** state)
|
|
{
|
|
// Warning is suppressed while autoping is enabled.
|
|
_stub_server_disco(TRUE);
|
|
|
|
prof_input("/autoping set 30");
|
|
assert_true(prof_output_exact("Autoping interval set to 30 seconds."));
|
|
|
|
prof_connect();
|
|
|
|
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
|
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
|
}
|
|
|
|
void
|
|
autoping_warning_not_shown_when_user_disabled(void** state)
|
|
{
|
|
// User opted out -> no warning.
|
|
_stub_server_disco(TRUE);
|
|
|
|
prof_input("/autoping set 0");
|
|
assert_true(prof_output_exact("Autoping disabled."));
|
|
|
|
prof_input("/autoping warning off");
|
|
assert_true(prof_output_exact("Autoping availability warning disabled."));
|
|
|
|
prof_connect();
|
|
|
|
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
|
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
|
}
|
|
|
|
void
|
|
autoping_warning_not_shown_for_user_jid(void** state)
|
|
{
|
|
// disco#info from a user JID (with '@') should not trigger the warning,
|
|
// only server responses (no '@') should.
|
|
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
|
"<iq to='stabber@localhost/profanity' type='result' from='buddy1@localhost'>"
|
|
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
|
"<identity category='person' type='chat' name='Buddy1'/>"
|
|
"<feature var='urn:xmpp:ping'/>"
|
|
"</query>"
|
|
"</iq>"
|
|
);
|
|
|
|
prof_input("/autoping set 0");
|
|
assert_true(prof_output_exact("Autoping disabled."));
|
|
|
|
prof_connect();
|
|
|
|
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
|
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
|
}
|
|
|
|
void
|
|
autoping_warning_not_shown_for_subdomain_service(void** state)
|
|
{
|
|
// disco#info from a subdomain service should not trigger the warning, only the server's own domain should
|
|
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
|
"<iq to='stabber@localhost/profanity' type='result' from='conf.localhost'>"
|
|
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
|
"<identity category='conference' type='text' name='Conference Service'/>"
|
|
"<feature var='urn:xmpp:ping'/>"
|
|
"</query>"
|
|
"</iq>"
|
|
);
|
|
|
|
prof_input("/autoping set 0");
|
|
assert_true(prof_output_exact("Autoping disabled."));
|
|
|
|
prof_connect();
|
|
|
|
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
|
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
|
}
|