1*** Settings ***
2Documentation     Test root user expire password.
3
4Resource          ../lib/resource.robot
5Resource          ../lib/bmc_redfish_resource.robot
6Resource          ../lib/ipmi_client.robot
7Library           ../lib/bmc_ssh_utils.py
8Library           SSHLibrary
9
10Test Setup        Test Setup Execution
11
12*** Test Cases ***
13
14Expire Root Password And Check IPMI Access Fails
15    [Documentation]   Expire root user password and expect an error while access via IPMI.
16    [Tags]  Expire_Root_Password_And_Check_IPMI_Access_Fails
17    [Teardown]  Run Keywords  Wait Until Keyword Succeeds  1 min  10 sec
18    ...  Restore Default Password For Root User  AND  FFDC On Test Case Fail
19
20    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
21
22    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
23    Should Contain  ${output}  password expiry information changed
24
25    ${status}=  Run Keyword And Return Status   Run External IPMI Standard Command  lan print -v
26    Should Be Equal  ${status}  ${False}
27
28Expire And Change Root User Password And Access Via SSH
29    [Documentation]   Expire and change root user password and access via SSH.
30    [Tags]  Expire_Root_User_Password_And_Access_Via_SSH
31    [Teardown]  Run Keywords  Wait Until Keyword Succeeds  1 min  10 sec
32    ...  Restore Default Password For Root User  AND  FFDC On Test Case Fail
33
34    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
35
36    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
37    Should Contain  ${output}  password expiry information changed
38
39    # Change to a valid password.
40    ${resp}=  Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
41    ...  body={'Password': '0penBmc123'}  valid_status_codes=[${HTTP_OK}]
42
43    # Verify login with the new password through SSH.
44    Open Connection And Log In  ${OPENBMC_USERNAME}  0penBmc123
45
46
47Expire Root Password And Update Bad Password Length Via Redfish
48   [Documentation]  Expire root password and update bad password via Redfish and expect an error.
49   [Tags]  Expire_Root_Password_And_Update_Bad_Password_Length_Via_Redfish
50   [Teardown]  Run Keywords  Wait Until Keyword Succeeds  1 min  10 sec
51    ...  Restore Default Password For Root User  AND  FFDC On Test Case Fail
52
53   Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
54   ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
55   Should Contain  ${output}  password expiry information changed
56
57   ${status}=  Run Keyword And Return Status
58   ...  Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
59   ...  body={'Password': '0penBmc0penBmc0penBmc'}
60   Should Be Equal  ${status}  ${False}
61
62*** Keywords ***
63
64Test Setup Execution
65   [Documentation]  Test setup  execution.
66
67   Redfish.login
68   Valid Length  OPENBMC_PASSWORD  min_length=8
69
70Restore Default Password For Root User
71    [Documentation]  Restore default password for root user (i.e. 0penBmc).
72
73    # Set default password for root user.
74    Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
75    ...   body={'Password': '${OPENBMC_PASSWORD}'}  valid_status_codes=[${HTTP_OK}]
76    # Verify that root user is able to run Redfish command using default password.
77    Redfish.login
78
79