Branch data Line data Source code
1 : : /* suggest.c --- Test the SASL mechanism suggestion function.
2 : : * Copyright (C) 2002-2012 Simon Josefsson
3 : : *
4 : : * This file is part of GNU SASL.
5 : : *
6 : : * This program is free software: you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation, either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * This program is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : : *
19 : : */
20 : :
21 : : #ifdef HAVE_CONFIG_H
22 : : #include "config.h"
23 : : #endif
24 : :
25 : : #include <stdio.h>
26 : : #include <stdarg.h>
27 : : #include <stdlib.h>
28 : : #include <string.h>
29 : : #include <gsasl.h>
30 : :
31 : : #include "utils.h"
32 : :
33 : : void
34 : 1 : doit (void)
35 : : {
36 : 1 : Gsasl *ctx = NULL;
37 : : const char *str;
38 : : const char *p;
39 : : int res;
40 : :
41 : 1 : res = gsasl_init (&ctx);
42 [ - + ]: 1 : if (res != GSASL_OK)
43 : : {
44 : 0 : fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res));
45 : 1 : return;
46 : : }
47 : :
48 : 1 : str = "FOO BAR FOO";
49 : 1 : p = gsasl_client_suggest_mechanism (ctx, str);
50 [ + - ]: 1 : if (debug)
51 [ - + ]: 1 : printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str,
52 : : p ? p : "(null)");
53 [ - + ]: 1 : if (p)
54 : 0 : fail ("FAIL: not null?!\n");
55 : :
56 [ + - ]: 1 : if (gsasl_client_support_p (ctx, "EXTERNAL"))
57 : : {
58 : 1 : str = "FOO BAR EXTERNAL BAR FOO";
59 : 1 : p = gsasl_client_suggest_mechanism (ctx, str);
60 [ + - ]: 1 : if (debug)
61 : 1 : printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p);
62 [ + - ][ - + ]: 1 : if (!p || strcmp (p, "EXTERNAL") != 0)
63 : 0 : fail ("FAIL: not external?!\n");
64 : : }
65 : :
66 [ + - ]: 1 : if (gsasl_client_support_p (ctx, "CRAM-MD5"))
67 : : {
68 : 1 : str = "FOO BAR CRAM-MD5 BAR FOO";
69 : 1 : p = gsasl_client_suggest_mechanism (ctx, str);
70 [ + - ]: 1 : if (debug)
71 : 1 : printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p);
72 [ + - ][ - + ]: 1 : if (!p || strcmp (p, "CRAM-MD5") != 0)
73 : 0 : fail ("FAIL: not cram-md5?!\n");
74 : : }
75 : :
76 [ + - ]: 1 : if (gsasl_client_support_p (ctx, "PLAIN")
77 [ + - ]: 1 : && gsasl_client_support_p (ctx, "CRAM-MD5"))
78 : : {
79 : 1 : str = "FOO PLAIN CRAM-MD5 BAR FOO";
80 : 1 : p = gsasl_client_suggest_mechanism (ctx, str);
81 [ + - ]: 1 : if (debug)
82 : 1 : printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p);
83 [ + - ][ - + ]: 1 : if (!p || strcmp (p, "CRAM-MD5") != 0)
84 : 0 : fail ("FAIL: not cram-md5?!\n");
85 : : }
86 : :
87 [ + - ]: 1 : if (gsasl_client_support_p (ctx, "PLAIN"))
88 : : {
89 : 1 : str = "FOO PLAIN BAR FOO";
90 : 1 : p = gsasl_client_suggest_mechanism (ctx, str);
91 [ + - ]: 1 : if (debug)
92 : 1 : printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p);
93 [ + - ][ - + ]: 1 : if (!p || strcmp (p, "PLAIN") != 0)
94 : 0 : fail ("FAIL: not plain?!\n");
95 : : }
96 : :
97 [ + - ]: 1 : if (gsasl_client_support_p (ctx, "PLAIN")
98 [ + - ]: 1 : && gsasl_client_support_p (ctx, "CRAM-MD5")
99 [ + - ]: 1 : && gsasl_client_support_p (ctx, "DIGEST-MD5"))
100 : : {
101 : 1 : str = "FOO PLAIN CRAM-MD5 DIGEST-MD5 FOO";
102 : 1 : p = gsasl_client_suggest_mechanism (ctx, str);
103 [ + - ]: 1 : if (debug)
104 : 1 : printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p);
105 [ + - ][ - + ]: 1 : if (!p || strcmp (p, "CRAM-MD5") != 0)
106 : 0 : fail ("FAIL: not cram-md5?!\n");
107 : : }
108 : :
109 : 1 : gsasl_done (ctx);
110 : : }
|