From 9f630d9eb0ce1c103532a4304ea080066199094e Mon Sep 17 00:00:00 2001 From: Richard Marian Thomaiyar Date: Thu, 24 May 2018 10:49:10 +0530 Subject: Basic support for User manager service Basic support for User Manager service methods are implemented. Change-Id: Id42432ec6dd421b99971268add931dcd70876f7c Signed-off-by: Richard Marian Thomaiyar --- test/utest.cpp | 133 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 65 insertions(+), 68 deletions(-) (limited to 'test') diff --git a/test/utest.cpp b/test/utest.cpp index 33e0576..5e17283 100644 --- a/test/utest.cpp +++ b/test/utest.cpp @@ -28,77 +28,70 @@ constexpr auto spPwdp = "$1$1G.cK/YP$JI5t0oliPxZveXOvLcZ/H.:17344:1:90:7:::"; class UserTest : public ::testing::Test { - public: - const std::string md5Salt = '$' + std::string(MD5) + '$' - + std::string(salt) + '$'; - const std::string shaSalt = '$' + std::string(SHA512) + '$' - + std::string(salt) + '$'; - - const std::string entry = fs::path(path).filename().string() + - ':' + std::string(spPwdp); - sdbusplus::bus::bus bus; - phosphor::user::User user; - - // Gets called as part of each TEST_F construction - UserTest() - : bus(sdbusplus::bus::new_default()), - user(bus, path) + public: + const std::string md5Salt = + '$' + std::string(MD5) + '$' + std::string(salt) + '$'; + const std::string shaSalt = + '$' + std::string(SHA512) + '$' + std::string(salt) + '$'; + + const std::string entry = + fs::path(path).filename().string() + ':' + std::string(spPwdp); + sdbusplus::bus::bus bus; + phosphor::user::User user; + + // Gets called as part of each TEST_F construction + UserTest() : bus(sdbusplus::bus::new_default()), user(bus, path) + { + // Create a shadow file entry + std::ofstream file(testShadow); + file << entry; + file.close(); + + // File to compare against + std::ofstream compare(shadowCompare); + compare << entry; + compare.close(); + } + + // Gets called as part of each TEST_F destruction + ~UserTest() + { + if (fs::exists(testShadow)) { - // Create a shadow file entry - std::ofstream file(testShadow); - file << entry; - file.close(); - - // File to compare against - std::ofstream compare(shadowCompare); - compare << entry; - compare.close(); + fs::remove(testShadow); } - // Gets called as part of each TEST_F destruction - ~UserTest() + if (fs::exists(shadowCompare)) { - if (fs::exists(testShadow)) - { - fs::remove(testShadow); - } - - if (fs::exists(shadowCompare)) - { - fs::remove(shadowCompare); - } - } - - /** @brief wrapper for get crypt field */ - auto getCryptField(char* data) - { - return User::getCryptField( - std::forward(data)); - } - - /** @brief wrapper for getSaltString */ - auto getSaltString(const std::string& crypt, - const std::string& salt) - { - return User::getSaltString( - std::forward(crypt), - std::forward(salt)); - } - - /** @brief wrapper for generateHash */ - auto generateHash(const std::string& password, - const std::string& salt) - { - return User::generateHash( - std::forward(password), - std::forward(salt)); - } - - /** @brief Applies the new password */ - auto applyPassword() - { - return user.applyPassword(testShadow, password, salt); + fs::remove(shadowCompare); } + } + + /** @brief wrapper for get crypt field */ + auto getCryptField(char* data) + { + return User::getCryptField(std::forward(data)); + } + + /** @brief wrapper for getSaltString */ + auto getSaltString(const std::string& crypt, const std::string& salt) + { + return User::getSaltString(std::forward(crypt), + std::forward(salt)); + } + + /** @brief wrapper for generateHash */ + auto generateHash(const std::string& password, const std::string& salt) + { + return User::generateHash(std::forward(password), + std::forward(salt)); + } + + /** @brief Applies the new password */ + auto applyPassword() + { + return user.applyPassword(testShadow, password, salt); + } }; /** @brief Makes sure that SHA512 crypt field is extracted @@ -175,8 +168,12 @@ TEST_F(UserTest, verifyShadowPermission) // Compare the permission of 2 files. // file rename would make sure that the permissions // of old are moved to new - struct stat shadow{}; - struct stat compare{}; + struct stat shadow + { + }; + struct stat compare + { + }; stat(testShadow, &shadow); stat(shadowCompare, &compare); -- cgit v1.2.1