Commit 7b860e03 authored by David Goulet's avatar David Goulet Committed by Ian Goldberg

Test: Add new test-suite in tests/

This is a completely new test suite that adds unit and regression tests.
Still not everything is covered but it's at 76.3% line coverage and
87.5% function coverage. See the current status here.

	https://coverage.otr.im/

In order to run the tests, simply type "make check" from the top
directory of the repository.

The test suite uses libtap and adds both a shell and C library located
in tests/utils/tap.

Note that this test suite is not related at all to the tests located in
the directory test_suite. Future work should be done to either merge
them or remove the old one.

Tested with libgcrypt 1.5.4 and 1.6.2.
Signed-off-by: jvoisin's avatarJulien Voisin <julien.voisin@dustri.org>
Signed-off-by: 's avatarDavid Goulet <dgoulet@ev0ke.net>
Signed-off-by: 's avatarIan Goldberg <iang@cs.uwaterloo.ca>

Fixes #8
parent 187a09ac
......@@ -15,6 +15,8 @@ Makefile.in
*.info
*.gz
*.tar
*.gcda
*.gcno
.dirstamp
configure
aclocal.m4
......@@ -38,3 +40,17 @@ libotr.pc
/toolkit/otr_readforge
/toolkit/otr_remac
/toolkit/otr_sesskeys
/tests/regression/client/client
/tests/unit/test_auth
/tests/unit/test_proto
/tests/unit/test_dh
/tests/unit/test_b64
/tests/unit/test_context
/tests/unit/test_userstate
/tests/unit/test_tlv
/tests/unit/test_mem
/tests/unit/test_sm
/tests/unit/test_instag
/tests/unit/test_privkey
ACLOCAL_AMFLAGS = -I config
SUBDIRS = src toolkit
SUBDIRS = src toolkit tests
EXTRA_DIST = Protocol-v3.html UPGRADING packaging libotr.m4 libotr.pc.in
......
......@@ -170,11 +170,11 @@ if test x$enable_linker_hardening != xno; then
OTR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
fi
AC_CONFIG_FILES([
Makefile
src/Makefile
toolkit/Makefile
libotr.pc
AC_OUTPUT([Makefile src/Makefile toolkit/Makefile tests/Makefile tests/utils/Makefile libotr.pc
tests/utils/tap/Makefile
tests/unit/Makefile
tests/regression/Makefile
tests/regression/client/Makefile
])
AC_OUTPUT
SUBDIRS = utils unit regression
AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests/utils/ -I$(srcdir)
LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la
check-am:
./run.sh test_list
dist_noinst_SCRIPTS = test_list run.sh
EXTRA_DIST = run.sh test_list
SUBDIRS = client
EXTRA_DIST = random-msg.sh random-msg-disconnect.sh random-msg-disconnect-auth.sh \
random-msg-disconnect-frag-auth.sh random-msg-fast.sh random-msg-auth.sh \
random-msg-disconnect-frag.sh random-msg-frag.sh
AM_CFLAGS = -I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-I$(top_srcdir)/tests/utils/ \
-I$(srcdir)
LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la
LIBOTR=$(top_builddir)/src/libotr.la
noinst_PROGRAMS = client
client_SOURCES = client.c
client_LDADD = $(LIBTAP) $(LIBOTR) -lpthread @LIBGCRYPT_LIBS@
EXTRA_DIST = otr.key
This diff is collapsed.
(privkeys
(account
(name alice)
(protocol otr-test)
(private-key
(dsa
(p #00E4240AE9740D5FB1DF076A3270143BBD5B66DEB9BFD601CF3C3DC3E8D76BF1EA0D1A66E209516600E915B79552887EE9810D613C63EA6D2B6E69321C3C81F71F533F02430D20AF65C05C15BA46EF10C78EFF3BE687C33A4F6EA90877AB30E6423070AAFD3F22B5939D0DC8FBE5145A68F38EBA98ADCA7E06EFBC5E345E9AEDEF#)
(q "\x00ջ*i#bU~{Uq")
(g #00D3A15721AEF3A49DF26E875EC8C5FF4096B0B1717AF89485A015245176FD4AE3065D9F7B2D185B1E02CEAFB53E6984B1D341E62EBB4A5C189EB40959CFED0C48DAE73F3391C5E1482372E9DE539CD6911C54583DC0A3179547A38E19549F81A6DBFA8036C471C2A358D4B3AB86C7424556DFD61C35CC1EC08304B0102A0EEE08#)
(y #6E3996E07B6CB54DC443BD83033293956E5B7CCC511D19DCAC8735496B061D6EB6DF3D5540548D3C97201393E669EF9066BCA6A72E3AC68710188BEDF06FDF22548D8709BD4E9E1AD02DB0E193399BEB39DE5218D70C999D9856D3205DB79BA8DFC188726E646A1BE1722843F5E56A51C499C5BE5F63FACE7802ECD565E99F39#)
(x #2C5887BA7EC5F426B6BE4438E2FAE4589DBF2CB6#)
)
)
)
(account
(name bob)
(protocol otr-test)
(private-key
(dsa
(p #00BD114F05B275A8A94954047983C5CD96ED95C782D2ED65A18E78C98E8EAFBAF58BBD046BE9895AD55FD0FF95907E7EBD6ACA2688D24779BDE9F0AAB13924CE65F597F9C9B9953DDBACF51DA7113FBAB9BE1DF6C6EA836DEB48983CCDCFC4125B5013D0CE52F890D0C391A035D30BCD5169A3451FD7023685274576DCB5F8FA47#)
(q #00D1DA3915346A704EB2D2F2A48CD48F3DCC4CF25D#)
(g #501BCFB989AD2C346BBD7782CA0230551F976B1A07EE3AEE27E4B63B7B00B1ACA712AD85784986411278163156D4DBA9DF75C8560F9C2E02C02AEC830EC403A56B6F64432869D6CA9314A648076511343507629BF4FC96F8FDBB9797258DDF11F437B1450BA23F1AA7E885EC6A33D37B7D7EC384A004420DB238E140B94AAAFE#)
(y #7C9CB7732164787DD1931BB58257665EB60D6AA72B8D64D634530A61BE93D5AF01427962646542F18401B73032B12B9CBCAE8E3CF080DAD55C6612A97D6D8776CF2CBDD3AAC75D302B60E6956E5B3C60B39E171A2D5F150A924C6E22981EFDF052D5C6507B2DEC15E96CB6CAF7B260D5386BBDD7D7F69B4BF14451D64D847AEB#)
(x #00AB1E941176D94505911118AC799A504ADCCE88F8#)
)
)
)
(account
(name otrtest3)
(protocol otr-test)
(private-key
(dsa
(p #00BB4C57669E50E4C35F8E4CA84855CF2C83EE75C4F44B4BB4A7E88590D394D7A738E82EE97892E5051CE45E200741E18D423137AA8E6679B1CFAB4FF11D45D8C9CBDE388D30FC800B4879713E3C57BA48A92FE135BB9AF265F770B706FB9A04802244D12CBFFD97ACE5C73FCE88C2B716B4B22B994CD6429A7E16D9B6D1874137#)
(q #00C40DA63B679A80FC31BF49A68503BB39754D0A45#)
(g #6C0A48BEA859587D6677306D1777A2A0635470F149A86EB64EA62EAAA4C21ECE4375ACD016B776E3AD3411C18BB3FF37F963FCEBB8820FF8838AFA6FCD1B39558DAB78450AE2ED9457DEDBDCE13DF5A6B20A738D2973D375D360C044AF7F0204CCC372098F0B6460963274B1EA0B5FEC93571A15F5C03DCDF54EE83BB198F363#)
(y #00AB2C8A82F020DB99EF5B7A8330EC43E0D5EBD623FEB67D1B046D88FACA01D8E31E4D7865DC62D4DA58CF8BC7FF4B57C203A9F7F5C85DAB1B63D63299EF13AD89AAA7E6638C9DBC42D096408936C9F0382224CFB5C1528DCC8C7F2554CB4CA2FF3C3239BC921F1C690295DD9AE69C8EF5BBD8E58A8FAA8BB9D5F88463CAECEE7B#)
(x #7824B713A4E5FA6D6C69172196648CD4657A1ED1#)
)
)
)
)
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=50
MAX_INTERVAL=500 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL and authentication"
$CLIENT --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG --auth
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=50
MAX_INTERVAL=100 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL with disconnect and authentication"
$CLIENT --disconnect --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG --auth
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=20
MAX_INTERVAL=500 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL with disconnect, framgents and authentication"
$CLIENT --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG --fragment --disconnect --auth
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=20
MAX_INTERVAL=500 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL, disconnect and fragmentation"
$CLIENT --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG --fragment --disconnect
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=50
MAX_INTERVAL=500 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL with disconnect"
$CLIENT --disconnect --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=250
MAX_INTERVAL=10 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL and number of message to $MAX_MSG"
$CLIENT --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=20
MAX_INTERVAL=500 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL and fragmentation"
$CLIENT --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG --fragment
#!/bin/bash
CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/..
CLIENT=$CURDIR/client/client
KEYFILE=$CURDIR/client/otr.key
MAX_MSG=50
MAX_INTERVAL=500 # msec
source $TESTDIR/utils/tap/tap.sh
diag "Messaging with random interval of max $MAX_INTERVAL"
$CLIENT --load-key $KEYFILE --timeout $MAX_INTERVAL --max-msg $MAX_MSG
#!/bin/bash
#
# Copyright (C) 2013 - Christian Babeux <christian.babeux@efficios.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
[ -z "$1" ] && echo "Error: No testlist. Please specify a testlist to run." && exit 1
prove $2 --merge --exec '' - < $1
unit/test_auth
unit/test_proto
unit/test_dh
unit/test_b64
unit/test_context
unit/test_userstate
unit/test_tlv
unit/test_mem
unit/test_sm
unit/test_instag
unit/test_privkey
regression/random-msg.sh
regression/random-msg-auth.sh
regression/random-msg-fast.sh
regression/random-msg-frag.sh
regression/random-msg-disconnect.sh
regression/random-msg-disconnect-frag.sh
regression/random-msg-disconnect-auth.sh
regression/random-msg-disconnect-frag-auth.sh
AM_CFLAGS = -I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-I$(top_srcdir)/tests/utils/ \
-I$(srcdir)
LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la
LIBOTR=$(top_builddir)/src/libotr.la
noinst_PROGRAMS = test_auth test_proto test_dh \
test_b64 test_context \
test_userstate test_tlv \
test_mem test_sm test_instag \
test_privkey
test_auth_SOURCES = test_auth.c
test_auth_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_proto_SOURCES = test_proto.c
test_proto_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_dh_SOURCES = test_dh.c
test_dh_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_b64_SOURCES = test_b64.c
test_b64_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_context_SOURCES = test_context.c
test_context_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_userstate_SOURCES = test_userstate.c
test_userstate_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_tlv_SOURCES = test_tlv.c
test_tlv_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_mem_SOURCES = test_mem.c
test_mem_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_sm_SOURCES = test_sm.c
test_sm_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_instag_SOURCES = test_instag.c
test_instag_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
test_privkey_SOURCES = test_privkey.c
test_privkey_LDADD = $(LIBTAP) $(LIBOTR) @LIBGCRYPT_LIBS@
EXTRA_DIST = instag.txt
alice_xmpp XMPP 01234567
alice_irc IRC 9abcdef0
alice_inv IRC WRONG
alice_icq ICQ 98765432
/*
* Copyright (C) 2014 - David Goulet <dgoulet@ev0ke.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
* published by the Free Software Foundation.
*
* This program 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
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <auth.h>
#include <context.h>
#include <gcrypt.h>
#include <pthread.h>
#include <tap/tap.h>
#include <utils.h>
#include <proto.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#define NUM_TESTS 5
static void test_auth_new(void)
{
struct context ctx;
OtrlAuthInfo *auth = &ctx.auth;
/* API call. */
otrl_auth_new(&ctx);
ok(auth->authstate == OTRL_AUTHSTATE_NONE &&
auth->our_keyid == 0 &&
auth->encgx == NULL &&
auth->encgx_len == 0 &&
utils_is_zeroed(auth->r, 16) &&
utils_is_zeroed(auth->hashgx, 32) &&
auth->their_pub == NULL &&
auth->their_keyid == 0 &&
auth->enc_c == NULL &&
auth->enc_cp == NULL &&
auth->mac_m1 == NULL &&
auth->mac_m1p == NULL &&
auth->mac_m2 == NULL &&
auth->mac_m2p == NULL &&
utils_is_zeroed(auth->their_fingerprint, 20) &&
auth->initiated == 0 &&
auth->protocol_version == 0 &&
utils_is_zeroed(auth->secure_session_id, 20) &&
auth->secure_session_id_len == 0 &&
auth->lastauthmsg == NULL &&
auth->commit_sent_time == 0 &&
auth->context == &ctx,
"OTR auth info init is valid");
}
static void test_auth_clear(void)
{
struct context ctx;
OtrlAuthInfo *auth = &ctx.auth;
/* API call. */
otrl_auth_clear(auth);
ok(auth->authstate == OTRL_AUTHSTATE_NONE &&
auth->our_keyid == 0 &&
auth->encgx == NULL &&
auth->encgx_len == 0 &&
utils_is_zeroed(auth->r, 16) &&
utils_is_zeroed(auth->hashgx, 32) &&
auth->their_pub == NULL &&
auth->their_keyid == 0 &&
auth->enc_c == NULL &&
auth->enc_cp == NULL &&
auth->mac_m1 == NULL &&
auth->mac_m1p == NULL &&
auth->mac_m2 == NULL &&
auth->mac_m2p == NULL &&
utils_is_zeroed(auth->their_fingerprint, 20) &&
auth->initiated == 0 &&
auth->protocol_version == 0 &&
utils_is_zeroed(auth->secure_session_id, 20) &&
auth->secure_session_id_len == 0 &&
auth->lastauthmsg == NULL &&
auth->commit_sent_time == 0 &&
auth->context == &ctx,
"OTR auth info clear is valid");
}
static void test_auth_start_v23(void)
{
unsigned int version = 3;
gcry_error_t err;
struct context ctx;
OtrlAuthInfo *auth = &ctx.auth;
/* API call. */
otrl_auth_new(&ctx);
err = otrl_auth_start_v23(auth, version);
ok(err == gcry_error(GPG_ERR_NO_ERROR) &&
auth->initiated == 1 &&
auth->protocol_version == version &&
auth->context->protocol_version == version &&
auth->our_keyid == 1 &&
!utils_is_zeroed(auth->r, sizeof(auth->r)) &&
auth->encgx != NULL &&
auth->encgx_len > 0 &&
!utils_is_zeroed(auth->hashgx, sizeof(auth->hashgx)) &&
auth->lastauthmsg != NULL &&
auth->authstate == OTRL_AUTHSTATE_AWAITING_DHKEY,
"OTR auth start v23 is valid");
}
static void test_otrl_auth_copy_on_key()
{
struct context m_ctx, ctx;
OtrlAuthInfo *auth = &ctx.auth;
OtrlAuthInfo *m_auth = &m_ctx.auth;
otrl_auth_new(&ctx);
otrl_auth_new(&m_ctx);
otrl_auth_start_v23(auth, 3);
otrl_auth_start_v23(m_auth, 3);
m_auth->authstate = OTRL_AUTHSTATE_NONE;
auth->authstate = OTRL_AUTHSTATE_AWAITING_REVEALSIG,
otrl_auth_copy_on_key(m_auth, auth);
ok(gcry_mpi_cmp((m_auth->our_dh.priv), (auth->our_dh.priv)) != 0 &&
gcry_mpi_cmp((m_auth->our_dh.pub), (auth->our_dh.pub)) != 0 &&
m_auth->our_keyid == auth->our_keyid &&
memcmp(m_auth->r, auth->r, 16) != 0 &&
memcmp(m_auth->encgx, auth->encgx, 16) != 0 &&
memcmp(m_auth->hashgx, auth->hashgx, 16) != 0 &&
auth->authstate == OTRL_AUTHSTATE_AWAITING_REVEALSIG,
"Copy not done");
auth->authstate = OTRL_AUTHSTATE_AWAITING_DHKEY;
m_auth->authstate = OTRL_AUTHSTATE_AWAITING_DHKEY;
otrl_auth_copy_on_key(m_auth, auth);
ok(m_auth->initiated == auth->initiated &&
m_auth->our_keyid == auth->our_keyid &&
m_auth->our_dh.groupid == auth->our_dh.groupid &&
gcry_mpi_cmp((m_auth->our_dh.priv), (auth->our_dh.priv)) == 0 &&
gcry_mpi_cmp((m_auth->our_dh.pub), (auth->our_dh.pub)) == 0 &&
m_auth->our_keyid == auth->our_keyid &&
memcmp(m_auth->r, auth->r, 16) == 0 &&
memcmp(m_auth->encgx, auth->encgx, 16) == 0 &&
memcmp(m_auth->hashgx, auth->hashgx, 16) == 0 &&
auth->authstate == OTRL_AUTHSTATE_AWAITING_DHKEY,
"Copy OK");
}
int main(int argc, char **argv)
{
/* Libtap call for the number of tests planned. */
plan_tests(NUM_TESTS);
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
OTRL_INIT;
/* Initialize libotr. */
otrl_dh_init();
test_auth_new();
test_auth_clear();
test_auth_start_v23();
test_otrl_auth_copy_on_key();
return 0;
}
/*
* Copyright (C) 2014 - Julien Voisin <julien.voisin@dustri.org>
* David Goulet <dgoulet@ev0ke.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
* published by the Free Software Foundation.
*
* This program 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
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <b64.h>
#include <tap/tap.h>
#include <proto.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#define NUM_TESTS 10
const char *alphanum_encoded =
"?OTR:" "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwCg==" ".";
const char *alphanum_decoded =
"abcdefghijklmnopqrstuvwxyz1234567890\n";
static void test_otrl_base64_otr_decode(void)
{
int ret;
unsigned char *bufp = NULL;
size_t len = 0;
/*
* Invalid decoding.
*/
ok(otrl_base64_otr_decode("hello", NULL, NULL) == -2,
"Call with no prefix returned an error");
ok(otrl_base64_otr_decode("?OTR:" "MTIzNAo=", NULL, NULL) == -2,
"Call with no suffix returned an error");
/* Message of size 0. */
ret = otrl_base64_otr_decode("", &bufp, &len);
ok(ret == -2 && bufp == NULL && len == 0,
"Decode b64 with message of len 0");
/*
* Valid decoding.
*/
/* Invalid chars are ignored */
ok(otrl_base64_otr_decode("?OTR:invalid_base64_thing.", &bufp, &len) == 0
&& len == 12, "Invalid b64 data");
free(bufp);
bufp = NULL;
len = 0;
ok(otrl_base64_otr_decode(alphanum_encoded, &bufp, &len) == 0,
"Call with valid data successfull");
ok(strcmp((const char*)bufp, alphanum_decoded) == 0
&& len == 37, "Decoded valid b64 test vector with success");
free(bufp);
bufp = NULL;
len = 0;
/* Invalid base64 char. */
ret = otrl_base64_otr_decode("?OTR:_*&?!!*\"().", &bufp, &len);
ok(ret == 0 && bufp != NULL && len == 0,
"Decode b64 with invalid b64 characters");
free(bufp);
bufp = NULL;
len = 0;
}
static void test_otrl_base64_otr_encode(void)
{
unsigned char *bufp = NULL;
size_t len = 0;
char *encoded;
encoded = otrl_base64_otr_encode((const unsigned char *) alphanum_decoded,
strlen(alphanum_decoded));
ok(strcmp(encoded, alphanum_encoded) == 0,
"Encoded b64 test vector with success");
ok(otrl_base64_otr_decode(encoded, &bufp, &len) == 0,
"Decoded previously encoded test vector");
ok(memcmp(bufp, alphanum_decoded, len) == 0
&& len == strlen(alphanum_decoded),
"Decoded value is exact");
free(bufp);
free(encoded);
}
int main(int argc, char** argv)
{
plan_tests(NUM_TESTS);
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
OTRL_INIT;
test_otrl_base64_otr_decode();
test_otrl_base64_otr_encode();
return 0;
}
/*
* Copyright (C) 2014 - Julien Voisin <julien.voisin@dustri.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
* published by the Free Software Foundation.
*
* This program 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
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <limits.h>
#include <pthread.h>
#include <context.h>
#include <tap/tap.h>
#define NUM_TESTS 22
static void test_otrl_context_find_fingerprint(void)
{
unsigned char fingerprint[20] = {0};
int add_if_missing = 0, addedp = 0;
ok(otrl_context_find_fingerprint(NULL, fingerprint,
add_if_missing, &addedp) == NULL, "NULL context detected");
}
static ConnContext *new_context(const char *user, const char *account,
const char *protocol)
{
ConnContext *context;
context = calloc(1, sizeof(ConnContext));
context->username = strdup(user);
context->accountname = strdup(account);
context->protocol = strdup(protocol);
context->m_context = context;
context->active_fingerprint = calloc(1, sizeof(Fingerprint));
context->context_priv = calloc(1, sizeof(ConnContextPriv));
return context;
}
static void free_context(ConnContext *context)
{
free(context->username);
free(context->accountname);
free(context->protocol);
free(context);
}
static void test_otrl_context_find_recent_instance()
{
ConnContext *context = new_context("main", "main", "main");
ConnContext *context_child = new_context("child", "child", "child");
ConnContext *context_rcvd = new_context("rcvd", "rcvd", "rcvd");
ConnContext *context_sent = new_context("sent", "sent", "sent");
ConnContext *tmp;
context->recent_child = context_child;
context->recent_rcvd_child = context_rcvd;
context->recent_sent_child = context_sent;
ok(otrl_context_find_recent_instance(NULL, OTRL_INSTAG_RECENT) == NULL,
"NULL context detected");
tmp = otrl_context_find_recent_instance(context, OTRL_INSTAG_RECENT);
ok(strcmp(tmp->username, "child") == 0, "OTRL_INSTAG_RECENT ok");
tmp = otrl_context_find_recent_instance(context,
OTRL_INSTAG_RECENT_RECEIVED);