User Mgr: Fix to populate secureLDAP variable while
deserializing based on ldap URI.

Issue is if secureLdap flag isn't populated during deserialize
we see missing nslcd.conf parameters for secure LDAP,due to
which restart nslcd fails.

Tested by:
1.Configure Secure LDAP
2.Login with ldap user
3.reboot, test login with ldap user
4.Conifgure Secure LDAP with same URI
5.login with ldap user
Tested non secure ldap as well.

Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
Change-Id: I31baed446d5155c4bc4a00524a212bd1e565009d
diff --git a/test/ldap_config_test.cpp b/test/ldap_config_test.cpp
index ab354ff..ddeaac6 100644
--- a/test/ldap_config_test.cpp
+++ b/test/ldap_config_test.cpp
@@ -109,6 +109,11 @@
         phosphor::ldap::ConfigMgr::createDefaultObjects();
     }
 
+    bool secureLDAP()
+    {
+        return ADConfigPtr->secureLDAP;
+    }
+
     friend class TestLDAPConfig;
 };
 
@@ -477,6 +482,38 @@
     delete managerPtr;
 }
 
+TEST_F(TestLDAPConfig, testsecureLDAPRestore)
+{
+    auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
+    auto tlsCacertfile = std::string(dir.c_str()) + "/" + tlsCacertFile;
+    auto tlsCertfile = std::string(dir.c_str()) + "/" + tlsCertFile;
+    auto dbusPersistentFilePath = std::string(dir.c_str());
+
+    if (fs::exists(configFilePath))
+    {
+        fs::remove(configFilePath);
+    }
+    EXPECT_FALSE(fs::exists(configFilePath));
+    MockConfigMgr* managerPtr =
+        new MockConfigMgr(bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
+                          dbusPersistentFilePath.c_str(), tlsCacertfile.c_str(),
+                          tlsCertfile.c_str());
+    EXPECT_CALL(*managerPtr, stopService("nslcd.service")).Times(1);
+    EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(1);
+    EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(1);
+    managerPtr->createConfig(
+        "ldaps://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
+        "MyLdap12", ldap_base::Create::SearchScope::sub,
+        ldap_base::Create::Type::ActiveDirectory, "attr1", "attr2");
+    managerPtr->getADConfigPtr()->enabled(true);
+    EXPECT_TRUE(managerPtr->secureLDAP());
+    managerPtr->restore();
+    // Check secureLDAP variable value after restoring
+    EXPECT_TRUE(managerPtr->secureLDAP());
+
+    delete managerPtr;
+}
+
 TEST_F(TestLDAPConfig, filePermission)
 {
     auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;