mgmt: Fix compilation and test cases when dropping privileges is not supported
Change-Id: I7da7eca3e5019dd5a7ed20b26f6e0c3260a03850
Refs: #3064, #2447
diff --git a/tests/daemon/mgmt/general-config-section.t.cpp b/tests/daemon/mgmt/general-config-section.t.cpp
index ed52046..3428624 100644
--- a/tests/daemon/mgmt/general-config-section.t.cpp
+++ b/tests/daemon/mgmt/general-config-section.t.cpp
@@ -39,30 +39,16 @@
public:
~GeneralConfigSectionFixture()
{
+#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
// revert changes to s_normalUid/s_normalGid, if any
PrivilegeHelper::s_normalUid = ::geteuid();
PrivilegeHelper::s_normalGid = ::getegid();
+#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
}
};
BOOST_FIXTURE_TEST_SUITE(MgmtGeneralConfigSection, GeneralConfigSectionFixture)
-BOOST_AUTO_TEST_CASE(UserAndGroupConfig)
-{
- const std::string CONFIG =
- "general\n"
- "{\n"
- " user nobody\n"
- " group nogroup\n"
- "}\n";
-
- ConfigFile configFile;
-
- general::setConfigFile(configFile);
- BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section"));
-
-}
-
BOOST_AUTO_TEST_CASE(DefaultConfig)
{
const std::string CONFIG =
@@ -78,6 +64,23 @@
BOOST_CHECK(getRouterName().getName().empty());
}
+#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
+
+BOOST_AUTO_TEST_CASE(UserAndGroupConfig)
+{
+ const std::string CONFIG =
+ "general\n"
+ "{\n"
+ " user nobody\n"
+ " group nogroup\n"
+ "}\n";
+
+ ConfigFile configFile;
+
+ general::setConfigFile(configFile);
+ BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section"));
+}
+
BOOST_AUTO_TEST_CASE(NoUserConfig)
{
const std::string CONFIG =
@@ -106,6 +109,8 @@
BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section"));
}
+#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
+
static bool
checkExceptionMessage(const ConfigFile::Error& error, const std::string& expected)
{