fix/functional_tests #63
2
external/stabber
vendored
2
external/stabber
vendored
Submodule external/stabber updated: 3e5c220071...14b664f4c7
@@ -140,7 +140,7 @@ static const struct cmd_t command_defs[] = {
|
||||
},
|
||||
|
||||
{ CMD_PREAMBLE("/connect",
|
||||
parse_args, 0, 7, NULL)
|
||||
parse_args, 0, 9, NULL)
|
||||
CMD_MAINFUNC(cmd_connect)
|
||||
CMD_TAGS(
|
||||
CMD_TAG_CONNECTION)
|
||||
|
||||
@@ -27,16 +27,16 @@ int main(int argc, char* argv[]) {
|
||||
const struct CMUnitTest all_tests[] = {
|
||||
|
||||
PROF_FUNC_TEST(connect_jid_requests_roster),
|
||||
// PROF_FUNC_TEST(connect_jid_sends_presence_after_receiving_roster),
|
||||
// PROF_FUNC_TEST(connect_jid_requests_bookmarks),
|
||||
// PROF_FUNC_TEST(connect_bad_password),
|
||||
// PROF_FUNC_TEST(connect_shows_presence_updates),
|
||||
PROF_FUNC_TEST(connect_jid_sends_presence_after_receiving_roster),
|
||||
PROF_FUNC_TEST(connect_jid_requests_bookmarks),
|
||||
PROF_FUNC_TEST(connect_bad_password),
|
||||
PROF_FUNC_TEST(connect_shows_presence_updates),
|
||||
|
||||
// PROF_FUNC_TEST(ping_server),
|
||||
// PROF_FUNC_TEST(ping_server_not_supported),
|
||||
// PROF_FUNC_TEST(ping_responds_to_server_request),
|
||||
// PROF_FUNC_TEST(ping_jid),
|
||||
// PROF_FUNC_TEST(ping_jid_not_supported),
|
||||
PROF_FUNC_TEST(ping_server),
|
||||
PROF_FUNC_TEST(ping_server_not_supported),
|
||||
PROF_FUNC_TEST(ping_responds_to_server_request),
|
||||
PROF_FUNC_TEST(ping_jid),
|
||||
PROF_FUNC_TEST(ping_jid_not_supported),
|
||||
|
||||
// PROF_FUNC_TEST(rooms_query),
|
||||
|
||||
|
||||
@@ -139,23 +139,22 @@ prof_start(void)
|
||||
int
|
||||
init_prof_test(void **state)
|
||||
{
|
||||
fprintf(stderr, "\n[TEST] init_prof_test() called\n");
|
||||
gboolean started = FALSE;
|
||||
for (int p = 5230; p < 5250; ++p) {
|
||||
fprintf(stderr, "[TEST] Trying to start stabber on port %d\n", p);
|
||||
if (stbbr_start(STBBR_LOGDEBUG, p, 0) == 0) {
|
||||
stub_port = p;
|
||||
fprintf(stderr, "[TEST] Stabber started successfully on port %d\n", p);
|
||||
started = TRUE;
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "[TEST] Port %d failed, trying next\n", p);
|
||||
}
|
||||
if (!started) {
|
||||
assert_true(FALSE); // could not start stabber on any port in range
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Give stabber server thread time to start listening
|
||||
usleep(100000); // 100ms
|
||||
|
||||
config_orig = getenv("XDG_CONFIG_HOME");
|
||||
data_orig = getenv("XDG_DATA_HOME");
|
||||
|
||||
@@ -206,12 +205,20 @@ init_prof_test(void **state)
|
||||
int
|
||||
close_prof_test(void **state)
|
||||
{
|
||||
prof_input("/quit");
|
||||
waitpid(exp_pid, NULL, 0);
|
||||
if (fd > 0) {
|
||||
prof_input("/quit");
|
||||
// Give profanity time to process quit command
|
||||
sleep(1);
|
||||
waitpid(exp_pid, NULL, 0);
|
||||
}
|
||||
_cleanup_dirs();
|
||||
|
||||
setenv("XDG_CONFIG_HOME", config_orig, 1);
|
||||
setenv("XDG_DATA_HOME", data_orig, 1);
|
||||
if (config_orig) {
|
||||
setenv("XDG_CONFIG_HOME", config_orig, 1);
|
||||
|
jabber.developer marked this conversation as resolved
Outdated
|
||||
}
|
||||
if (data_orig) {
|
||||
setenv("XDG_DATA_HOME", data_orig, 1);
|
||||
}
|
||||
|
||||
stbbr_stop();
|
||||
return 0;
|
||||
@@ -255,67 +262,26 @@ prof_connect_with_roster(const char *roster)
|
||||
stbbr_for_query("jabber:iq:roster", roster_str->str);
|
||||
g_string_free(roster_str, TRUE);
|
||||
|
||||
// Set up stabber to expect password "password"
|
||||
stbbr_auth_passwd("password");
|
||||
|
||||
char connect_cmd[128];
|
||||
snprintf(connect_cmd, sizeof(connect_cmd), "/connect stabber@localhost server 127.0.0.1 port %d tls disable", stub_port);
|
||||
fprintf(stderr, "\n[TEST] Sending connect command: %s\n", connect_cmd);
|
||||
fprintf(stderr, "[TEST] stub_port = %d\n", stub_port);
|
||||
snprintf(connect_cmd, sizeof(connect_cmd), "/connect stabber@localhost server 127.0.0.1 port %d tls disable auth legacy", stub_port);
|
||||
prof_input(connect_cmd);
|
||||
|
||||
// Check password prompt appears
|
||||
assert_true(prof_output_regex("password:"));
|
||||
|
||||
prof_input("password");
|
||||
|
||||
// Allow time for profanity to connect
|
||||
exp_timeout = 60;
|
||||
|
||||
// First check: did we get any connection message?
|
||||
gboolean got_connecting = prof_output_regex("Connecting as stabber@localhost");
|
||||
gboolean got_success = FALSE;
|
||||
gboolean got_failure = FALSE;
|
||||
|
||||
if (got_connecting) {
|
||||
fprintf(stderr, "\nDEBUG: Saw 'Connecting as' message, waiting longer for result...\n");
|
||||
sleep(5); // Give extra time for SASL + bind
|
||||
|
||||
// Try to dump whatever is on the screen by sending Enter and reading response
|
||||
prof_input("");
|
||||
usleep(500000); // 0.5s
|
||||
|
||||
// Now wait for success or failure
|
||||
got_success = prof_output_regex("logged in successfully");
|
||||
if (!got_success) {
|
||||
got_failure = prof_output_regex("failed|Failed|error|Error|disconnect|Disconnect");
|
||||
if (!got_failure) {
|
||||
fprintf(stderr, "\nDEBUG: No success or failure after 5s, sending /who to trigger output...\n");
|
||||
// Send a command to see if connection is actually established
|
||||
prof_input("/who");
|
||||
usleep(500000);
|
||||
got_success = prof_output_regex("logged in successfully|online");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Maybe we went straight to success?
|
||||
got_success = prof_output_regex("logged in successfully");
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nDEBUG: got_connecting=%d got_success=%d got_failure=%d\n",
|
||||
got_connecting, got_success, got_failure);
|
||||
|
||||
if (got_success) {
|
||||
assert_true(prof_output_regex(".+online.+ \\(priority 0\\)\\."));
|
||||
} else {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
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\\)\\."));
|
||||
|
||||
exp_timeout = 10;
|
||||
// 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(
|
||||
"<presence id=\"*\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://profanity-im.github.io/\" ver=\"*\"/>"
|
||||
"<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://profanity-im.github.io\" ver=\"*\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stabber.h>
|
||||
#include <expect.h>
|
||||
@@ -23,26 +24,35 @@ ping_server(void **state)
|
||||
|
||||
// Respond to ping IQs independent of the request id
|
||||
stbbr_for_query("urn:xmpp:ping",
|
||||
"<iq type='result' to='stabber@localhost/profanity'/>"
|
||||
"<iq from='localhost' to='stabber@localhost/profanity' type='result'/>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
// Give profanity time to process disco#info
|
||||
sleep(2);
|
||||
|
||||
prof_input("/ping");
|
||||
// Check that ping IQ was sent
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_ping_4' type='get'>"
|
||||
"<iq id='*' type='get' to='*'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
jabber.developer2 marked this conversation as resolved
Outdated
jabber.developer
commented
What do we test for then in such case? If server supports, then we should expect successful ping, otherwise error. We can't just accept both variants, as it would mean that we don't test functionality. What do we test for then in such case? If server supports, then we should expect successful ping, otherwise error. We can't just accept both variants, as it would mean that we don't test functionality.
jabber.developer
commented
Resolved. Resolved.
|
||||
assert_true(prof_output_exact("Ping response from server"));
|
||||
// Now check for the response message
|
||||
prof_timeout(30);
|
||||
assert_true(prof_output_regex("Ping response from server"));
|
||||
prof_timeout_reset();
|
||||
|
||||
prof_input("/ping");
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_ping_5' type='get'>"
|
||||
"<iq id='*' type='get' to='*'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
assert_true(prof_output_exact("Ping response from server"));
|
||||
prof_timeout(30);
|
||||
assert_true(prof_output_regex("Ping response from server"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -59,7 +69,7 @@ ping_server_not_supported(void **state)
|
||||
prof_connect();
|
||||
|
||||
prof_input("/ping");
|
||||
assert_true(prof_output_exact("Server does not support ping requests."));
|
||||
assert_true(prof_output_regex("Server does not support ping requests"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -68,13 +78,13 @@ ping_responds_to_server_request(void **state)
|
||||
prof_connect();
|
||||
|
||||
stbbr_send(
|
||||
"<iq id='pingtest1' type='get' to='stabber@localhost/profanity' from='localhost'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
|
||||
"<ping xmlns=\"urn:xmpp:ping\"/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='pingtest1' type='result' from='stabber@localhost/profanity' to='localhost'/>"
|
||||
"<iq id='pingtest1' type='result' from='stabber@localhost/profanity' to='localhost'></iq>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -109,7 +119,7 @@ void ping_jid(void **state)
|
||||
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_caps_4' to='buddy1@localhost/mobile' type='get'>"
|
||||
"<iq id='*' to='buddy1@localhost/mobile' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='/>"
|
||||
"</iq>"
|
||||
));
|
||||
@@ -122,11 +132,11 @@ void ping_jid(void **state)
|
||||
prof_input("/ping buddy1@localhost/mobile");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_ping_5' type='get' to='buddy1@localhost/mobile'>"
|
||||
"<iq id='*' type='get' to='buddy1@localhost/mobile'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
assert_true(prof_output_exact("Ping response from buddy1@localhost/mobile"));
|
||||
assert_true(prof_output_regex("Ping response from buddy1@localhost/mobile"));
|
||||
}
|
||||
|
||||
void ping_jid_not_supported(void **state)
|
||||
@@ -158,7 +168,7 @@ void ping_jid_not_supported(void **state)
|
||||
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_caps_4' to='buddy1@localhost/mobile' type='get'>"
|
||||
"<iq id='*' to='buddy1@localhost/mobile' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user
Great addition!