Add port validation for ldap server uri
When a user sets the LDAP server URI with invalid port - value
either less than 0 or greater than 65536, the service should
return error instead of accepting invalid values.
The error that will be returned in this scenario:
Failed to set property LDAPServerURI on interface \
xyz.openbmc_project.User.Ldap.Config: Invalid argument was given.
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: Ie9ff263310fbe97298fd6f18b871d82e300189a2
diff --git a/test/utils_test.cpp b/test/utils_test.cpp
index d312685..7e152b6 100644
--- a/test/utils_test.cpp
+++ b/test/utils_test.cpp
@@ -64,6 +64,18 @@
ipaddress = "ldaps://x.x.x.x";
EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPSscheme));
+
+ ipaddress = "ldap://9.3.185.83:70000";
+ EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
+
+ ipaddress = "ldap://9.3.185.83:-3";
+ EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
+
+ ipaddress = "ldap://9.3.185.83:221";
+ EXPECT_EQ(true, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
+
+ ipaddress = "ldap://9.3.185.83:0";
+ EXPECT_EQ(false, isValidLDAPURI(ipaddress.c_str(), LDAPscheme));
}
} // namespace ldap
} // namespace phosphor