test: user_mgr: convert mktemp to mkstemp
`mktemp` is consider deprecated and should no longer be used. Switch
the test case calls to use `mkstemp` instead.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ia9318eff88e403422fc8d40fb6b09b60cd226c76
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 187d3c2..9e55fc8 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -1,6 +1,8 @@
#include "mock_user_mgr.hpp"
#include "user_mgr.hpp"
+#include <unistd.h>
+
#include <sdbusplus/test/sdbus_mock.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/User/Common/error.hpp>
@@ -254,18 +256,42 @@
public:
UserMgrInTest() : UserMgr(busInTest, objectRootInTest)
{
- tempFaillockConfigFile = "/tmp/test-data-XXXXXX";
- mktemp(tempFaillockConfigFile.data());
- EXPECT_NO_THROW(
- dumpStringToFile(rawFailLockConfig, tempFaillockConfigFile));
- tempPWHistoryConfigFile = "/tmp/test-data-XXXXXX";
- mktemp(tempPWHistoryConfigFile.data());
- EXPECT_NO_THROW(
- dumpStringToFile(rawPWHistoryConfig, tempPWHistoryConfigFile));
- tempPWQualityConfigFile = "/tmp/test-data-XXXXXX";
- mktemp(tempPWQualityConfigFile.data());
- EXPECT_NO_THROW(
- dumpStringToFile(rawPWQualityConfig, tempPWQualityConfigFile));
+ {
+ tempFaillockConfigFile = tempFilePath;
+ int fd = mkstemp(tempFaillockConfigFile.data());
+ EXPECT_NE(-1, fd);
+ EXPECT_NO_THROW(
+ dumpStringToFile(rawFailLockConfig, tempFaillockConfigFile));
+ if (fd != -1)
+ {
+ close(fd);
+ }
+ }
+
+ {
+ tempPWHistoryConfigFile = tempFilePath;
+ int fd = mkstemp(tempPWHistoryConfigFile.data());
+ EXPECT_NE(-1, fd);
+ EXPECT_NO_THROW(
+ dumpStringToFile(rawPWHistoryConfig, tempPWHistoryConfigFile));
+ if (fd != -1)
+ {
+ close(fd);
+ }
+ }
+
+ {
+ tempPWQualityConfigFile = tempFilePath;
+ int fd = mkstemp(tempPWQualityConfigFile.data());
+ EXPECT_NE(-1, fd);
+ EXPECT_NO_THROW(
+ dumpStringToFile(rawPWQualityConfig, tempPWQualityConfigFile));
+ if (fd != -1)
+ {
+ close(fd);
+ }
+ }
+
// Set config files to test files
faillockConfigFile = tempFaillockConfigFile;
pwHistoryConfigFile = tempPWHistoryConfigFile;
@@ -361,6 +387,8 @@
MOCK_METHOD(bool, isUserEnabled, (const std::string& userName), (override));
protected:
+ static constexpr auto tempFilePath = "/tmp/test-data-XXXXXX";
+
static sdbusplus::bus_t busInTest;
std::string tempFaillockConfigFile;
std::string tempPWHistoryConfigFile;