1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 10:13:12 +02:00

tests: add tests on some IRC SASL functions

This commit is contained in:
Sébastien Helleu
2021-11-13 09:06:34 +01:00
parent cbadaecc4f
commit a3924a27a0
8 changed files with 127 additions and 2 deletions
+1 -1
View File
@@ -434,6 +434,7 @@ WeeChat "core" is located in following directories:
|             test-irc-mode.cpp | Tests: IRC modes.
|             test-irc-nick.cpp | Tests: IRC nicks.
|             test-irc-protocol.cpp | Tests: IRC protocol.
|             test-irc-sasl.cpp | Tests: SASL authentication with IRC protocol.
|             test-irc-server.cpp | Tests: IRC server.
|          trigger/ | Root of unit tests for trigger plugin.
|             test-trigger.cpp | Tests: triggers.
@@ -443,7 +444,6 @@ WeeChat "core" is located in following directories:
|             test-typing-status.cpp | Tests: typing status.
|          relay/ | Root of unit tests for Relay plugin.
|             test-relay-auth.cpp | Tests: clients authentication.
|===
[[documentation_translations]]
+1
View File
@@ -436,6 +436,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|             test-irc-mode.cpp | Tests : modes IRC.
|             test-irc-nick.cpp | Tests : pseudos IRC.
|             test-irc-protocol.cpp | Tests : protocole IRC.
|             test-irc-sasl.cpp | Tests : authentification SASL avec le protocole IRC.
|             test-irc-server.cpp | Tests : serveur IRC.
|          trigger/ | Racine des tests unitaires pour l'extension trigger.
|             test-trigger.cpp | Tests : triggers.
+2
View File
@@ -468,6 +468,8 @@ WeeChat "core" は以下のディレクトリに配置されています:
|             test-irc-nick.cpp | Tests: IRC nicks.
|             test-irc-protocol.cpp | テスト: IRC プロトコル
// TRANSLATION MISSING
|             test-irc-sasl.cpp | Tests: SASL authentication with IRC protocol.
// TRANSLATION MISSING
|             test-irc-server.cpp | Tests: IRC server.
// TRANSLATION MISSING
|          trigger/ | Root of unit tests for trigger plugin.
+2 -1
View File
@@ -436,6 +436,8 @@ WeeChat „језгро” се налази у следећим директо
|             test-irc-mode.cpp | Тестови: IRC режими.
|             test-irc-nick.cpp | Тестови: IRC надимци.
|             test-irc-protocol.cpp | Тестови: IRC протокол.
// TRANSLATION MISSING
|             test-irc-sasl.cpp | Tests: SASL authentication with IRC protocol.
|             test-irc-server.cpp | Тестови: IRC сервер.
|          trigger/ | Корен unit тестова за окидач додатак.
|             test-trigger.cpp | Тестови: окидачи.
@@ -446,7 +448,6 @@ WeeChat „језгро” се налази у следећим директо
|             test-typing-status.cpp | Тестови: typing статус.
|          relay/ | Корен unit тестова за Релеј додатак.
|             test-relay-auth.cpp | Тестови: аутентификација клијената.
|===
[[documentation_translations]]
+9
View File
@@ -58,6 +58,9 @@ irc_sasl_mechanism_plain (const char *sasl_username, const char *sasl_password)
char *answer_base64, *string;
int length_username, length;
if (!sasl_username || !sasl_password)
return NULL;
answer_base64 = NULL;
length_username = strlen (sasl_username);
length = ((length_username + 1) * 2) + strlen (sasl_password) + 1;
@@ -117,6 +120,12 @@ irc_sasl_mechanism_scram (struct t_irc_server *server,
int server_key_size, server_signature_size, verifier_size;
long number;
if (!server || !hash_algo || !data_base64 || !sasl_username
|| !sasl_password)
{
return NULL;
}
answer_base64 = NULL;
string = NULL;
length = 0;
+1
View File
@@ -63,6 +63,7 @@ if(ENABLE_IRC)
unit/plugins/irc/test-irc-mode.cpp
unit/plugins/irc/test-irc-nick.cpp
unit/plugins/irc/test-irc-protocol.cpp
unit/plugins/irc/test-irc-sasl.cpp
unit/plugins/irc/test-irc-server.cpp
unit/plugins/irc/test-irc-tag.cpp
)
+1
View File
@@ -78,6 +78,7 @@ tests_irc = unit/plugins/irc/test-irc-buffer.cpp \
unit/plugins/irc/test-irc-mode.cpp \
unit/plugins/irc/test-irc-nick.cpp \
unit/plugins/irc/test-irc-protocol.cpp \
unit/plugins/irc/test-irc-sasl.cpp \
unit/plugins/irc/test-irc-server.cpp \
unit/plugins/irc/test-irc-tag.cpp
endif
+110
View File
@@ -0,0 +1,110 @@
/*
* test-irc-sasl.cpp - test IRC SASL functions
*
* Copyright (C) 2021 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CppUTest/TestHarness.h"
extern "C"
{
#include <string.h>
#include "src/core/wee-string.h"
#include "src/plugins/plugin.h"
#include "src/plugins/irc/irc-sasl.h"
#include "src/plugins/irc/irc-server.h"
}
TEST_GROUP(IrcSasl)
{
};
/*
* Tests functions:
* irc_sasl_mechanism_plain
*/
TEST(IrcSasl, MechanismPlain)
{
POINTERS_EQUAL(NULL, irc_sasl_mechanism_plain (NULL, NULL));
POINTERS_EQUAL(NULL, irc_sasl_mechanism_plain (NULL, ""));
POINTERS_EQUAL(NULL, irc_sasl_mechanism_plain ("", NULL));
STRCMP_EQUAL("AAA=", irc_sasl_mechanism_plain ("", ""));
/* "alice\0alice\0" */
STRCMP_EQUAL("YWxpY2UAYWxpY2UA",
irc_sasl_mechanism_plain ("alice", ""));
/* "alice\0alice\0secret" */
STRCMP_EQUAL("YWxpY2UAYWxpY2UAc2VjcmV0",
irc_sasl_mechanism_plain ("alice", "secret"));
/* "\0\0secret" */
STRCMP_EQUAL("AABzZWNyZXQ=",
irc_sasl_mechanism_plain ("", "secret"));
}
/*
* Tests functions:
* irc_sasl_mechanism_scram
*/
TEST(IrcSasl, MechanismScram)
{
struct t_irc_server *server;
char *str, str_decoded[1024], *error;
POINTERS_EQUAL(NULL, irc_sasl_mechanism_scram (NULL, NULL, NULL, NULL,
NULL, NULL));
server = irc_server_alloc ("my_ircd");
/* decoded returned value is like: n,,n=user,r=rOprNGfwEbeRWgbNEkqO */
error = NULL;
str = irc_sasl_mechanism_scram (server, "sha256", "+",
"user1", "secret", &error);
POINTERS_EQUAL(NULL, error);
CHECK(string_base64_decode (str, str_decoded) > 0);
CHECK(strncmp (str_decoded, "n,,n=user1,r=", 13) == 0);
free (str);
/* TODO: complete tests */
irc_server_free (server);
}
/*
* Tests functions:
* irc_sasl_get_key_content
*/
TEST(IrcSasl, GetKeyContent)
{
/* TODO: write tests */
}
/*
* Tests functions:
* irc_sasl_mechanism_ecdsa_nist256p_challenge
*/
TEST(IrcSasl, MechanismEcdsaNist256pChallenge)
{
/* TODO: write tests */
}