User management test suite

Added:
    - Update default "root" user password.

Resolves  openbmc/openbmc-test-automation#888

Change-Id: If7d36dc131e8e367513e5147d2cf1f1b52de121e
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/data/variables.py b/data/variables.py
index afa48a3..35a0339 100644
--- a/data/variables.py
+++ b/data/variables.py
@@ -127,6 +127,9 @@
 NTP_MODE = TIME_DBUS_BASE + 'Synchronization.Method.NTP'
 MANUAL_MODE = TIME_DBUS_BASE + 'Synchronization.Method.Manual'
 
+# User manager variable.
+BMC_USER_URI = OPENBMC_BASE_URI + 'user/'
+
 '''
   QEMU HTTPS variable:
 
diff --git a/lib/rest_client.robot b/lib/rest_client.robot
index b164164..3530bee 100644
--- a/lib/rest_client.robot
+++ b/lib/rest_client.robot
@@ -113,6 +113,8 @@
 
 Initialize OpenBMC
     [Arguments]  ${timeout}=20  ${quiet}=${1}
+    ...  ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
+    ...  ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
 
     # Description of argument(s):
     # timeout  REST login attempt time out.
@@ -122,9 +124,12 @@
     # This will retry at 20 second interval.
     Wait Until Keyword Succeeds  40 sec  20 sec
     ...  Post Login Request  ${timeout}  ${quiet}
+    ...  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
 
 Post Login Request
     [Arguments]  ${timeout}=20  ${quiet}=${1}
+    ...  ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
+    ...  ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
 
     # Description of argument(s):
     # timeout  REST login attempt time out.
diff --git a/tests/security/test_user_management.robot b/tests/security/test_user_management.robot
new file mode 100644
index 0000000..abc3a9a
--- /dev/null
+++ b/tests/security/test_user_management.robot
@@ -0,0 +1,78 @@
+*** Settings ***
+Documentation   OpenBMC user management test.
+
+Resource         ../../lib/rest_client.robot
+Resource         ../../lib/openbmc_ffdc.robot
+Library          SSHLibrary
+
+Test Teardown    Test Teardown Execution
+
+*** Variables ****
+
+${test_password}   abc123
+
+*** Test Cases ***
+
+Verify Root Password Update
+    [Documentation]  Update system "root" user password and verify.
+    [Tags]  Verify_Root_Password_Update
+
+    Delete All Sessions
+
+    Initialize OpenBMC
+    Update Root Password  ${test_password}
+
+    # Time for user manager to sync.
+    Sleep  5 s
+
+    Delete All Sessions
+
+    # SSH Login to BMC with new "root" password.
+    SSHLibrary.Open Connection  ${OPENBMC_HOST}
+    Login  ${OPENBMC_USERNAME}  ${test_password}
+
+    # REST Login to BMC with new "root" password.
+    Initialize OpenBMC  OPENBMC_PASSWORD=${test_password}
+
+    ${resp}=  Get Request  openbmc  ${BMC_USER_URI}enumerate
+    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
+    ...  msg=Verify of new root password failed, RC=${resp.status_code}.
+
+
+*** Keywords ***
+
+Test Teardown Execution
+    [Documentation]  Do test teardown task.
+
+    # REST Login to BMC with new "root" password.
+    Initialize OpenBMC  OPENBMC_PASSWORD=${test_password}
+    Update Root Password
+    Sleep  5 s
+    Delete All Sessions
+
+    # SSH Login to BMC with user default "root" password.
+    SSHLibrary.Open Connection  ${OPENBMC_HOST}
+    Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
+
+    # REST Login to BMC with user default "root" password.
+    Initialize OpenBMC
+
+    FFDC On Test Case Fail
+    Close All Connections
+
+
+Update Root Password
+    [Documentation]  Update system default "root" user password.
+    [Arguments]  ${user_password}=${OPENBMC_PASSWORD}
+
+    # Description of argument(s):
+    # user_password  User password string.
+
+    @{password} =  Create List  ${user_password}
+    ${data} =  Create Dictionary  data=@{password}
+
+    ${headers} =  Create Dictionary  Content-Type=application/json
+    ${resp} =  Post Request  openbmc  ${BMC_USER_URI}root/action/SetPassword
+    ...  data=${data}  headers=${headers}
+    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
+    ...  msg=Updating the new root password failed, RC=${resp.status_code}.