]>
jfr.im git - solanum.git/blob - tests/sasl_abort1.c
2 * sasl_abort1.c: Test SASL abort from the ircd to services
3 * Copyright 2019 Simon Arlott
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
27 #include "tap/basic.h"
29 #include "ircd_util.h"
30 #include "client_util.h"
34 #include "s_newconf.h"
37 #define MSG "%s:%d (%s; aborted=%d, by_user=%d)", __FILE__, __LINE__, __FUNCTION__, aborted, by_user
39 static void common_sasl_test(bool aborted
, bool by_user
)
41 ircd_util_init(__FILE__
);
44 struct Client
*user
= make_local_unknown();
45 struct Client
*server
= make_remote_server(&me
);
46 struct Client
*remote
= make_remote_person(server
);
48 rb_inet_pton_sock(TEST_IP
, &user
->localClient
->ip
);
49 rb_strlcpy(user
->host
, TEST_HOSTNAME
, sizeof(user
->host
));
50 rb_inet_ntop_sock((struct sockaddr
*)&user
->localClient
->ip
, user
->sockhost
, sizeof(user
->sockhost
));
52 strcpy(server
->id
, TEST_SERVER_ID
);
53 strcpy(remote
->id
, TEST_REMOTE_ID
);
54 add_to_id_hash(remote
->id
, remote
);
55 server
->localClient
->caps
= CAP_ENCAP
| CAP_TS6
;
56 remote
->umodes
|= UMODE_SERVICE
;
58 client_util_parse(user
, "CAP LS 302" CRLF
);
60 while ((line
= get_client_sendq(user
)) && strcmp(line
, "")) {
64 client_util_parse(user
, "NICK " TEST_NICK CRLF
);
65 client_util_parse(user
, "USER " TEST_USERNAME
" 0 0 :" TEST_REALNAME CRLF
);
66 is_client_sendq_empty(user
, MSG
);
70 client_util_parse(user
, "CAP REQ :sasl" CRLF
);
71 is_client_sendq(":" TEST_ME_NAME
" CAP " TEST_NICK
" ACK :sasl" CRLF
, user
, MSG
);
73 client_util_parse(user
, "AUTHENTICATE EXTERNAL" CRLF
);
74 is_client_sendq_empty(user
, MSG
);
76 is_client_sendq_one(":" TEST_ME_ID
" ENCAP " TEST_SERVER_NAME
" SASL " TEST_ME_ID
"AAAAAB " TEST_REMOTE_ID
" H " TEST_HOSTNAME
" " TEST_IP
" P" CRLF
, server
, MSG
);
77 is_client_sendq_one(":" TEST_ME_ID
" ENCAP " TEST_SERVER_NAME
" SASL " TEST_ME_ID
"AAAAAB " TEST_REMOTE_ID
" S EXTERNAL" CRLF
, server
, MSG
);
78 is_client_sendq_empty(server
, MSG
);
82 // Explicit abort by user
83 client_util_parse(user
, "AUTHENTICATE *" CRLF
);
84 is_client_sendq(":" TEST_ME_NAME
" 906 " TEST_NICK
" :SASL authentication aborted" CRLF
, user
, MSG
);
86 client_util_parse(user
, "CAP END" CRLF
);
87 ok(IsClient(user
), MSG
);
89 // Implicit abort by completing registration
90 client_util_parse(user
, "CAP END" CRLF
);
91 ok(IsClient(user
), MSG
);
92 is_client_sendq_one(":" TEST_ME_NAME
" 906 " TEST_NICK
" :SASL authentication aborted" CRLF
, user
, MSG
);
95 is_client_sendq_one(":" TEST_ME_ID
" ENCAP " TEST_SERVER_NAME
" SASL " TEST_ME_ID
"AAAAAB " TEST_REMOTE_ID
" D A" CRLF
, server
, MSG
);
96 is_client_sendq(":" TEST_ME_ID
" UID " TEST_NICK
" 1 42 +i ~" TEST_USERNAME
" " TEST_HOSTNAME
" " TEST_IP
" " TEST_ME_ID
"AAAAAB :" TEST_REALNAME CRLF
, server
, MSG
);
98 // Return a successful auth
99 client_util_parse(server
, ":" TEST_SERVER_NAME
" ENCAP " TEST_ME_NAME
" SASL " TEST_REMOTE_ID
" " TEST_ME_ID
"AAAAAB D S" CRLF
);
101 // User should be authenticated
102 is_client_sendq_one(":" TEST_ME_NAME
" 903 " TEST_NICK
" :SASL authentication successful" CRLF
, user
, MSG
);
104 client_util_parse(user
, "CAP END" CRLF
);
105 ok(IsClient(user
), MSG
);
108 is_client_sendq_one(":" TEST_ME_NAME
" 001 " TEST_NICK
" :Welcome to the Test Internet Relay Chat Network " TEST_NICK CRLF
, user
, MSG
);
109 while ((line
= get_client_sendq(user
)) && strcmp(line
, "")) {
114 // Return a successful auth after auth was aborted
115 client_util_parse(server
, ":" TEST_SERVER_NAME
" ENCAP " TEST_ME_NAME
" SASL " TEST_REMOTE_ID
" " TEST_ME_ID
"AAAAAB D S" CRLF
);
117 // User should not be authenticated
118 is_client_sendq_empty(user
, MSG
);
121 remove_local_person(user
);
122 remove_remote_person(remote
);
123 remove_remote_server(server
);
129 static void successful_login(void)
131 common_sasl_test(false, false);
134 static void successful_login_after_aborted_by_registration(void)
136 common_sasl_test(true, false);
139 static void successful_login_after_aborted_by_user(void)
141 common_sasl_test(true, true);
144 int main(int argc
, char *argv
[])
149 successful_login_after_aborted_by_registration();
150 successful_login_after_aborted_by_user();