summaryrefslogtreecommitdiffstats
path: root/test/utils_test.cpp
blob: cded32174124c0366c7eb753d10279313b1dadad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "phosphor-ldap-config/utils.hpp"
#include <netinet/in.h>
#include <gtest/gtest.h>
#include <ldap.h>

namespace phosphor
{
namespace ldap
{
constexpr auto LDAPscheme = "ldap";
constexpr auto LDAPSscheme = "ldaps";

class TestUtil : public testing::Test
{
  public:
    TestUtil()
    {
        // Empty
    }
};

TEST_F(TestUtil, URIValidation)
{
    std::string ipaddress = "ldap://0.0.0.0";
    EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));

    ipaddress = "ldap://9.3.185.83";
    EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));

    ipaddress = "ldaps://9.3.185.83";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));

    ipaddress = "ldap://9.3.a.83";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));

    ipaddress = "ldap://9.3.185.a";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));

    ipaddress = "ldap://x.x.x.x";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));

    ipaddress = "ldaps://0.0.0.0";
    EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldap://0.0.0.0";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldaps://9.3.185.83";
    EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldap://9.3.185.83";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldaps://9.3.185.83";
    EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldaps://9.3.185.a";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldaps://9.3.a.83";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));

    ipaddress = "ldaps://x.x.x.x";
    EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
}
} // namespace ldap
} // namespace phosphor
OpenPOWER on IntegriCloud