1*** Settings ***
2
3Documentation  Test OpenBMC GUI "User management" sub-menu of "Security and access".
4
5Resource        ../../lib/gui_resource.robot
6
7Suite Setup     Launch Browser And Login GUI
8Suite Teardown  Close Browser
9Test Setup      Test Setup Execution
10
11
12*** Variables ***
13${xpath_user_management_heading}         //h1[text()="User management"]
14${xpath_select_user}                     //input[contains(@class,"custom-control-input")]
15${xpath_account_policy}                  //button[contains(text(),'Account policy settings')]
16${xpath_add_user}                        //button[contains(text(),'Add user')]
17${xpath_edit_user}                       //*[@data-test-id='userManagement-tableRowAction-edit-0']
18${xpath_delete_user}                     //*[@data-test-id='userManagement-tableRowAction-delete-1']
19${xpath_account_status_enabled_button}   //*[@data-test-id='userManagement-radioButton-statusEnabled']
20${xpath_account_status_disabled_button}  //*[@data-test-id='userManagement-radioButton-statusDisabled']
21${xpath_username_input_button}           //*[@data-test-id='userManagement-input-username']
22${xpath_privilege_list_button}           //*[@data-test-id='userManagement-select-privilege']
23${xpath_password_input_button}           //*[@data-test-id='userManagement-input-password']
24${xpath_password_confirm_button}         //*[@data-test-id='userManagement-input-passwordConfirmation']
25${xpath_cancel_button}                   //*[@data-test-id='userManagement-button-cancel']
26${xpath_submit_button}                   //*[@data-test-id='userManagement-button-submit']
27${xpath_add_user_heading}                //h5[contains(text(),'Add user')]
28${xpath_policy_settings_header}          //*[text()="Account policy settings"]
29${xpath_auto_unlock}                     //*[@data-test-id='userManagement-radio-automaticUnlock']
30${xpath_manual_unlock}                   //*[@data-test-id='userManagement-radio-manualUnlock']
31${xpath_max_failed_login}                //*[@data-test-id='userManagement-input-lockoutThreshold']
32${test_user_password}                    TestPwd1
33
34*** Test Cases ***
35
36Verify Navigation To User Management Page
37    [Documentation]  Verify navigation to user management page.
38    [Tags]  Verify_Navigation_To_User_Management_Page
39
40    Page Should Contain Element  ${xpath_user_management_heading}
41
42
43Verify Existence Of All Sections In User Management Page
44    [Documentation]  Verify existence of all sections in user management page.
45    [Tags]  Verify_Existence_Of_All_Sections_In_User_Management_Page
46
47    Page should contain  View privilege role descriptions
48
49
50Verify Existence Of All Input Boxes In User Management Page
51    [Documentation]  Verify existence of all sections in user managemnet page.
52    [Tags]  Verify_Existence_Of_All_Input_Boxes_In_User_Management_Page
53
54    Page Should Contain Checkbox  ${xpath_select_user}
55
56
57Verify Existence Of All Buttons In User Management Page
58    [Documentation]  Verify existence of all buttons in user management page.
59    [Tags]  Verify_Existence_Of_All_Buttons_In_User_Management_Page
60
61    Page should contain Button  ${xpath_account_policy}
62    Page should contain Button  ${xpath_add_user}
63    Page Should Contain Element  ${xpath_edit_user}
64    Page Should Contain Element  ${xpath_delete_user}
65
66
67Verify Existence Of All Button And Fields In Add User
68    [Documentation]  Verify existence of all buttons and fields in add user page.
69    [Tags]  Verify_Existence_Of_All_Button_And_Fields_In_Add_User
70    [Teardown]  Click Element  ${xpath_cancel_button}
71
72    Click Element  ${xpath_add_user}
73    Wait Until Page Contains Element  ${xpath_add_user_heading}
74    Page Should Contain Element  ${xpath_account_status_enabled_button}
75    Page Should Contain Element  ${xpath_account_status_disabled_button}
76    Page Should Contain Element  ${xpath_username_input_button}
77    Page Should Contain Element  ${xpath_privilege_list_button}
78    Page Should Contain Element  ${xpath_password_input_button}
79    Page Should Contain Element  ${xpath_password_confirm_button}
80    Page Should Contain Element  ${xpath_cancel_button}
81    Page Should Contain Element  ${xpath_submit_button}
82
83
84Verify Existence Of All Buttons And Fields In Account Policy Settings
85    [Documentation]  Verify existence of all buttons and fields in account policy settings page.
86    [Tags]  Verify_Existence_Of_All_Buttons_And_Fields_In_Account_Policy_Settings
87    [Teardown]  Click Element  ${xpath_cancel_button}
88
89    Click Element  ${xpath_account_policy}
90    Wait Until Page Contains Element  ${xpath_policy_settings_header}
91    Page Should Contain Element  ${xpath_auto_unlock}
92    Page Should Contain Element  ${xpath_manual_unlock}
93    Page Should Contain Element  ${xpath_max_failed_login}
94    Page Should Contain Element  ${xpath_submit_button}
95    Page Should Contain Element  ${xpath_cancel_button}
96
97
98Verify User Access Privilege
99    [Documentation]  Create a new user with a privilege and verify that user is created.
100    [Tags]  Verify_User_Access_Privilege
101    [Template]  Create User And Verify
102
103    # username      privilege_level  enabled
104    admin_user      Administrator    ${True}
105    operator_user   Operator         ${True}
106    readonly_user   ReadOnly         ${True}
107    noaccess_user   NoAccess         ${True}
108    disabled_user   Administrator    ${False}
109
110
111Verify User Account And Properties Saved Through Reboots
112    [Documentation]  Verify that user account and properties saved through reboots.
113    [Tags]  Verify_User_Account_And_Properties_Saved_Through_Reboots
114
115    # Create an User account.
116    Create User And Verify  my_admin_user  Administrator  ${True}
117
118    # Reboot BMC.
119    Redfish OBMC Reboot (off)  stack_mode=normal
120
121    Click Element  ${xpath_refresh_button}
122    Wait Until Page Contains  my_admin_user  timeout=15
123
124
125*** Keywords ***
126
127Create User And Verify
128    [Documentation]  Create a user with given user name and privilege and verify that the
129    ...  user is created successfully via GUI and Redfish.
130    [Teardown]  Run Keywords  Redfish.Logout  AND  Redfish.Login  AND
131    ...  Redfish.Delete  /redfish/v1/AccountService/Accounts/${user_name}
132    [Arguments]  ${user_name}  ${user_privilege}  ${enabled}
133
134    # Description of argument(s):
135    # user_name           The name of the user to be created (e.g. "test", "robert", etc.).
136    # user_privilege      Privilege of the user.
137    # enabled             If the user is enabled (e.g True if enabled, False if disabled).
138
139    Click Element  ${xpath_add_user}
140    Wait Until Page Contains Element  ${xpath_add_user_heading}
141
142    # Select disabled radio button if user needs to be disabled
143    Run Keyword If  ${enabled} == ${False}
144    ...  Click Element At Coordinates  ${xpath_account_status_disabled_button}  0  0
145
146    # Input username, password and privilege.
147    Input Text  ${xpath_username_input_button}  ${user_name}
148    Select From List by Value  ${xpath_privilege_list_button}  ${user_privilege}
149
150    Input Text  ${xpath_password_input_button}  ${test_user_password}
151
152    Input Text  ${xpath_password_confirm_button}  ${test_user_password}
153
154    # Submit.
155    Click Element  ${xpath_submit_button}
156
157    # Refresh page and check new user is available.
158    Wait Until Page Contains Element  ${xpath_add_user}
159    Click Element  ${xpath_refresh_button}
160    Wait Until Page Contains  ${user_name}  timeout=15
161
162    # Cross check the privilege of newly added user via Redfish.
163    ${user_priv_redfish}=  Redfish_Utils.Get Attribute
164    ...  /redfish/v1/AccountService/Accounts/${user_name}  RoleId
165    Should Be Equal  ${user_privilege}  ${user_priv_redfish}
166
167    # Check enable/disable status for user.
168    Redfish.Logout
169    ${status}=  Run Keyword And Return Status  Redfish.Login  ${user_name}  ${test_user_password}
170    Run Keyword If  ${enabled} == ${False}
171    ...  Should Be Equal  ${status}  ${False}
172    ...  ELSE  Should Be Equal  ${status}  ${True}
173
174
175Test Setup Execution
176    [Documentation]  Do test case setup tasks.
177
178    # Navigate to https://xx.xx.xx.xx/#/access-control/user-management  user management page.
179
180    Click Element  ${xpath_secuity_and_accesss_menu}
181    Click Element  ${xpath_user_management_sub_menu}
182    Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  user-managemen
183