blob: f7962f7f8579d5364122522e5a92a068d67d7708 [file] [log] [blame]
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -06001#include "config.h"
2#include "phosphor-ldap-config/ldap_configuration.hpp"
Ratan Gupta95a29312019-02-18 20:34:10 +05303#include "phosphor-ldap-config/ldap_serialize.hpp"
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -06004
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -06005#include <phosphor-logging/log.hpp>
6#include <phosphor-logging/elog-errors.hpp>
7#include <sdbusplus/bus.hpp>
8#include <xyz/openbmc_project/Common/error.hpp>
9#include <sdbusplus/bus.hpp>
10#include <gmock/gmock.h>
11#include <gtest/gtest.h>
Ratan Gupta95a29312019-02-18 20:34:10 +053012
13#include <filesystem>
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060014#include <fstream>
15#include <string>
16#include <sys/types.h>
17
18namespace phosphor
19{
20namespace ldap
21{
Ratan Gupta95a29312019-02-18 20:34:10 +053022namespace fs = std::filesystem;
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060023namespace ldap_base = sdbusplus::xyz::openbmc_project::User::Ldap::server;
24using Config = phosphor::ldap::Config;
Ratan Gupta95a29312019-02-18 20:34:10 +053025static constexpr const char* dbusPersistFile = "Config";
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060026
27class TestLDAPConfig : public testing::Test
28{
29 public:
30 TestLDAPConfig() : bus(sdbusplus::bus::new_default())
31 {
32 }
33 void SetUp() override
34 {
35 using namespace phosphor::ldap;
36 char tmpldap[] = "/tmp/ldap_test.XXXXXX";
37 dir = fs::path(mkdtemp(tmpldap));
38 fs::path tslCacertFilePath{TLS_CACERT_FILE};
39 tslCacertFile = tslCacertFilePath.filename().c_str();
40 fs::path confFilePath{LDAP_CONFIG_FILE};
41 ldapconfFile = confFilePath.filename().c_str();
42 std::fstream fs;
43 fs.open(dir / defaultNslcdFile, std::fstream::out);
44 fs.close();
45 fs.open(dir / nsSwitchFile, std::fstream::out);
46 fs.close();
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060047 }
48
49 void TearDown() override
50 {
51 fs::remove_all(dir);
52 }
53
54 protected:
55 fs::path dir;
56 std::string tslCacertFile;
57 std::string ldapconfFile;
58 sdbusplus::bus::bus bus;
59};
60
61class MockConfigMgr : public phosphor::ldap::ConfigMgr
62{
63 public:
64 MockConfigMgr(sdbusplus::bus::bus& bus, const char* path,
Ratan Gupta95a29312019-02-18 20:34:10 +053065 const char* filePath, const char* dbusPersistentFile,
66 const char* caCertFile) :
67 phosphor::ldap::ConfigMgr(bus, path, filePath, dbusPersistentFile,
68 caCertFile)
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060069 {
70 }
71 MOCK_METHOD1(restartService, void(const std::string& service));
72 MOCK_METHOD1(stopService, void(const std::string& service));
73 std::unique_ptr<Config>& getConfigPtr()
74 {
75 return configPtr;
76 }
77
78 void restore(const char* filePath)
79 {
80 phosphor::ldap::ConfigMgr::restore(filePath);
81 return;
82 }
83
84 friend class TestLDAPConfig;
85};
86
87TEST_F(TestLDAPConfig, testCreate)
88{
89 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -060090 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +053091 auto dbusPersistentFilePath =
92 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060093
94 if (fs::exists(configFilePath))
95 {
96 fs::remove(configFilePath);
97 }
98 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -060099 MockConfigMgr manager(bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
Ratan Gupta95a29312019-02-18 20:34:10 +0530100 dbusPersistentFilePath.c_str(),
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600101 tlsCacertfile.c_str());
Nagaraju Gorugantibc4f1802018-11-09 03:34:12 -0600102 EXPECT_CALL(manager, restartService("nslcd.service")).Times(1);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600103 EXPECT_CALL(manager, restartService("nscd.service")).Times(1);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600104 manager.createConfig(
105 "ldap://9.194.251.136/", "cn=Users,dc=com", "cn=Users,dc=corp",
106 "MyLdap12", ldap_base::Create::SearchScope::sub,
107 ldap_base::Create::Type::ActiveDirectory, "uid", "gid");
108 manager.getConfigPtr()->enabled(true);
Ratan Gupta95a29312019-02-18 20:34:10 +0530109
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600110 EXPECT_TRUE(fs::exists(configFilePath));
111 EXPECT_EQ(manager.getConfigPtr()->lDAPServerURI(), "ldap://9.194.251.136/");
112 EXPECT_EQ(manager.getConfigPtr()->lDAPBindDN(), "cn=Users,dc=com");
113 EXPECT_EQ(manager.getConfigPtr()->lDAPBaseDN(), "cn=Users,dc=corp");
114 EXPECT_EQ(manager.getConfigPtr()->lDAPSearchScope(),
115 ldap_base::Config::SearchScope::sub);
116 EXPECT_EQ(manager.getConfigPtr()->lDAPType(),
117 ldap_base::Config::Type::ActiveDirectory);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600118 EXPECT_EQ(manager.getConfigPtr()->userNameAttribute(), "uid");
119 EXPECT_EQ(manager.getConfigPtr()->groupNameAttribute(), "gid");
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600120}
121
122TEST_F(TestLDAPConfig, testRestores)
123{
124 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600125 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +0530126 auto dbusPersistentFilePath =
127 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600128
129 if (fs::exists(configFilePath))
130 {
131 fs::remove(configFilePath);
132 }
133 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600134 MockConfigMgr* managerPtr = new MockConfigMgr(
Ratan Gupta95a29312019-02-18 20:34:10 +0530135 bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
136 dbusPersistentFilePath.c_str(), tlsCacertfile.c_str());
137 EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(2);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600138 EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(2);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600139 managerPtr->createConfig(
140 "ldap://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
141 "MyLdap12", ldap_base::Create::SearchScope::sub,
142 ldap_base::Create::Type::ActiveDirectory, "uid", "gid");
Ratan Gupta95a29312019-02-18 20:34:10 +0530143 managerPtr->getConfigPtr()->enabled(false);
144
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600145 EXPECT_TRUE(fs::exists(configFilePath));
Ratan Gupta95a29312019-02-18 20:34:10 +0530146 EXPECT_FALSE(managerPtr->getConfigPtr()->enabled());
147 managerPtr->getConfigPtr()->enabled(true);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600148 // Delete LDAP configuration
149 managerPtr->deleteObject();
150 EXPECT_TRUE(fs::exists(configFilePath));
151 // Restore from configFilePath
152 managerPtr->restore(configFilePath.c_str());
153 // validate restored properties
Ratan Gupta95a29312019-02-18 20:34:10 +0530154 EXPECT_TRUE(managerPtr->getConfigPtr()->enabled());
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600155 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPServerURI(),
156 "ldap://9.194.251.138/");
157 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPBindDN(), "cn=Users,dc=com");
158 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPBaseDN(), "cn=Users,dc=corp");
159 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPSearchScope(),
160 ldap_base::Config::SearchScope::sub);
161 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPType(),
162 ldap_base::Config::Type::ActiveDirectory);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600163 EXPECT_EQ(managerPtr->getConfigPtr()->userNameAttribute(), "uid");
164 EXPECT_EQ(managerPtr->getConfigPtr()->groupNameAttribute(), "gid");
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600165 delete managerPtr;
166}
167
168TEST_F(TestLDAPConfig, testLDAPServerURI)
169{
170 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600171 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +0530172 auto dbusPersistentFilePath =
173 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600174
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600175 if (fs::exists(configFilePath))
176 {
177 fs::remove(configFilePath);
178 }
179 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600180 MockConfigMgr* managerPtr = new MockConfigMgr(
Ratan Gupta95a29312019-02-18 20:34:10 +0530181 bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
182 dbusPersistentFilePath.c_str(), tlsCacertfile.c_str());
183 EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(3);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600184 EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(2);
185
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600186 managerPtr->createConfig(
187 "ldap://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
188 "MyLdap12", ldap_base::Create::SearchScope::sub,
189 ldap_base::Create::Type::ActiveDirectory, "attr1", "attr2");
190 managerPtr->getConfigPtr()->enabled(true);
Ratan Gupta95a29312019-02-18 20:34:10 +0530191
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600192 // Change LDAP Server URI
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600193 managerPtr->getConfigPtr()->lDAPServerURI("ldap://9.194.251.139/");
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600194 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPServerURI(),
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600195 "ldap://9.194.251.139/");
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600196 // Change LDAP Server URI
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600197 EXPECT_THROW(
198 managerPtr->getConfigPtr()->lDAPServerURI("ldaps://9.194.251.139/"),
199 NoCACertificate);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600200 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPServerURI(),
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600201 "ldap://9.194.251.139/");
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600202 // Delete LDAP configuration
203 managerPtr->deleteObject();
204
205 managerPtr->restore(configFilePath.c_str());
206 // Check LDAP Server URI
207 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPServerURI(),
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600208 "ldap://9.194.251.139/");
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600209 delete managerPtr;
210}
211
212TEST_F(TestLDAPConfig, testLDAPBindDN)
213{
214 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600215 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +0530216 auto dbusPersistentFilePath =
217 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600218
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600219 if (fs::exists(configFilePath))
220 {
221 fs::remove(configFilePath);
222 }
223 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600224 MockConfigMgr* managerPtr = new MockConfigMgr(
Ratan Gupta95a29312019-02-18 20:34:10 +0530225 bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
226 dbusPersistentFilePath.c_str(), tlsCacertfile.c_str());
227 EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(3);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600228 EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(2);
229
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600230 managerPtr->createConfig(
231 "ldap://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
232 "MyLdap12", ldap_base::Create::SearchScope::sub,
233 ldap_base::Create::Type::ActiveDirectory, "attr1", "attr2");
234 managerPtr->getConfigPtr()->enabled(true);
Ratan Gupta95a29312019-02-18 20:34:10 +0530235
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600236 // Change LDAP BindDN
237 managerPtr->getConfigPtr()->lDAPBindDN(
238 "cn=Administrator,cn=Users,dc=corp,dc=ibm,dc=com");
239 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPBindDN(),
240 "cn=Administrator,cn=Users,dc=corp,dc=ibm,dc=com");
241 // Change LDAP BindDN
242 EXPECT_THROW(
243 {
244 try
245 {
246 managerPtr->getConfigPtr()->lDAPBindDN("");
247 }
248 catch (const InvalidArgument& e)
249 {
250 throw;
251 }
252 },
253 InvalidArgument);
254 // Delete LDAP configuration
255 managerPtr->deleteObject();
256
257 managerPtr->restore(configFilePath.c_str());
258 // Check LDAP BindDN after restoring
259 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPBindDN(),
260 "cn=Administrator,cn=Users,dc=corp,dc=ibm,dc=com");
261 delete managerPtr;
262}
263
264TEST_F(TestLDAPConfig, testLDAPBaseDN)
265{
266 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600267 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +0530268 auto dbusPersistentFilePath =
269 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600270
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600271 if (fs::exists(configFilePath))
272 {
273 fs::remove(configFilePath);
274 }
275 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600276 MockConfigMgr* managerPtr = new MockConfigMgr(
Ratan Gupta95a29312019-02-18 20:34:10 +0530277 bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
278 dbusPersistentFilePath.c_str(), tlsCacertfile.c_str());
279 EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(3);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600280 EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(2);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600281 managerPtr->createConfig(
282 "ldap://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
283 "MyLdap12", ldap_base::Create::SearchScope::sub,
284 ldap_base::Create::Type::ActiveDirectory, "attr1", "attr2");
285 managerPtr->getConfigPtr()->enabled(true);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600286 // Change LDAP BaseDN
287 managerPtr->getConfigPtr()->lDAPBaseDN(
288 "cn=Administrator,cn=Users,dc=corp,dc=ibm,dc=com");
289 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPBaseDN(),
290 "cn=Administrator,cn=Users,dc=corp,dc=ibm,dc=com");
291 // Change LDAP BaseDN
292 EXPECT_THROW(
293 {
294 try
295 {
296 managerPtr->getConfigPtr()->lDAPBaseDN("");
297 }
298 catch (const InvalidArgument& e)
299 {
300 throw;
301 }
302 },
303 InvalidArgument);
304 // Delete LDAP configuration
305 managerPtr->deleteObject();
306
307 managerPtr->restore(configFilePath.c_str());
308 // Check LDAP BaseDN after restoring
309 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPBaseDN(),
310 "cn=Administrator,cn=Users,dc=corp,dc=ibm,dc=com");
311 delete managerPtr;
312}
313
314TEST_F(TestLDAPConfig, testSearchScope)
315{
316 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600317 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +0530318 auto dbusPersistentFilePath =
319 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600320
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600321 if (fs::exists(configFilePath))
322 {
323 fs::remove(configFilePath);
324 }
325 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600326 MockConfigMgr* managerPtr = new MockConfigMgr(
Ratan Gupta95a29312019-02-18 20:34:10 +0530327 bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
328 dbusPersistentFilePath.c_str(), tlsCacertfile.c_str());
329 EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(3);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600330 EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(2);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600331 managerPtr->createConfig(
332 "ldap://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
333 "MyLdap12", ldap_base::Create::SearchScope::sub,
334 ldap_base::Create::Type::ActiveDirectory, "attr1", "attr2");
335 managerPtr->getConfigPtr()->enabled(true);
Ratan Gupta95a29312019-02-18 20:34:10 +0530336
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600337 // Change LDAP SearchScope
338 managerPtr->getConfigPtr()->lDAPSearchScope(
339 ldap_base::Config::SearchScope::one);
340 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPSearchScope(),
341 ldap_base::Config::SearchScope::one);
342 // Delete LDAP configuration
343 managerPtr->deleteObject();
344
345 managerPtr->restore(configFilePath.c_str());
346 // Check LDAP SearchScope after restoring
347 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPSearchScope(),
348 ldap_base::Config::SearchScope::one);
349 delete managerPtr;
350}
351
352TEST_F(TestLDAPConfig, testLDAPType)
353{
354 auto configFilePath = std::string(dir.c_str()) + "/" + ldapconfFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600355 auto tlsCacertfile = std::string(dir.c_str()) + "/" + tslCacertFile;
Ratan Gupta95a29312019-02-18 20:34:10 +0530356 auto dbusPersistentFilePath =
357 std::string(dir.c_str()) + "/" + dbusPersistFile;
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600358
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600359 if (fs::exists(configFilePath))
360 {
361 fs::remove(configFilePath);
362 }
363 EXPECT_FALSE(fs::exists(configFilePath));
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600364 MockConfigMgr* managerPtr = new MockConfigMgr(
Ratan Gupta95a29312019-02-18 20:34:10 +0530365 bus, LDAP_CONFIG_ROOT, configFilePath.c_str(),
366 dbusPersistentFilePath.c_str(), tlsCacertfile.c_str());
367 EXPECT_CALL(*managerPtr, restartService("nslcd.service")).Times(3);
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600368 EXPECT_CALL(*managerPtr, restartService("nscd.service")).Times(2);
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600369 managerPtr->createConfig(
370 "ldap://9.194.251.138/", "cn=Users,dc=com", "cn=Users,dc=corp",
371 "MyLdap12", ldap_base::Create::SearchScope::sub,
372 ldap_base::Create::Type::ActiveDirectory, "attr1", "attr2");
373 managerPtr->getConfigPtr()->enabled(true);
Ratan Gupta95a29312019-02-18 20:34:10 +0530374
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600375 // Change LDAP type
376 managerPtr->getConfigPtr()->lDAPType(ldap_base::Config::Type::OpenLdap);
377 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPType(),
378 ldap_base::Config::Type::OpenLdap);
379 // Delete LDAP configuration
380 managerPtr->deleteObject();
381
382 managerPtr->restore(configFilePath.c_str());
383 // Check LDAP type after restoring
384 EXPECT_EQ(managerPtr->getConfigPtr()->lDAPType(),
385 ldap_base::Config::Type::OpenLdap);
386 delete managerPtr;
387}
388} // namespace ldap
389} // namespace phosphor