Fix a security issue with LDAP usernames
[quassel.git] / tests / core / ldapescapetest.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2021 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "testglobal.h"
22
23 #include "ldapescaper.h"
24
25 TEST(LdapEscapeTest, unescaped)
26 {
27     EXPECT_EQ("Babs Jensen",
28               LdapEscaper::escapeQuery("Babs Jensen"));
29     EXPECT_EQ("Tim Howes",
30               LdapEscaper::escapeQuery("Tim Howes"));
31     EXPECT_EQ("Babs J\\2a",
32               LdapEscaper::escapeQuery("Babs J*"));
33 }
34
35 TEST(LdapEscapeTest, escaped)
36 {
37     EXPECT_EQ("Parens R Us \\28for all your parenthetical needs\\29",
38               LdapEscaper::escapeQuery("Parens R Us (for all your parenthetical needs)"));
39     EXPECT_EQ("\\2a",
40               LdapEscaper::escapeQuery("*"));
41     EXPECT_EQ("C:\\5cMyFile",
42               LdapEscaper::escapeQuery("C:\\MyFile"));
43     EXPECT_EQ("Lu\\c4\\8di\\c4\\87",
44               LdapEscaper::escapeQuery("Lu\xc4\x8di\xc4\x87"));
45     EXPECT_EQ("\u0004\u0002Hi",
46               LdapEscaper::escapeQuery("\x04\x02\x48\x69"));
47 }