ci: stop adding capabilities before running unit tests
This ensures that all tests pass (or are automatically skipped)
when run as an unprivileged user.
Change-Id: If8b66fd6555de455648576565b1c6cbd02695d1b
Refs: #3418
diff --git a/tests/core/privilege-helper.t.cpp b/tests/core/privilege-helper.t.cpp
index 84c5f39..ce024e9 100644
--- a/tests/core/privilege-helper.t.cpp
+++ b/tests/core/privilege-helper.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -35,10 +35,7 @@
BOOST_AUTO_TEST_CASE(DropRaise)
{
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
- if (::geteuid() != 0) {
- BOOST_TEST_MESSAGE("This test case needs to be run as super user, skipping");
- return;
- }
+ SKIP_IF_NOT_SUPERUSER();
// The following assumes that nobody/nogroup is present on the test system
BOOST_CHECK_NO_THROW(PrivilegeHelper::initialize("nobody", "nogroup"));
@@ -50,14 +47,14 @@
// separate runElevated case to improve log reporting (otherwise output is unreadable)
BOOST_CHECK_NO_THROW(PrivilegeHelper::runElevated([]{}));
PrivilegeHelper::runElevated([] {
- BOOST_CHECK_EQUAL(::geteuid(), 0);
- });
+ BOOST_CHECK_EQUAL(::geteuid(), 0);
+ });
BOOST_CHECK_NE(::geteuid(), 0);
BOOST_CHECK_NO_THROW(PrivilegeHelper::raise());
BOOST_CHECK_EQUAL(::geteuid(), 0);
#else
- BOOST_TEST_MESSAGE("Skipping test, since drop/raise privileges is not supported on this platform");
+ BOOST_TEST_MESSAGE("Dropping/raising privileges not supported on this platform, skipping");
#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
}
diff --git a/tests/daemon/mgmt/face-manager-process-config.t.cpp b/tests/daemon/mgmt/face-manager-process-config.t.cpp
index 16996b8..0ccc75c 100644
--- a/tests/daemon/mgmt/face-manager-process-config.t.cpp
+++ b/tests/daemon/mgmt/face-manager-process-config.t.cpp
@@ -58,7 +58,6 @@
ConfigFile m_config;
};
-
BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture)
#ifdef HAVE_UNIX_SOCKETS
@@ -120,7 +119,6 @@
" listen hello\n"
" }\n"
"}\n";
-
BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
}
@@ -312,9 +310,8 @@
auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second);
BOOST_REQUIRE(factory != nullptr);
- if (factory->getMulticastFaces().size() == 0) {
- BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
- "no UDP multicast faces are available");
+ if (factory->getMulticastFaces().empty()) {
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require at least one UDP multicast face");
return;
}
@@ -335,6 +332,7 @@
BOOST_AUTO_TEST_CASE(ProcessSectionEther)
{
+ SKIP_IF_NOT_SUPERUSER();
const std::string CONFIG =
"face_system\n"
@@ -345,7 +343,6 @@
" mcast_group 01:00:5E:00:17:AA\n"
" }\n"
"}\n";
-
BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
}
@@ -395,6 +392,8 @@
BOOST_AUTO_TEST_CASE(ProcessSectionEtherMulticastReinit)
{
+ SKIP_IF_NOT_SUPERUSER();
+
const std::string CONFIG_WITH_MCAST =
"face_system\n"
"{\n"
@@ -409,9 +408,8 @@
auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second);
BOOST_REQUIRE(factory != nullptr);
- if (factory->getMulticastFaces().size() == 0) {
- BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
- "no Ethernet multicast faces are available");
+ if (factory->getMulticastFaces().empty()) {
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require at least one Ethernet multicast face");
return;
}
diff --git a/tests/daemon/mgmt/general-config-section.t.cpp b/tests/daemon/mgmt/general-config-section.t.cpp
index d3af366..26e87ea 100644
--- a/tests/daemon/mgmt/general-config-section.t.cpp
+++ b/tests/daemon/mgmt/general-config-section.t.cpp
@@ -28,6 +28,8 @@
#include "tests/test-common.hpp"
+#include <cstring>
+
namespace nfd {
namespace general {
namespace tests {
@@ -37,17 +39,18 @@
class GeneralConfigSectionFixture : public BaseFixture
{
public:
+#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
~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
}
+#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
};
-BOOST_FIXTURE_TEST_SUITE(MgmtGeneralConfigSection, GeneralConfigSectionFixture)
+BOOST_AUTO_TEST_SUITE(Mgmt)
+BOOST_FIXTURE_TEST_SUITE(TestGeneralConfigSection, GeneralConfigSectionFixture)
BOOST_AUTO_TEST_CASE(DefaultConfig)
{
@@ -113,12 +116,6 @@
#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
-static bool
-checkExceptionMessage(const ConfigFile::Error& error, const std::string& expected)
-{
- return error.what() == expected;
-}
-
BOOST_AUTO_TEST_CASE(InvalidUserConfig)
{
const std::string CONFIG =
@@ -130,10 +127,12 @@
ConfigFile configFile;
general::setConfigFile(configFile);
- const std::string expected = "Invalid value for \"user\" in \"general\" section";
- BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
- ConfigFile::Error,
- bind(&checkExceptionMessage, _1, expected));
+ BOOST_CHECK_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
+ ConfigFile::Error,
+ [] (const ConfigFile::Error& e) {
+ return std::strcmp(e.what(),
+ "Invalid value for \"user\" in \"general\" section") == 0;
+ });
}
BOOST_AUTO_TEST_CASE(InvalidGroupConfig)
@@ -147,13 +146,16 @@
ConfigFile configFile;
general::setConfigFile(configFile);
- const std::string expected = "Invalid value for \"group\" in \"general\" section";
- BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
- ConfigFile::Error,
- bind(&checkExceptionMessage, _1, expected));
+ BOOST_CHECK_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
+ ConfigFile::Error,
+ [] (const ConfigFile::Error& e) {
+ return std::strcmp(e.what(),
+ "Invalid value for \"group\" in \"general\" section") == 0;
+ });
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestGeneralConfigSection
+BOOST_AUTO_TEST_SUITE_END() // Mgmt
} // namespace tests
} // namespace general
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index ffff22a..9ea3d3c 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -38,7 +38,7 @@
#define SKIP_IF_NOT_SUPERUSER() \
do { \
if (::geteuid() != 0) { \
- BOOST_TEST_MESSAGE("This test case needs to be run as superuser, skipping"); \
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require superuser privileges"); \
return; \
} \
} while (false)