1010** This program is dual licensed under the MIT or GPLv3 licenses.
1111*/
1212
13+ #include <assert.h>
1314#include <stdio.h>
1415#include <string.h>
1516
17+ #include "test.h"
18+
1619#include "strophe.h"
1720#include "common.h"
1821#include "sasl.h"
@@ -31,7 +34,53 @@ static const char response_md5[] =
3134 "cG9uc2U9NGVhNmU4N2JjMDkzMzUwNzQzZGIyOGQ3MDIwOGNhZmIsY2hhcnNl"
3235 "dD11dGYtOA==" ;
3336
34- int test_plain (xmpp_ctx_t * ctx )
37+ /* stubs to build test without whole libstrophe */
38+ void * strophe_alloc (const xmpp_ctx_t * ctx , size_t size )
39+ {
40+ (void )ctx ;
41+ return malloc (size );
42+ }
43+ void * strophe_realloc (const xmpp_ctx_t * ctx , void * p , size_t size )
44+ {
45+ (void )ctx ;
46+ return realloc (p , size );
47+ }
48+
49+ void strophe_free (const xmpp_ctx_t * ctx , void * p )
50+ {
51+ (void )ctx ;
52+ free (p );
53+ }
54+
55+ xmpp_ctx_t * xmpp_ctx_new (const xmpp_mem_t * mem , const xmpp_log_t * log )
56+ {
57+ return calloc (1 , sizeof (struct _xmpp_ctx_t ));
58+ }
59+
60+ void xmpp_ctx_free (xmpp_ctx_t * ctx )
61+ {
62+ free (ctx );
63+ }
64+
65+ void xmpp_rand_nonce (xmpp_rand_t * rand , char * output , size_t len )
66+ {
67+ const char * nonce = "00DEADBEEF00" ;
68+ memcpy (output , nonce , len );
69+ }
70+
71+ void xmpp_disconnect (xmpp_conn_t * conn ) {}
72+
73+ void strophe_error (const xmpp_ctx_t * ctx ,
74+ const char * area ,
75+ const char * fmt ,
76+ ...)
77+ {
78+ (void )ctx ;
79+ (void )area ;
80+ (void )fmt ;
81+ }
82+
83+ static int test_plain (xmpp_ctx_t * ctx )
3584{
3685 char * result ;
3786
@@ -49,19 +98,43 @@ int test_plain(xmpp_ctx_t *ctx)
4998 return 0 ;
5099}
51100
52- int test_digest_md5 (xmpp_ctx_t * ctx )
101+ static int test_digest_md5 (xmpp_ctx_t * ctx )
53102{
54- char * result ;
55-
56- result =
103+ int ret = 0 ;
104+ char * result =
57105 sasl_digest_md5 (ctx , challenge_md5 , "somenode@somerealm" , "secret" );
58- printf ( "response:\n%s\n" , result );
106+ assert ( result != NULL );
59107 if (strcmp (response_md5 , result )) {
60108 /* generated incorrect response to challenge */
61- return 1 ;
109+ size_t n = 0 ;
110+ char * should , * is ;
111+ printf ("\nshould: %s\n" , response_md5 );
112+ printf (" is: %s\n" , result );
113+ printf (" " );
114+ while (response_md5 [n ] == result [n ]) {
115+ putchar (' ' );
116+ n ++ ;
117+ }
118+ printf ("^\n" );
119+ should =
120+ xmpp_base64_decode_str (ctx , response_md5 , strlen (response_md5 ));
121+ is = xmpp_base64_decode_str (ctx , result , strlen (result ));
122+ printf ("\nshould: %s\n" , should );
123+ printf (" is: %s\n" , is );
124+ printf (" " );
125+ n = 0 ;
126+ while (should [n ] == is [n ]) {
127+ putchar (' ' );
128+ n ++ ;
129+ }
130+ strophe_free (ctx , is );
131+ strophe_free (ctx , should );
132+ printf ("^\n" );
133+ ret = 1 ;
62134 }
135+ strophe_free (ctx , result );
63136
64- return 0 ;
137+ return ret ;
65138}
66139
67140int main ()
0 commit comments