From 1f5a002f4b596522cf46eaad3cfd072a44b5848d Mon Sep 17 00:00:00 2001 From: Richard Marian Thomaiyar Date: Sat, 16 Dec 2017 15:11:47 +0530 Subject: Fix to use mkstemp for temp shadow file creation Do not rely on randomString() for tempShadowFile, as it uses '/' in random set, and cause file creation error. Also, it's safe to use mkstemp to create temp shadow file with random name suffixing shadow file name. Change-Id: I0b80cc6d7c002e732e22f660e50b0701acac15fe Signed-off-by: Richard Marian Thomaiyar --- test/utest.cpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'test/utest.cpp') diff --git a/test/utest.cpp b/test/utest.cpp index bdca968..33e0576 100644 --- a/test/utest.cpp +++ b/test/utest.cpp @@ -14,7 +14,6 @@ namespace fs = std::experimental::filesystem; constexpr auto path = "/dummy/user"; constexpr auto testShadow = "/tmp/__tshadow__"; -constexpr auto shadowCopy = "/tmp/__tshadowCopy__"; constexpr auto shadowCompare = "/tmp/__tshadowCompare__"; // New password @@ -64,11 +63,6 @@ class UserTest : public ::testing::Test fs::remove(testShadow); } - if (fs::exists(shadowCopy)) - { - fs::remove(shadowCopy); - } - if (fs::exists(shadowCompare)) { fs::remove(shadowCompare); @@ -103,8 +97,7 @@ class UserTest : public ::testing::Test /** @brief Applies the new password */ auto applyPassword() { - return user.applyPassword(testShadow, shadowCopy, - password, salt); + return user.applyPassword(testShadow, password, salt); } }; @@ -168,22 +161,6 @@ TEST_F(UserTest, applyPassword) EXPECT_EQ(shadowEntry, shadowCompareEntry); } -/** @brief Verifies the shadow copy file is removed - */ -TEST_F(UserTest, checkShadowCopyRemove) -{ - // Update the password so that the temp file is in action - applyPassword(); - - // Compare the permission of 2 files - struct stat shadow{}; - struct stat temp{}; - - stat(testShadow, &shadow); - stat(shadowCopy, &temp); - EXPECT_EQ(false, fs::exists(shadowCopy)); -} - /** @brief Verifies the permissions are correct */ TEST_F(UserTest, verifyShadowPermission) -- cgit v1.2.1