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