summaryrefslogtreecommitdiffstats
path: root/test/utest.cpp
diff options
context:
space:
mode:
authorRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-05-24 10:49:10 +0530
committerRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-09-03 14:16:20 +0530
commit9f630d9eb0ce1c103532a4304ea080066199094e (patch)
treeb102a63e2617d928ce82215b07637336ded2db7d /test/utest.cpp
parent10eb23f8d64d197dade920178b193c1979235156 (diff)
downloadphosphor-user-manager-9f630d9eb0ce1c103532a4304ea080066199094e.tar.gz
phosphor-user-manager-9f630d9eb0ce1c103532a4304ea080066199094e.zip
Basic support for User manager service
Basic support for User Manager service methods are implemented. Change-Id: Id42432ec6dd421b99971268add931dcd70876f7c Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'test/utest.cpp')
-rw-r--r--test/utest.cpp133
1 files changed, 65 insertions, 68 deletions
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<decltype(data)>(data));
- }
-
- /** @brief wrapper for getSaltString */
- auto getSaltString(const std::string& crypt,
- const std::string& salt)
- {
- return User::getSaltString(
- std::forward<decltype(crypt)>(crypt),
- std::forward<decltype(salt)>(salt));
- }
-
- /** @brief wrapper for generateHash */
- auto generateHash(const std::string& password,
- const std::string& salt)
- {
- return User::generateHash(
- std::forward<decltype(password)>(password),
- std::forward<decltype(salt)>(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<decltype(data)>(data));
+ }
+
+ /** @brief wrapper for getSaltString */
+ auto getSaltString(const std::string& crypt, const std::string& salt)
+ {
+ return User::getSaltString(std::forward<decltype(crypt)>(crypt),
+ std::forward<decltype(salt)>(salt));
+ }
+
+ /** @brief wrapper for generateHash */
+ auto generateHash(const std::string& password, const std::string& salt)
+ {
+ return User::generateHash(std::forward<decltype(password)>(password),
+ std::forward<decltype(salt)>(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);
OpenPOWER on IntegriCloud