Skip to content

Commit 0c9b09e

Browse files
committed
Make test_sasl work
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent d772a3c commit 0c9b09e

2 files changed

Lines changed: 77 additions & 3 deletions

File tree

Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ STATIC_TESTS = \
189189
tests/test_hash \
190190
tests/test_jid \
191191
tests/test_ctx \
192+
tests/test_sasl \
192193
tests/test_send_queue \
193194
tests/test_serialize_sm \
194195
tests/test_string \
@@ -265,6 +266,10 @@ tests_test_resolver_LDFLAGS = -static
265266
tests_test_rand_SOURCES = tests/test_rand.c tests/test.c src/sha1.c
266267
tests_test_rand_CFLAGS = $(STROPHE_FLAGS) -I$(top_srcdir)/src
267268

269+
tests_test_sasl_SOURCES = tests/test_sasl.c src/sasl.c \
270+
src/crypto.c src/hash.c src/jid.c src/md5.c src/scram.c src/sha1.c src/sha256.c src/sha512.c src/snprintf.c src/util.c
271+
tests_test_sasl_CFLAGS = -I$(top_srcdir)/src
272+
268273
tests_test_scram_SOURCES = tests/test_scram.c tests/test.c src/sha1.c \
269274
src/sha256.c src/sha512.c
270275
tests_test_scram_CFLAGS = $(STROPHE_FLAGS) -I$(top_srcdir)/src

tests/test_sasl.c

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <stdio.h>
1414
#include <string.h>
1515

16+
#include "test.h"
17+
1618
#include "strophe.h"
1719
#include "common.h"
1820
#include "sasl.h"
@@ -31,7 +33,53 @@ static const char response_md5[] =
3133
"cG9uc2U9NGVhNmU4N2JjMDkzMzUwNzQzZGIyOGQ3MDIwOGNhZmIsY2hhcnNl"
3234
"dD11dGYtOA==";
3335

34-
int test_plain(xmpp_ctx_t *ctx)
36+
/* stubs to build test without whole libstrophe */
37+
void *strophe_alloc(const xmpp_ctx_t *ctx, size_t size)
38+
{
39+
(void)ctx;
40+
return malloc(size);
41+
}
42+
void *strophe_realloc(const xmpp_ctx_t *ctx, void *p, size_t size)
43+
{
44+
(void)ctx;
45+
return realloc(p, size);
46+
}
47+
48+
void strophe_free(const xmpp_ctx_t *ctx, void *p)
49+
{
50+
(void)ctx;
51+
free(p);
52+
}
53+
54+
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t *mem, const xmpp_log_t *log)
55+
{
56+
return calloc(1, sizeof(struct _xmpp_ctx_t));
57+
}
58+
59+
void xmpp_ctx_free(xmpp_ctx_t *ctx)
60+
{
61+
free(ctx);
62+
}
63+
64+
void xmpp_rand_nonce(xmpp_rand_t *rand, char *output, size_t len)
65+
{
66+
const char *nonce = "00DEADBEEF00";
67+
memcpy(output, nonce, len);
68+
}
69+
70+
void xmpp_disconnect(xmpp_conn_t *conn) {}
71+
72+
void strophe_error(const xmpp_ctx_t *ctx,
73+
const char *area,
74+
const char *fmt,
75+
...)
76+
{
77+
(void)ctx;
78+
(void)area;
79+
(void)fmt;
80+
}
81+
82+
static int test_plain(xmpp_ctx_t *ctx)
3583
{
3684
char *result;
3785

@@ -49,15 +97,36 @@ int test_plain(xmpp_ctx_t *ctx)
4997
return 0;
5098
}
5199

52-
int test_digest_md5(xmpp_ctx_t *ctx)
100+
static int test_digest_md5(xmpp_ctx_t *ctx)
53101
{
54102
char *result;
55103

56104
result =
57105
sasl_digest_md5(ctx, challenge_md5, "somenode@somerealm", "secret");
58-
printf("response:\n%s\n", result);
59106
if (strcmp(response_md5, result)) {
60107
/* generated incorrect response to challenge */
108+
size_t n = 0;
109+
char *should, *is;
110+
printf("\nshould: %s\n", response_md5);
111+
printf(" is: %s\n", result);
112+
printf(" ");
113+
while (response_md5[n] == result[n]) {
114+
putchar(' ');
115+
n++;
116+
}
117+
printf("^\n");
118+
should =
119+
xmpp_base64_decode_str(ctx, response_md5, strlen(response_md5));
120+
is = xmpp_base64_decode_str(ctx, result, strlen(result));
121+
printf("\nshould: %s\n", should);
122+
printf(" is: %s\n", is);
123+
printf(" ");
124+
n = 0;
125+
while (should[n] == is[n]) {
126+
putchar(' ');
127+
n++;
128+
}
129+
printf("^\n");
61130
return 1;
62131
}
63132

0 commit comments

Comments
 (0)