ffi-tox 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ProjectTox-Core/AUTHORS +0 -0
- data/ProjectTox-Core/ChangeLog +0 -0
- data/ProjectTox-Core/INSTALL +370 -0
- data/ProjectTox-Core/INSTALL.md +455 -56
- data/ProjectTox-Core/Makefile.am +35 -0
- data/ProjectTox-Core/NEWS +0 -0
- data/ProjectTox-Core/README +43 -0
- data/ProjectTox-Core/README.md +34 -44
- data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
- data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
- data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
- data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
- data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
- data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
- data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
- data/ProjectTox-Core/auto_tests/helpers.h +15 -0
- data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
- data/ProjectTox-Core/auto_tests/network_test.c +171 -0
- data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
- data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
- data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
- data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
- data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
- data/ProjectTox-Core/autogen.sh +6 -0
- data/ProjectTox-Core/build/Makefile.am +14 -0
- data/ProjectTox-Core/configure.ac +694 -0
- data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
- data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
- data/ProjectTox-Core/dist-build/android-build.sh +59 -0
- data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
- data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
- data/ProjectTox-Core/docs/Group-Chats.md +71 -0
- data/ProjectTox-Core/docs/Hardening.txt +60 -0
- data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
- data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
- data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
- data/ProjectTox-Core/docs/TODO +62 -0
- data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
- data/ProjectTox-Core/docs/av_api.md +194 -0
- data/ProjectTox-Core/libtoxav.pc.in +11 -0
- data/ProjectTox-Core/libtoxcore.pc.in +11 -0
- data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
- data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
- data/ProjectTox-Core/m4/pkg.m4 +199 -0
- data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
- data/ProjectTox-Core/other/DHTnodes +3 -0
- data/ProjectTox-Core/other/Makefile.inc +20 -0
- data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
- data/ProjectTox-Core/other/tox.png +0 -0
- data/ProjectTox-Core/testing/DHT_test.c +170 -98
- data/ProjectTox-Core/testing/Makefile.inc +112 -0
- data/ProjectTox-Core/testing/Messenger_test.c +133 -69
- data/ProjectTox-Core/testing/dns3_test.c +115 -0
- data/ProjectTox-Core/testing/misc_tools.c +59 -13
- data/ProjectTox-Core/testing/nTox.c +1127 -264
- data/ProjectTox-Core/testing/nTox.h +10 -19
- data/ProjectTox-Core/testing/tox_shell.c +159 -0
- data/ProjectTox-Core/testing/tox_sync.c +299 -0
- data/ProjectTox-Core/tools/README +11 -0
- data/ProjectTox-Core/tools/astylerc +11 -0
- data/ProjectTox-Core/tools/pre-commit +17 -0
- data/ProjectTox-Core/toxav/Makefile.inc +36 -0
- data/ProjectTox-Core/toxav/codec.c +357 -0
- data/ProjectTox-Core/toxav/codec.h +116 -0
- data/ProjectTox-Core/toxav/msi.c +1949 -0
- data/ProjectTox-Core/toxav/msi.h +267 -0
- data/ProjectTox-Core/toxav/rtp.c +600 -0
- data/ProjectTox-Core/toxav/rtp.h +196 -0
- data/ProjectTox-Core/toxav/toxav.c +1148 -0
- data/ProjectTox-Core/toxav/toxav.h +389 -0
- data/ProjectTox-Core/toxcore/DHT.c +2521 -0
- data/ProjectTox-Core/toxcore/DHT.h +412 -0
- data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
- data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
- data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
- data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
- data/ProjectTox-Core/toxcore/Messenger.h +818 -0
- data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
- data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
- data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
- data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
- data/ProjectTox-Core/toxcore/assoc.c +1033 -0
- data/ProjectTox-Core/toxcore/assoc.h +104 -0
- data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
- data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
- data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
- data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
- data/ProjectTox-Core/toxcore/group_chats.c +837 -0
- data/ProjectTox-Core/toxcore/group_chats.h +199 -0
- data/ProjectTox-Core/toxcore/list.c +256 -0
- data/ProjectTox-Core/toxcore/list.h +85 -0
- data/ProjectTox-Core/toxcore/logger.c +153 -0
- data/ProjectTox-Core/toxcore/logger.h +84 -0
- data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
- data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
- data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
- data/ProjectTox-Core/toxcore/network.c +979 -0
- data/ProjectTox-Core/toxcore/network.h +367 -0
- data/ProjectTox-Core/toxcore/onion.c +540 -0
- data/ProjectTox-Core/toxcore/onion.h +150 -0
- data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
- data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
- data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
- data/ProjectTox-Core/toxcore/onion_client.h +253 -0
- data/ProjectTox-Core/toxcore/ping.c +346 -0
- data/ProjectTox-Core/toxcore/ping.h +47 -0
- data/ProjectTox-Core/toxcore/ping_array.c +162 -0
- data/ProjectTox-Core/toxcore/ping_array.h +75 -0
- data/ProjectTox-Core/toxcore/tox.c +940 -0
- data/ProjectTox-Core/toxcore/tox.h +734 -0
- data/ProjectTox-Core/toxcore/util.c +193 -0
- data/ProjectTox-Core/toxcore/util.h +63 -0
- data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
- data/ProjectTox-Core/toxdns/toxdns.c +238 -0
- data/ProjectTox-Core/toxdns/toxdns.h +88 -0
- data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
- data/interfaces/libtox.i +2 -6
- data/lib/ffi-tox/libtox.rb +406 -28
- metadata +124 -46
- data/ProjectTox-Core/CMakeLists.txt +0 -50
- data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
- data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
- data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
- data/ProjectTox-Core/core/CMakeLists.txt +0 -19
- data/ProjectTox-Core/core/DHT.c +0 -1104
- data/ProjectTox-Core/core/DHT.h +0 -111
- data/ProjectTox-Core/core/LAN_discovery.c +0 -79
- data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
- data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
- data/ProjectTox-Core/core/Messenger.c +0 -596
- data/ProjectTox-Core/core/Messenger.h +0 -165
- data/ProjectTox-Core/core/friend_requests.c +0 -131
- data/ProjectTox-Core/core/friend_requests.h +0 -51
- data/ProjectTox-Core/core/net_crypto.c +0 -575
- data/ProjectTox-Core/core/net_crypto.h +0 -134
- data/ProjectTox-Core/core/network.c +0 -205
- data/ProjectTox-Core/core/network.h +0 -134
- data/ProjectTox-Core/docs/commands.md +0 -25
- data/ProjectTox-Core/docs/start_guide.de.md +0 -40
- data/ProjectTox-Core/docs/start_guide.md +0 -38
- data/ProjectTox-Core/other/CMakeLists.txt +0 -9
- data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
- data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
- data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
- data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
- data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
- data/ProjectTox-Core/testing/misc_tools.h +0 -29
- data/ProjectTox-Core/testing/nTox_win32.c +0 -387
- data/ProjectTox-Core/testing/nTox_win32.h +0 -40
- data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,238 @@
|
|
1
|
+
/* Unit testing for friend requests, statuses, and messages.
|
2
|
+
* Purpose: Check that messaging functions actually do what
|
3
|
+
* they're supposed to by setting up two local clients.
|
4
|
+
*
|
5
|
+
* Design: (Subject to change.)
|
6
|
+
* 1. Parent sends a friend request, and waits for a response.
|
7
|
+
* It it doesn't get one, it kills the child.
|
8
|
+
* 2. Child gets friend request, accepts, then waits for a status change.
|
9
|
+
* 3. The parent waits on a status change, killing the child if it takes
|
10
|
+
* too long.
|
11
|
+
* 4. The child gets the status change, then sends a message. After that,
|
12
|
+
* it returns. If if doesn't get the status change, it just loops forever.
|
13
|
+
* 5. After getting the status change, the parent waits for a message, on getting
|
14
|
+
* one, it waits on the child to return, then returns 0.
|
15
|
+
*
|
16
|
+
* Note about "waiting":
|
17
|
+
* Wait time is decided by WAIT_COUNT and WAIT_TIME. c_sleep(WAIT_TIME) WAIT_COUNT
|
18
|
+
* times. This is used both to ensure that we don't loop forever on a broken build,
|
19
|
+
* and that we don't get too slow with messaging. The current time is 15 seconds. */
|
20
|
+
|
21
|
+
#ifdef HAVE_CONFIG_H
|
22
|
+
#include "config.h"
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#include "../toxcore/friend_requests.h"
|
26
|
+
#include "../toxcore/Messenger.h"
|
27
|
+
#include <assert.h>
|
28
|
+
#include <unistd.h>
|
29
|
+
#include <sys/mman.h>
|
30
|
+
#include <signal.h>
|
31
|
+
#include <sys/wait.h>
|
32
|
+
|
33
|
+
#define WAIT_COUNT 30
|
34
|
+
#define WAIT_TIME 500
|
35
|
+
|
36
|
+
#ifndef MAP_ANONYMOUS
|
37
|
+
#define MAP_ANONYMOUS MAP_ANON
|
38
|
+
#endif
|
39
|
+
|
40
|
+
/* first step, second step */
|
41
|
+
#define FIRST_FLAG 0x1
|
42
|
+
#define SECOND_FLAG 0x2
|
43
|
+
|
44
|
+
/* ensure that we sleep in milliseconds */
|
45
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
46
|
+
#define c_sleep(x) Sleep(x)
|
47
|
+
#else
|
48
|
+
#define c_sleep(x) usleep(1000*x)
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#define PORT 33445
|
52
|
+
|
53
|
+
static Messenger *m;
|
54
|
+
|
55
|
+
uint8_t *parent_id = NULL;
|
56
|
+
uint8_t *child_id = NULL;
|
57
|
+
|
58
|
+
pid_t child_pid = 0;
|
59
|
+
int request_flags = 0;
|
60
|
+
|
61
|
+
void do_tox(DHT *dht)
|
62
|
+
{
|
63
|
+
static int dht_on = 0;
|
64
|
+
|
65
|
+
if (!dht_on && DHT_isconnected(dht)) {
|
66
|
+
dht_on = 1;
|
67
|
+
} else if (dht_on && !DHT_isconnected(dht)) {
|
68
|
+
dht_on = 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
doMessenger(m);
|
72
|
+
}
|
73
|
+
|
74
|
+
void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length, void *userdata)
|
75
|
+
{
|
76
|
+
puts("OK");
|
77
|
+
request_flags |= SECOND_FLAG;
|
78
|
+
}
|
79
|
+
|
80
|
+
void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length, void *userdata)
|
81
|
+
{
|
82
|
+
puts("OK");
|
83
|
+
request_flags |= FIRST_FLAG;
|
84
|
+
}
|
85
|
+
|
86
|
+
int parent_friend_request(DHT *dht)
|
87
|
+
{
|
88
|
+
char *message = "Watson, come here, I need you.";
|
89
|
+
int len = strlen(message);
|
90
|
+
int i = 0;
|
91
|
+
|
92
|
+
fputs("Sending child request.", stdout);
|
93
|
+
fflush(stdout);
|
94
|
+
|
95
|
+
m_addfriend(m, child_id, (uint8_t *)message, len);
|
96
|
+
|
97
|
+
/* wait on the status change */
|
98
|
+
for (i = 0; i < WAIT_COUNT; i++) {
|
99
|
+
do_tox(dht);
|
100
|
+
|
101
|
+
if (request_flags & FIRST_FLAG)
|
102
|
+
break;
|
103
|
+
|
104
|
+
fputs(".", stdout);
|
105
|
+
fflush(stdout);
|
106
|
+
c_sleep(WAIT_TIME);
|
107
|
+
}
|
108
|
+
|
109
|
+
if (!(request_flags & FIRST_FLAG)) {
|
110
|
+
fputs("\nfriends_test: The child took to long to respond!\n"
|
111
|
+
"Friend requests may be broken, failing build!\n", stderr);
|
112
|
+
kill(child_pid, SIGKILL);
|
113
|
+
return -1;
|
114
|
+
}
|
115
|
+
|
116
|
+
return 0;
|
117
|
+
}
|
118
|
+
|
119
|
+
void child_got_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
120
|
+
{
|
121
|
+
fputs("OK\nsending status to parent", stdout);
|
122
|
+
fflush(stdout);
|
123
|
+
m_addfriend_norequest(m, public_key);
|
124
|
+
request_flags |= FIRST_FLAG;
|
125
|
+
}
|
126
|
+
|
127
|
+
void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length, void *userdata)
|
128
|
+
{
|
129
|
+
request_flags |= SECOND_FLAG;
|
130
|
+
}
|
131
|
+
|
132
|
+
int parent_wait_for_message(DHT *dht)
|
133
|
+
{
|
134
|
+
int i = 0;
|
135
|
+
|
136
|
+
fputs("Parent waiting for message.", stdout);
|
137
|
+
fflush(stdout);
|
138
|
+
|
139
|
+
for (i = 0; i < WAIT_COUNT; i++) {
|
140
|
+
do_tox(dht);
|
141
|
+
|
142
|
+
if (request_flags & SECOND_FLAG)
|
143
|
+
break;
|
144
|
+
|
145
|
+
fputs(".", stdout);
|
146
|
+
fflush(stdout);
|
147
|
+
c_sleep(WAIT_TIME);
|
148
|
+
}
|
149
|
+
|
150
|
+
if (!(request_flags & SECOND_FLAG)) {
|
151
|
+
fputs("\nParent hasn't received the message yet!\n"
|
152
|
+
"Messaging may be broken, failing the build!\n", stderr);
|
153
|
+
kill(child_pid, SIGKILL);
|
154
|
+
return -1;
|
155
|
+
}
|
156
|
+
|
157
|
+
return 0;
|
158
|
+
}
|
159
|
+
|
160
|
+
void cleanup(void)
|
161
|
+
{
|
162
|
+
munmap(parent_id, crypto_box_PUBLICKEYBYTES);
|
163
|
+
munmap(child_id, crypto_box_PUBLICKEYBYTES);
|
164
|
+
puts("============= END TEST =============");
|
165
|
+
}
|
166
|
+
|
167
|
+
int main(int argc, char *argv[])
|
168
|
+
{
|
169
|
+
puts("=========== FRIENDS_TEST ===========");
|
170
|
+
|
171
|
+
/* set up the global memory */
|
172
|
+
parent_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE,
|
173
|
+
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
174
|
+
child_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE,
|
175
|
+
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
176
|
+
|
177
|
+
fputs("friends_test: Starting test...\n", stdout);
|
178
|
+
|
179
|
+
if ((child_pid = fork()) == 0) {
|
180
|
+
/* child */
|
181
|
+
int i = 0;
|
182
|
+
char *message = "Y-yes Mr. Watson?";
|
183
|
+
|
184
|
+
m = initMessenger();
|
185
|
+
|
186
|
+
Messenger_save(m, child_id);
|
187
|
+
msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
|
188
|
+
|
189
|
+
m_callback_friendrequest(m, child_got_request, NULL);
|
190
|
+
m_callback_statusmessage(m, child_got_statuschange, NULL);
|
191
|
+
|
192
|
+
/* wait on the friend request */
|
193
|
+
while (!(request_flags & FIRST_FLAG))
|
194
|
+
do_tox(m->dht);
|
195
|
+
|
196
|
+
/* wait for the status change */
|
197
|
+
while (!(request_flags & SECOND_FLAG))
|
198
|
+
do_tox(m->dht);
|
199
|
+
|
200
|
+
for (i = 0; i < 6; i++) {
|
201
|
+
/* send the message six times, just to be sure */
|
202
|
+
m_sendmessage(m, 0, (uint8_t *)message, strlen(message));
|
203
|
+
do_tox(m->dht);
|
204
|
+
}
|
205
|
+
|
206
|
+
cleanupMessenger(m);
|
207
|
+
|
208
|
+
return 0;
|
209
|
+
}
|
210
|
+
|
211
|
+
/* parent */
|
212
|
+
if (atexit(cleanup) != 0) {
|
213
|
+
fputs("friends_test: atexit() failed!\nFailing build...\n", stderr);
|
214
|
+
kill(child_pid, SIGKILL);
|
215
|
+
return -1;
|
216
|
+
}
|
217
|
+
|
218
|
+
m = initMessenger();
|
219
|
+
|
220
|
+
msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
|
221
|
+
m_callback_statusmessage(m, parent_confirm_status, NULL);
|
222
|
+
m_callback_friendmessage(m, parent_confirm_message, NULL);
|
223
|
+
|
224
|
+
/* hacky way to give the child time to set up */
|
225
|
+
c_sleep(50);
|
226
|
+
|
227
|
+
Messenger_save(m, parent_id);
|
228
|
+
|
229
|
+
if (parent_friend_request(m->dht) == -1)
|
230
|
+
return -1;
|
231
|
+
|
232
|
+
if (parent_wait_for_message(m->dht) == -1)
|
233
|
+
return -1;
|
234
|
+
|
235
|
+
wait(NULL);
|
236
|
+
fputs("friends_test: Build passed!\n", stdout);
|
237
|
+
return 0;
|
238
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifndef TOXCORE_TEST_HELPERS_H
|
2
|
+
#define TOXCORE_TEST_HELPERS_H
|
3
|
+
|
4
|
+
#include <check.h>
|
5
|
+
|
6
|
+
#define DEFTESTCASE(NAME) \
|
7
|
+
TCase *tc_##NAME = tcase_create(#NAME); \
|
8
|
+
tcase_add_test(tc_##NAME, test_##NAME); \
|
9
|
+
suite_add_tcase(s, tc_##NAME);
|
10
|
+
|
11
|
+
#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
|
12
|
+
DEFTESTCASE(NAME) \
|
13
|
+
tcase_set_timeout(tc_##NAME, TIMEOUT);
|
14
|
+
|
15
|
+
#endif // TOXCORE_TEST_HELPERS_H
|
@@ -0,0 +1,365 @@
|
|
1
|
+
/* unit tests for /core/Messenger.c
|
2
|
+
* Design:
|
3
|
+
* Just call every non-static function in Messenger.c, checking that
|
4
|
+
* they return as they should with check calls. "Bad" calls of the type
|
5
|
+
* function(bad_data, good_length) are _not_ checked for, this type
|
6
|
+
* of call is the fault of the client code.
|
7
|
+
*
|
8
|
+
* Note:
|
9
|
+
* None of the functions here test things that rely on the network, i.e.
|
10
|
+
* checking that status changes are received, messages can be sent, etc.
|
11
|
+
* All of that is done in a separate test, with two local clients running. */
|
12
|
+
|
13
|
+
#ifdef HAVE_CONFIG_H
|
14
|
+
#include "config.h"
|
15
|
+
#endif
|
16
|
+
|
17
|
+
#include "../testing/misc_tools.c" // hex_string_to_bin
|
18
|
+
#include "../toxcore/Messenger.h"
|
19
|
+
#include <sys/types.h>
|
20
|
+
#include <stdint.h>
|
21
|
+
#include <string.h>
|
22
|
+
#include <check.h>
|
23
|
+
|
24
|
+
#include "helpers.h"
|
25
|
+
|
26
|
+
#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7))
|
27
|
+
#define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0)
|
28
|
+
|
29
|
+
char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db";
|
30
|
+
|
31
|
+
/* in case we need more than one ID for a test */
|
32
|
+
char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441";
|
33
|
+
char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64";
|
34
|
+
|
35
|
+
char *bad_id_str = "9B569D14ff637e69f2";
|
36
|
+
|
37
|
+
unsigned char *friend_id = NULL;
|
38
|
+
unsigned char *good_id_a = NULL;
|
39
|
+
unsigned char *good_id_b = NULL;
|
40
|
+
unsigned char *bad_id = NULL;
|
41
|
+
|
42
|
+
int friend_id_num = 0;
|
43
|
+
|
44
|
+
Messenger *m;
|
45
|
+
|
46
|
+
START_TEST(test_m_sendmesage)
|
47
|
+
{
|
48
|
+
char *message = "h-hi :3";
|
49
|
+
int good_len = strlen(message);
|
50
|
+
int bad_len = MAX_CRYPTO_PACKET_SIZE;
|
51
|
+
|
52
|
+
|
53
|
+
ck_assert(m_sendmessage(m, -1, (uint8_t *)message, good_len) == 0);
|
54
|
+
ck_assert(m_sendmessage(m, REALLY_BIG_NUMBER, (uint8_t *)message, good_len) == 0);
|
55
|
+
ck_assert(m_sendmessage(m, 17, (uint8_t *)message, good_len) == 0);
|
56
|
+
ck_assert(m_sendmessage(m, friend_id_num, (uint8_t *)message, bad_len) == 0);
|
57
|
+
}
|
58
|
+
END_TEST
|
59
|
+
|
60
|
+
START_TEST(test_m_get_userstatus_size)
|
61
|
+
{
|
62
|
+
int rc = 0;
|
63
|
+
ck_assert_msg((m_get_statusmessage_size(m, -1) == -1),
|
64
|
+
"m_get_statusmessage_size did NOT catch an argument of -1");
|
65
|
+
ck_assert_msg((m_get_statusmessage_size(m, REALLY_BIG_NUMBER) == -1),
|
66
|
+
"m_get_statusmessage_size did NOT catch the following argument: %d\n",
|
67
|
+
REALLY_BIG_NUMBER);
|
68
|
+
rc = m_get_statusmessage_size(m, friend_id_num);
|
69
|
+
|
70
|
+
/* this WILL error if the original m_addfriend_norequest() failed */
|
71
|
+
ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
|
72
|
+
"m_get_statusmessage_size is returning out of range values!\n"
|
73
|
+
"(this can be caused by the error of m_addfriend_norequest"
|
74
|
+
" in the beginning of the suite)\n");
|
75
|
+
}
|
76
|
+
END_TEST
|
77
|
+
|
78
|
+
START_TEST(test_m_set_userstatus)
|
79
|
+
{
|
80
|
+
char *status = "online!";
|
81
|
+
uint16_t good_length = strlen(status);
|
82
|
+
uint16_t bad_length = REALLY_BIG_NUMBER;
|
83
|
+
|
84
|
+
ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1),
|
85
|
+
"m_set_userstatus did NOT catch the following length: %d\n",
|
86
|
+
REALLY_BIG_NUMBER);
|
87
|
+
|
88
|
+
ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0),
|
89
|
+
"m_set_userstatus did NOT return 0 on the following length: %d\n"
|
90
|
+
"MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
|
91
|
+
}
|
92
|
+
END_TEST
|
93
|
+
|
94
|
+
START_TEST(test_m_get_friend_connectionstatus)
|
95
|
+
{
|
96
|
+
ck_assert_msg((m_get_friend_connectionstatus(m, -1) == -1),
|
97
|
+
"m_get_friend_connectionstatus did NOT catch an argument of -1.\n");
|
98
|
+
ck_assert_msg((m_get_friend_connectionstatus(m, REALLY_BIG_NUMBER) == -1),
|
99
|
+
"m_get_friend_connectionstatus did NOT catch an argument of %d.\n",
|
100
|
+
REALLY_BIG_NUMBER);
|
101
|
+
}
|
102
|
+
END_TEST
|
103
|
+
|
104
|
+
START_TEST(test_m_friend_exists)
|
105
|
+
{
|
106
|
+
ck_assert_msg((m_friend_exists(m, -1) == 0),
|
107
|
+
"m_friend_exists did NOT catch an argument of -1.\n");
|
108
|
+
ck_assert_msg((m_friend_exists(m, REALLY_BIG_NUMBER) == 0),
|
109
|
+
"m_friend_exists did NOT catch an argument of %d.\n",
|
110
|
+
REALLY_BIG_NUMBER);
|
111
|
+
}
|
112
|
+
END_TEST
|
113
|
+
|
114
|
+
START_TEST(test_m_delfriend)
|
115
|
+
{
|
116
|
+
ck_assert_msg((m_delfriend(m, -1) == -1),
|
117
|
+
"m_delfriend did NOT catch an argument of -1\n");
|
118
|
+
ck_assert_msg((m_delfriend(m, REALLY_BIG_NUMBER) == -1),
|
119
|
+
"m_delfriend did NOT catch the following number: %d\n",
|
120
|
+
REALLY_BIG_NUMBER);
|
121
|
+
}
|
122
|
+
END_TEST
|
123
|
+
/*
|
124
|
+
START_TEST(test_m_addfriend)
|
125
|
+
{
|
126
|
+
char *good_data = "test";
|
127
|
+
char *bad_data = "";
|
128
|
+
|
129
|
+
int good_len = strlen(good_data);
|
130
|
+
int bad_len = strlen(bad_data);
|
131
|
+
int really_bad_len = (MAX_CRYPTO_PACKET_SIZE - crypto_box_PUBLICKEYBYTES
|
132
|
+
- crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
|
133
|
+
+ crypto_box_ZEROBYTES + 100); */
|
134
|
+
/* TODO: Update this properly to latest master
|
135
|
+
if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG)
|
136
|
+
ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len);
|
137
|
+
*/
|
138
|
+
/* this will error if the original m_addfriend_norequest() failed */
|
139
|
+
/* if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT)
|
140
|
+
ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n"
|
141
|
+
"(this can be caused by the error of m_addfriend_norequest in"
|
142
|
+
" the beginning of the suite)\n");
|
143
|
+
|
144
|
+
if(m_addfriend(m, (uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE)
|
145
|
+
ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len);
|
146
|
+
*/
|
147
|
+
/* this should REALLY error */
|
148
|
+
/*
|
149
|
+
* TODO: validate client_id in m_addfriend?
|
150
|
+
if(m_addfriend((uint8_t *)bad_id, (uint8_t *)good_data, good_len) >= 0)
|
151
|
+
ck_abort_msg("The following ID passed through "
|
152
|
+
"m_addfriend without an error:\n'%s'\n", bad_id_str);
|
153
|
+
|
154
|
+
}
|
155
|
+
END_TEST */
|
156
|
+
|
157
|
+
START_TEST(test_setname)
|
158
|
+
{
|
159
|
+
char *good_name = "consensualCorn";
|
160
|
+
int good_length = strlen(good_name);
|
161
|
+
int bad_length = REALLY_BIG_NUMBER;
|
162
|
+
|
163
|
+
ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1),
|
164
|
+
"setname() did NOT error on %d as a length argument!\n", bad_length);
|
165
|
+
|
166
|
+
ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0),
|
167
|
+
"setname() did NOT return 0 on good arguments!\n");
|
168
|
+
}
|
169
|
+
END_TEST
|
170
|
+
|
171
|
+
START_TEST(test_getself_name)
|
172
|
+
{
|
173
|
+
char *nickname = "testGallop";
|
174
|
+
int len = strlen(nickname);
|
175
|
+
char nick_check[len];
|
176
|
+
|
177
|
+
setname(m, (uint8_t *)nickname, len);
|
178
|
+
getself_name(m, (uint8_t *)nick_check);
|
179
|
+
|
180
|
+
ck_assert_msg((memcmp(nickname, nick_check, len) == 0),
|
181
|
+
"getself_name failed to return the known name!\n"
|
182
|
+
"known name: %s\nreturned: %s\n", nickname, nick_check);
|
183
|
+
}
|
184
|
+
END_TEST
|
185
|
+
|
186
|
+
/* this test is excluded for now, due to lack of a way
|
187
|
+
* to set a friend's status for now.
|
188
|
+
* ideas:
|
189
|
+
* if we have access to the friends list, we could
|
190
|
+
* just add a status manually ourselves. */
|
191
|
+
/*
|
192
|
+
START_TEST(test_m_copy_userstatus)
|
193
|
+
{
|
194
|
+
assert(m_copy_userstatus(-1, buf, MAX_USERSTATUS_LENGTH) == -1);
|
195
|
+
assert(m_copy_userstatus(REALLY_BIG_NUMBER, buf, MAX_USERSTATUS_LENGTH) == -1);
|
196
|
+
m_copy_userstatus(friend_id_num, buf, MAX_USERSTATUS_LENGTH + 6);
|
197
|
+
|
198
|
+
assert(STRINGS_EQUAL(name_buf, friend_id_status));
|
199
|
+
}
|
200
|
+
END_TEST
|
201
|
+
*/
|
202
|
+
|
203
|
+
START_TEST(test_getname)
|
204
|
+
{
|
205
|
+
uint8_t name_buf[MAX_NAME_LENGTH];
|
206
|
+
uint8_t test_name[] = {'f', 'o', 'o'};
|
207
|
+
|
208
|
+
ck_assert(getname(m, -1, name_buf) == -1);
|
209
|
+
ck_assert(getname(m, REALLY_BIG_NUMBER, name_buf) == -1);
|
210
|
+
|
211
|
+
memcpy(m->friendlist[0].name, &test_name[0], 3);
|
212
|
+
m->friendlist[0].name_length = 4;
|
213
|
+
ck_assert(getname(m, 0, &name_buf[0]) == 4);
|
214
|
+
|
215
|
+
ck_assert(strcmp((char *)&name_buf[0], "foo") == 0);
|
216
|
+
}
|
217
|
+
END_TEST
|
218
|
+
|
219
|
+
START_TEST(test_dht_state_saveloadsave)
|
220
|
+
{
|
221
|
+
/* validate that:
|
222
|
+
* a) saving stays within the confined space
|
223
|
+
* b) a save()d state can be load()ed back successfully
|
224
|
+
* c) a second save() is of equal size
|
225
|
+
* d) the second save() is of equal content */
|
226
|
+
size_t i, extra = 64;
|
227
|
+
size_t size = DHT_size(m->dht);
|
228
|
+
uint8_t buffer[size + 2 * extra];
|
229
|
+
memset(buffer, 0xCD, extra);
|
230
|
+
memset(buffer + extra + size, 0xCD, extra);
|
231
|
+
DHT_save(m->dht, buffer + extra);
|
232
|
+
|
233
|
+
for (i = 0; i < extra; i++) {
|
234
|
+
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", i);
|
235
|
+
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", i);
|
236
|
+
}
|
237
|
+
|
238
|
+
int res = DHT_load(m->dht, buffer + extra, size);
|
239
|
+
|
240
|
+
if (res == -1)
|
241
|
+
ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
|
242
|
+
else {
|
243
|
+
char msg[128];
|
244
|
+
size_t offset = res >> 4;
|
245
|
+
uint8_t *ptr = buffer + extra + offset;
|
246
|
+
sprintf(msg, "Failed to load back stored buffer: 0x%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx @%zu/%zu, code %d",
|
247
|
+
ptr[-2], ptr[-1], ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], offset, size, res & 0x0F);
|
248
|
+
ck_assert_msg(res == 0, msg);
|
249
|
+
}
|
250
|
+
|
251
|
+
size_t size2 = DHT_size(m->dht);
|
252
|
+
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
|
253
|
+
|
254
|
+
uint8_t buffer2[size2];
|
255
|
+
DHT_save(m->dht, buffer2);
|
256
|
+
|
257
|
+
ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle");
|
258
|
+
}
|
259
|
+
END_TEST
|
260
|
+
|
261
|
+
START_TEST(test_messenger_state_saveloadsave)
|
262
|
+
{
|
263
|
+
/* validate that:
|
264
|
+
* a) saving stays within the confined space
|
265
|
+
* b) a save()d state can be load()ed back successfully
|
266
|
+
* c) a second save() is of equal size
|
267
|
+
* d) the second save() is of equal content */
|
268
|
+
size_t i, extra = 64;
|
269
|
+
size_t size = messenger_size(m);
|
270
|
+
uint8_t buffer[size + 2 * extra];
|
271
|
+
memset(buffer, 0xCD, extra);
|
272
|
+
memset(buffer + extra + size, 0xCD, extra);
|
273
|
+
messenger_save(m, buffer + extra);
|
274
|
+
|
275
|
+
for (i = 0; i < extra; i++) {
|
276
|
+
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from messenger_save() @%u", i);
|
277
|
+
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from messenger_save() @%u", i);
|
278
|
+
}
|
279
|
+
|
280
|
+
int res = messenger_load(m, buffer + extra, size);
|
281
|
+
|
282
|
+
if (res == -1)
|
283
|
+
ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
|
284
|
+
else {
|
285
|
+
char msg[128];
|
286
|
+
size_t offset = res >> 4;
|
287
|
+
uint8_t *ptr = buffer + extra + offset;
|
288
|
+
sprintf(msg, "Failed to load back stored buffer: 0x%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx @%zu/%zu, code %d",
|
289
|
+
ptr[-2], ptr[-1], ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], offset, size, res & 0x0F);
|
290
|
+
ck_assert_msg(res == 0, msg);
|
291
|
+
}
|
292
|
+
|
293
|
+
size_t size2 = messenger_size(m);
|
294
|
+
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
|
295
|
+
|
296
|
+
uint8_t buffer2[size2];
|
297
|
+
messenger_save(m, buffer2);
|
298
|
+
|
299
|
+
ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "Messenger state changed by store/load/store cycle");
|
300
|
+
}
|
301
|
+
END_TEST
|
302
|
+
|
303
|
+
Suite *messenger_suite(void)
|
304
|
+
{
|
305
|
+
Suite *s = suite_create("Messenger");
|
306
|
+
|
307
|
+
DEFTESTCASE(dht_state_saveloadsave);
|
308
|
+
DEFTESTCASE(messenger_state_saveloadsave);
|
309
|
+
|
310
|
+
DEFTESTCASE(getself_name);
|
311
|
+
DEFTESTCASE(m_get_userstatus_size);
|
312
|
+
DEFTESTCASE(m_set_userstatus);
|
313
|
+
|
314
|
+
/* DEFTESTCASE(m_addfriend); */
|
315
|
+
DEFTESTCASE(m_friend_exists);
|
316
|
+
DEFTESTCASE(m_get_friend_connectionstatus);
|
317
|
+
DEFTESTCASE(m_delfriend);
|
318
|
+
|
319
|
+
DEFTESTCASE(setname);
|
320
|
+
DEFTESTCASE(getname);
|
321
|
+
DEFTESTCASE(m_sendmesage);
|
322
|
+
|
323
|
+
return s;
|
324
|
+
}
|
325
|
+
|
326
|
+
int main(int argc, char *argv[])
|
327
|
+
{
|
328
|
+
Suite *messenger = messenger_suite();
|
329
|
+
SRunner *test_runner = srunner_create(messenger);
|
330
|
+
int number_failed = 0;
|
331
|
+
|
332
|
+
friend_id = hex_string_to_bin(friend_id_str);
|
333
|
+
good_id_a = hex_string_to_bin(good_id_a_str);
|
334
|
+
good_id_b = hex_string_to_bin(good_id_b_str);
|
335
|
+
bad_id = hex_string_to_bin(bad_id_str);
|
336
|
+
|
337
|
+
/* IPv6 status from global define */
|
338
|
+
Messenger_Options options = {0};
|
339
|
+
options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
|
340
|
+
m = new_messenger(&options);
|
341
|
+
|
342
|
+
/* setup a default friend and friendnum */
|
343
|
+
if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0)
|
344
|
+
fputs("m_addfriend_norequest() failed on a valid ID!\n"
|
345
|
+
"this was CRITICAL to the test, and the build WILL fail.\n"
|
346
|
+
"the tests will continue now...\n\n", stderr);
|
347
|
+
|
348
|
+
if ((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0)
|
349
|
+
fputs("getfriend_id() failed on a valid ID!\n"
|
350
|
+
"this was CRITICAL to the test, and the build WILL fail.\n"
|
351
|
+
"the tests will continue now...\n\n", stderr);
|
352
|
+
|
353
|
+
srunner_run_all(test_runner, CK_NORMAL);
|
354
|
+
number_failed = srunner_ntests_failed(test_runner);
|
355
|
+
|
356
|
+
srunner_free(test_runner);
|
357
|
+
free(friend_id);
|
358
|
+
free(good_id_a);
|
359
|
+
free(good_id_b);
|
360
|
+
free(bad_id);
|
361
|
+
|
362
|
+
kill_messenger(m);
|
363
|
+
|
364
|
+
return number_failed;
|
365
|
+
}
|