Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : * Test suite for ldap client
4 : *
5 : * Copyright (C) 2018 Andreas Schneider <asn@samba.org>
6 : *
7 : * This program is free software; you can redistribute it and/or modify
8 : * it under the terms of the GNU General Public License as published by
9 : * the Free Software Foundation; either version 3 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * This program is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU General Public License
18 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include <stdarg.h>
22 : #include <stddef.h>
23 : #include <stdint.h>
24 : #include <setjmp.h>
25 : #include <cmocka.h>
26 :
27 : #include "source3/lib/tldap.c"
28 :
29 1 : static void test_tldap_unescape_ldapv3(void **state)
30 : {
31 1 : const char *unescaped_dn = "(&(objectclass=group)(cn=Samba*))";
32 1 : char dn[] = "\\28&\\28objectclass=group\\29\\28cn=Samba\\2a\\29\\29";
33 1 : size_t dnlen = sizeof(dn);
34 : bool ok;
35 :
36 1 : ok = tldap_unescape_inplace(dn, &dnlen);
37 1 : assert_true(ok);
38 :
39 1 : assert_string_equal(dn, unescaped_dn);
40 1 : }
41 :
42 1 : static void test_tldap_unescape_ldapv2(void **state)
43 : {
44 1 : const char *unescaped_dn = "(&(objectclass=group)(cn=Samba*))";
45 1 : char dn[] = "\\(&\\(objectclass=group\\)\\(cn=Samba\\*\\)\\)";
46 1 : size_t dnlen = sizeof(dn);
47 : bool ok;
48 :
49 1 : ok = tldap_unescape_inplace(dn, &dnlen);
50 1 : assert_true(ok);
51 :
52 1 : assert_string_equal(dn, unescaped_dn);
53 1 : }
54 :
55 1 : int main(void) {
56 1 : const struct CMUnitTest tests[] = {
57 : cmocka_unit_test(test_tldap_unescape_ldapv3),
58 : cmocka_unit_test(test_tldap_unescape_ldapv2)
59 : };
60 :
61 1 : cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
62 1 : return cmocka_run_group_tests(tests, NULL, NULL);
63 : }
|