Fix user account status for manually blocked users
User account status in web interface is displayed incorrectly
if account is disabled (or enabled) via ssh.
Test manually:
1. Create new user using web interface
2. Change user account expiration date via ssh
chage -E 1970-01-01 <new user>
User account is blocked
3. Check user status in web interface.
Blocked user account status should be displayed as "Disabled".
Change-Id: I15e93a87653289b5ba76313895da0cf7e5dd2c7c
Signed-off-by: Denis Zlobin <zlobin.d.al@gmail.com>
diff --git a/test/mock_user_mgr.hpp b/test/mock_user_mgr.hpp
index 3440299..99f2b37 100644
--- a/test/mock_user_mgr.hpp
+++ b/test/mock_user_mgr.hpp
@@ -17,6 +17,7 @@
MOCK_METHOD0(getPrivilegeMapperObject, DbusUserObj());
MOCK_METHOD1(userLockedForFailedAttempt, bool(const std::string& userName));
MOCK_METHOD1(userPasswordExpired, bool(const std::string& userName));
+ MOCK_METHOD1(isUserEnabled, bool(const std::string& userName));
MOCK_CONST_METHOD1(getPrimaryGroup, gid_t(const std::string& userName));
MOCK_CONST_METHOD3(isGroupMember,
bool(const std::string& userName, gid_t primaryGid,
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 9c825a4..cf623ae 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -44,6 +44,16 @@
sdbusplus::message::object_path tempObjPath(usersObjPath);
tempObjPath /= userName;
std::string userObj(tempObjPath);
+ if (enabled)
+ {
+ ON_CALL(mockManager, isUserEnabled)
+ .WillByDefault(testing::Return(true));
+ }
+ else
+ {
+ ON_CALL(mockManager, isUserEnabled)
+ .WillByDefault(testing::Return(false));
+ }
mockManager.usersList.emplace(
userName, std::make_unique<phosphor::user::Users>(
mockManager.bus, userObj.c_str(), groupNames, priv,
@@ -261,7 +271,21 @@
pwHistoryConfigFile = tempPWHistoryConfigFile;
pwQualityConfigFile = tempPWQualityConfigFile;
- ON_CALL(*this, executeUserAdd).WillByDefault(testing::Return());
+ ON_CALL(*this, executeUserAdd(testing::_, testing::_, testing::_,
+ testing::Eq(true)))
+ .WillByDefault(
+ [this]() {
+ ON_CALL(*this, isUserEnabled).WillByDefault(testing::Return(true));
+ testing::Return();
+ });
+
+ ON_CALL(*this, executeUserAdd(testing::_, testing::_, testing::_,
+ testing::Eq(false)))
+ .WillByDefault(
+ [this]() {
+ ON_CALL(*this, isUserEnabled).WillByDefault(testing::Return(false));
+ testing::Return();
+ });
ON_CALL(*this, executeUserDelete).WillByDefault(testing::Return());
@@ -275,8 +299,21 @@
ON_CALL(*this, executeUserModify(testing::_, testing::_, testing::_))
.WillByDefault(testing::Return());
- ON_CALL(*this, executeUserModifyUserEnable)
- .WillByDefault(testing::Return());
+ ON_CALL(*this,
+ executeUserModifyUserEnable(testing::_, testing::Eq(true)))
+ .WillByDefault(
+ [this]() {
+ ON_CALL(*this, isUserEnabled).WillByDefault(testing::Return(true));
+ testing::Return();
+ });
+
+ ON_CALL(*this,
+ executeUserModifyUserEnable(testing::_, testing::Eq(false)))
+ .WillByDefault(
+ [this]() {
+ ON_CALL(*this, isUserEnabled).WillByDefault(testing::Return(false));
+ testing::Return();
+ });
ON_CALL(*this, executeGroupCreation(testing::_))
.WillByDefault(testing::Return());
@@ -321,6 +358,8 @@
MOCK_METHOD(void, executeGroupDeletion, (const char*), (override));
+ MOCK_METHOD(bool, isUserEnabled, (const std::string& userName), (override));
+
protected:
static sdbusplus::bus_t busInTest;
std::string tempFaillockConfigFile;
diff --git a/user_mgr.hpp b/user_mgr.hpp
index d7b731c..6addc49 100644
--- a/user_mgr.hpp
+++ b/user_mgr.hpp
@@ -171,6 +171,14 @@
*/
void userEnable(const std::string& userName, bool enabled);
+ /** @brief get user enabled state
+ * method to get user enabled state.
+ *
+ * @param[in] userName - name of the user
+ * @return - user enabled status (true/false)
+ */
+ virtual bool isUserEnabled(const std::string& userName);
+
/** @brief update minimum password length requirement
*
* @param[in] val - minimum password length
@@ -444,14 +452,6 @@
*/
UserSSHLists getUserAndSshGrpList(void);
- /** @brief get user enabled state
- * method to get user enabled state.
- *
- * @param[in] userName - name of the user
- * @return - user enabled status (true/false)
- */
- bool isUserEnabled(const std::string& userName);
-
/** @brief initialize the user manager objects
* method to initialize the user manager objects accordingly
*
diff --git a/users.cpp b/users.cpp
index 8d6df6a..3440b94 100644
--- a/users.cpp
+++ b/users.cpp
@@ -140,7 +140,7 @@
*/
bool Users::userEnabled(void) const
{
- return UsersIface::userEnabled();
+ return manager.isUserEnabled(userName);
}
void Users::setUserEnabled(bool value)