blob: cded32174124c0366c7eb753d10279313b1dadad [file] [log] [blame]
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -06001#include "phosphor-ldap-config/utils.hpp"
2#include <netinet/in.h>
3#include <gtest/gtest.h>
4#include <ldap.h>
5
6namespace phosphor
7{
8namespace ldap
9{
10constexpr auto LDAPscheme = "ldap";
11constexpr auto LDAPSscheme = "ldaps";
12
13class TestUtil : public testing::Test
14{
15 public:
16 TestUtil()
17 {
18 // Empty
19 }
20};
21
22TEST_F(TestUtil, URIValidation)
23{
24 std::string ipaddress = "ldap://0.0.0.0";
25 EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
26
27 ipaddress = "ldap://9.3.185.83";
28 EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
29
30 ipaddress = "ldaps://9.3.185.83";
31 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
32
33 ipaddress = "ldap://9.3.a.83";
34 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
35
36 ipaddress = "ldap://9.3.185.a";
37 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
38
39 ipaddress = "ldap://x.x.x.x";
40 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
41
42 ipaddress = "ldaps://0.0.0.0";
43 EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
44
45 ipaddress = "ldap://0.0.0.0";
46 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
47
48 ipaddress = "ldaps://9.3.185.83";
49 EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
50
51 ipaddress = "ldap://9.3.185.83";
52 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
53
54 ipaddress = "ldaps://9.3.185.83";
55 EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
56
57 ipaddress = "ldaps://9.3.185.a";
58 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
59
60 ipaddress = "ldaps://9.3.a.83";
61 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
62
63 ipaddress = "ldaps://x.x.x.x";
64 EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
65}
66} // namespace ldap
67} // namespace phosphor