tests: add remote server message tests
Test sendto_one, sendto_one_prefix, sendto_one_notice and complete sendto_one_numeric (for unregistered clients).
This commit is contained in:
parent
6af47466a8
commit
60f1d711e6
5 changed files with 270 additions and 13 deletions
|
@ -23,10 +23,11 @@
|
|||
#include <unistd.h>
|
||||
#include "tap/basic.h"
|
||||
|
||||
#include "stdinc.h"
|
||||
#include "ircd_defs.h"
|
||||
#include "client_util.h"
|
||||
|
||||
#include "hash.h"
|
||||
#include "s_newconf.h"
|
||||
|
||||
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
|
||||
|
||||
struct Client *make_local_person(void)
|
||||
|
@ -47,8 +48,8 @@ struct Client *make_local_person_full(const char *nick, const char *username, co
|
|||
rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list);
|
||||
client->servptr = &me;
|
||||
rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users);
|
||||
SetClient(client);
|
||||
make_user(client);
|
||||
SetClient(client);
|
||||
|
||||
rb_inet_pton_sock(ip, (struct sockaddr *)&client->localClient->ip);
|
||||
rb_strlcpy(client->name, nick, sizeof(client->name));
|
||||
|
@ -57,6 +58,8 @@ struct Client *make_local_person_full(const char *nick, const char *username, co
|
|||
rb_inet_ntop_sock((struct sockaddr *)&client->localClient->ip, client->sockhost, sizeof(client->sockhost));
|
||||
rb_strlcpy(client->info, realname, sizeof(client->info));
|
||||
|
||||
add_to_client_hash(client->name, client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
|
@ -72,6 +75,92 @@ void remove_local_person(struct Client *client)
|
|||
exit_client(NULL, client, &me, "Test client removed");
|
||||
}
|
||||
|
||||
struct Client *make_remote_server(struct Client *uplink)
|
||||
{
|
||||
return make_remote_server_name(uplink, TEST_SERVER_NAME);
|
||||
}
|
||||
|
||||
struct Client *make_remote_server_name(struct Client *uplink, const char *name)
|
||||
{
|
||||
return make_remote_server_full(uplink, name, "");
|
||||
}
|
||||
|
||||
struct Client *make_remote_server_full(struct Client *uplink, const char *name, const char *id)
|
||||
{
|
||||
struct Client *client;
|
||||
|
||||
client = make_client(NULL);
|
||||
client->servptr = uplink;
|
||||
|
||||
attach_server_conf(client, find_server_conf(name));
|
||||
|
||||
rb_strlcpy(client->name, name, sizeof(client->name));
|
||||
rb_strlcpy(client->id, id, sizeof(client->id));
|
||||
|
||||
rb_dlinkAdd(client, &client->lnode, &uplink->serv->servers);
|
||||
rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &serv_list);
|
||||
rb_dlinkAddTailAlloc(client, &global_serv_list);
|
||||
|
||||
make_server(client);
|
||||
SetServer(client);
|
||||
|
||||
add_to_client_hash(client->name, client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
struct Client *make_remote_person(struct Client *server)
|
||||
{
|
||||
return make_remote_person_nick(server, TEST_REMOTE_NICK);
|
||||
}
|
||||
|
||||
struct Client *make_remote_person_nick(struct Client *server, const char *nick)
|
||||
{
|
||||
return make_remote_person_full(server, nick, TEST_USERNAME, TEST_HOSTNAME, TEST_IP, TEST_REALNAME);
|
||||
}
|
||||
|
||||
struct Client *make_remote_person_full(struct Client *server, const char *nick, const char *username, const char *hostname, const char *ip, const char *realname)
|
||||
{
|
||||
struct Client *client;
|
||||
struct sockaddr addr;
|
||||
|
||||
client = make_client(server);
|
||||
make_user(client);
|
||||
SetRemoteClient(client);
|
||||
|
||||
client->servptr = server;
|
||||
rb_dlinkAdd(server, &server->lnode, &server->servptr->serv->users);
|
||||
|
||||
rb_inet_pton_sock(ip, &addr);
|
||||
rb_strlcpy(client->name, nick, sizeof(client->name));
|
||||
rb_strlcpy(client->username, username, sizeof(client->username));
|
||||
rb_strlcpy(client->host, hostname, sizeof(client->host));
|
||||
rb_inet_ntop_sock(&addr, client->sockhost, sizeof(client->sockhost));
|
||||
rb_strlcpy(client->info, realname, sizeof(client->info));
|
||||
|
||||
add_to_client_hash(nick, client);
|
||||
add_to_hostname_hash(client->host, client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
void make_remote_person_oper(struct Client *client)
|
||||
{
|
||||
rb_dlinkAddAlloc(client, &oper_list);
|
||||
SetOper(client);
|
||||
}
|
||||
|
||||
void remove_remote_person(struct Client *client)
|
||||
{
|
||||
exit_client(client, client->servptr, client->servptr, "Test client removed");
|
||||
}
|
||||
|
||||
void remove_remote_server(struct Client *server)
|
||||
{
|
||||
exit_client(server, server, server->servptr, "Test server removed");
|
||||
}
|
||||
|
||||
|
||||
char *get_client_sendq(const struct Client *client)
|
||||
{
|
||||
static char buf[EXT_BUFSIZE + sizeof(CRLF)];
|
||||
|
|
|
@ -27,11 +27,22 @@
|
|||
#include "msg.h"
|
||||
#include "client.h"
|
||||
|
||||
#define TEST_NICK "test"
|
||||
#include "ircd_util.h"
|
||||
|
||||
#define TEST_NICK "local_test"
|
||||
#define TEST_USERNAME "username"
|
||||
#define TEST_HOSTNAME "example.test"
|
||||
#define TEST_IP "2001:db8::1:5ee:bad:c0de"
|
||||
#define TEST_REALNAME "Test user"
|
||||
#define TEST_ID TEST_ME_ID "00000"
|
||||
|
||||
#define TEST_ID_SUFFIX "!" TEST_USERNAME "@" TEST_HOSTNAME
|
||||
|
||||
#define TEST_SERVER_NAME "remote.test"
|
||||
#define TEST_SERVER_ID "1BB"
|
||||
|
||||
#define TEST_REMOTE_NICK "remote_test"
|
||||
#define TEST_REMOTE_ID TEST_SERVER_ID "00001"
|
||||
|
||||
#define CRLF "\r\n"
|
||||
|
||||
|
@ -44,6 +55,16 @@ struct Client *make_local_person_full(const char *nick, const char *username, co
|
|||
void make_local_person_oper(struct Client *client);
|
||||
void remove_local_person(struct Client *client);
|
||||
|
||||
struct Client *make_remote_server(struct Client *uplink);
|
||||
struct Client *make_remote_server_name(struct Client *uplink, const char *name);
|
||||
struct Client *make_remote_server_full(struct Client *uplink, const char *name, const char *id);
|
||||
struct Client *make_remote_person(struct Client *server);
|
||||
struct Client *make_remote_person_nick(struct Client *server, const char *nick);
|
||||
struct Client *make_remote_person_full(struct Client *server, const char *nick, const char *username, const char *hostname, const char *ip, const char *realname);
|
||||
void make_remote_person_oper(struct Client *client);
|
||||
void remove_remote_person(struct Client *client);
|
||||
void remove_remote_server(struct Client *server);
|
||||
|
||||
char *get_client_sendq(const struct Client *client);
|
||||
|
||||
#define is_client_sendq_empty(client, message, ...) do { \
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "ircd_defs.h"
|
||||
|
||||
#define TEST_ME_NAME "me.test"
|
||||
#define TEST_ME_ID "0AA"
|
||||
|
||||
void ircd_util_init(const char *name);
|
||||
void ircd_util_free(void);
|
||||
|
|
158
tests/send1.c
158
tests/send1.c
|
@ -30,14 +30,151 @@
|
|||
|
||||
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
|
||||
|
||||
static struct Client *user;
|
||||
static struct Client *server;
|
||||
static struct Client *remote;
|
||||
|
||||
static void standard_init(void)
|
||||
{
|
||||
user = make_local_person();
|
||||
server = make_remote_server(&me);
|
||||
remote = make_remote_person(server);
|
||||
}
|
||||
|
||||
static void standard_ids(void)
|
||||
{
|
||||
strcpy(user->id, TEST_ID);
|
||||
strcpy(server->id, TEST_SERVER_ID);
|
||||
strcpy(remote->id, TEST_REMOTE_ID);
|
||||
}
|
||||
|
||||
static void standard_free(void)
|
||||
{
|
||||
remove_local_person(user);
|
||||
remove_remote_person(remote);
|
||||
remove_remote_server(server);
|
||||
}
|
||||
|
||||
static void sendto_one1(void)
|
||||
{
|
||||
standard_init();
|
||||
|
||||
sendto_one(user, "Hello %s!", "World");
|
||||
is_client_sendq("Hello World!" CRLF, user, MSG);
|
||||
|
||||
sendto_one(server, "Hello %s!", "World");
|
||||
is_client_sendq("Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one(remote, "Hello %s!", "World");
|
||||
is_client_sendq("Hello World!" CRLF, server, MSG);
|
||||
|
||||
standard_free();
|
||||
}
|
||||
|
||||
static void sendto_one_prefix1(void)
|
||||
{
|
||||
standard_init();
|
||||
|
||||
// Local
|
||||
sendto_one_prefix(user, &me, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " TEST " TEST_NICK " :Hello World!" CRLF, user, MSG);
|
||||
|
||||
sendto_one_prefix(user, user, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_NICK " TEST " TEST_NICK " :Hello World!" CRLF, user, MSG);
|
||||
|
||||
sendto_one_prefix(user, remote, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_REMOTE_NICK " TEST " TEST_NICK " :Hello World!" CRLF, user, MSG);
|
||||
|
||||
sendto_one_prefix(user, server, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_SERVER_NAME " TEST " TEST_NICK " :Hello World!" CRLF, user, MSG);
|
||||
|
||||
// Remote (without ID)
|
||||
sendto_one_prefix(remote, &me, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " TEST " TEST_REMOTE_NICK " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_prefix(remote, user, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_NICK " TEST " TEST_REMOTE_NICK " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_prefix(remote, remote, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_REMOTE_NICK " TEST " TEST_REMOTE_NICK " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_prefix(remote, server, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_SERVER_NAME " TEST " TEST_REMOTE_NICK " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
standard_ids();
|
||||
|
||||
// Remote (with ID)
|
||||
sendto_one_prefix(remote, &me, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_ID " TEST " TEST_REMOTE_ID " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_prefix(remote, user, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ID " TEST " TEST_REMOTE_ID " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_prefix(remote, remote, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_REMOTE_ID " TEST " TEST_REMOTE_ID " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_prefix(remote, server, "TEST", ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_SERVER_ID " TEST " TEST_REMOTE_ID " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
standard_free();
|
||||
}
|
||||
|
||||
static void sendto_one_notice1(void)
|
||||
{
|
||||
standard_init();
|
||||
|
||||
// Local
|
||||
sendto_one_notice(user, ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " NOTICE " TEST_NICK " :Hello World!" CRLF, user, MSG);
|
||||
|
||||
// Remote (without ID)
|
||||
sendto_one_notice(remote, ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " NOTICE " TEST_REMOTE_NICK " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
standard_ids();
|
||||
|
||||
// Remote (with ID)
|
||||
sendto_one_notice(remote, ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_ID " NOTICE " TEST_REMOTE_ID " :Hello World!" CRLF, server, MSG);
|
||||
|
||||
// Local (unregistered)
|
||||
user->name[0] = '\0';
|
||||
sendto_one_notice(user, ":Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " NOTICE * :Hello World!" CRLF, user, MSG);
|
||||
|
||||
standard_free();
|
||||
}
|
||||
|
||||
static void sendto_one_numeric1(void)
|
||||
{
|
||||
struct Client *user = make_local_person();
|
||||
standard_init();
|
||||
|
||||
// Local
|
||||
sendto_one_numeric(user, 1, "Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " 001 " TEST_NICK " Hello World!" CRLF, user, MSG);
|
||||
|
||||
remove_local_person(user);
|
||||
// Remote (without ID)
|
||||
sendto_one_numeric(server, 1, "Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " 001 " TEST_SERVER_NAME " Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_numeric(remote, 1, "Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " 001 " TEST_REMOTE_NICK " Hello World!" CRLF, server, MSG);
|
||||
|
||||
standard_ids();
|
||||
|
||||
// Remote (with ID)
|
||||
sendto_one_numeric(server, 1, "Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_ID " 001 " TEST_SERVER_ID " Hello World!" CRLF, server, MSG);
|
||||
|
||||
sendto_one_numeric(remote, 1, "Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_ID " 001 " TEST_REMOTE_ID " Hello World!" CRLF, server, MSG);
|
||||
|
||||
// Local (unregistered)
|
||||
user->name[0] = '\0';
|
||||
sendto_one_numeric(user, 1, "Hello %s!", "World");
|
||||
is_client_sendq(":" TEST_ME_NAME " 001 * Hello World!" CRLF, user, MSG);
|
||||
|
||||
standard_free();
|
||||
}
|
||||
|
||||
static void sendto_wallops_flags1(void)
|
||||
|
@ -61,20 +198,20 @@ static void sendto_wallops_flags1(void)
|
|||
oper4->umodes |= UMODE_OPERWALL;
|
||||
|
||||
sendto_wallops_flags(UMODE_WALLOP, oper1, "Test to users");
|
||||
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, user1, "User is +w; " MSG);
|
||||
is_client_sendq(":oper1" TEST_ID_SUFFIX " WALLOPS :Test to users" CRLF, user1, "User is +w; " MSG);
|
||||
is_client_sendq_empty(user2, "User is -w; " MSG);
|
||||
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper1, "User is +w; " MSG);
|
||||
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper2, "User is +w; " MSG);
|
||||
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper3, "User is +w; " MSG);
|
||||
is_client_sendq(":oper1" TEST_ID_SUFFIX " WALLOPS :Test to users" CRLF, oper1, "User is +w; " MSG);
|
||||
is_client_sendq(":oper1" TEST_ID_SUFFIX " WALLOPS :Test to users" CRLF, oper2, "User is +w; " MSG);
|
||||
is_client_sendq(":oper1" TEST_ID_SUFFIX " WALLOPS :Test to users" CRLF, oper3, "User is +w; " MSG);
|
||||
is_client_sendq_empty(oper4, "User is -w; " MSG);
|
||||
|
||||
sendto_wallops_flags(UMODE_OPERWALL, oper2, "Test to opers");
|
||||
is_client_sendq_empty(user1, "Not an oper; " MSG);
|
||||
is_client_sendq_empty(user2, "Not an oper; " MSG);
|
||||
is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper1, "Oper is +z; " MSG);
|
||||
is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper2, "Oper is +z; " MSG);
|
||||
is_client_sendq(":oper2" TEST_ID_SUFFIX " WALLOPS :Test to opers" CRLF, oper1, "Oper is +z; " MSG);
|
||||
is_client_sendq(":oper2" TEST_ID_SUFFIX " WALLOPS :Test to opers" CRLF, oper2, "Oper is +z; " MSG);
|
||||
is_client_sendq_empty(oper3, "Oper is -z; " MSG);
|
||||
is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper4, "Oper is +z; " MSG);
|
||||
is_client_sendq(":oper2" TEST_ID_SUFFIX " WALLOPS :Test to opers" CRLF, oper4, "Oper is +z; " MSG);
|
||||
|
||||
sendto_wallops_flags(UMODE_ADMIN, &me, "Test to admins");
|
||||
is_client_sendq_empty(user1, "Not an admin; " MSG);
|
||||
|
@ -99,6 +236,9 @@ int main(int argc, char *argv[])
|
|||
ircd_util_init(__FILE__);
|
||||
client_util_init();
|
||||
|
||||
sendto_one1();
|
||||
sendto_one_prefix1();
|
||||
sendto_one_notice1();
|
||||
sendto_one_numeric1();
|
||||
sendto_wallops_flags1();
|
||||
|
||||
|
|
|
@ -5,3 +5,9 @@ serverinfo {
|
|||
network_name = "Test network";
|
||||
};
|
||||
|
||||
connect "remote.test" {
|
||||
host = "::1";
|
||||
fingerprint = "test";
|
||||
class = "default";
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue