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