-
Notifications
You must be signed in to change notification settings - Fork 14
Add E2E tests for the msentraid broker #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 42 commits
82c286f
ccefbbd
29276e1
577d58e
cd750f3
d83f0af
b3f4ec1
4a7a178
3dedd8e
f91af83
05f73bc
1775ebc
1146ae5
7d0f822
49a1341
b7e5aff
5ad1646
6093c3b
d13f080
c59cf2d
1dd4626
9379e39
81816f9
7f15d8f
dc566bb
f4fcba0
8fb2eee
a55071a
c4dc0e0
91625fc
809ff78
dd85ff6
3f2cad7
ae133cd
9bcf9c6
4aefdc6
b3f0043
1dcbd50
12bbb3e
3df1bef
e6d0d4b
ff78cbc
740aa91
605aa83
ee1edf8
5aba600
eb5b25b
b99578e
1033a01
3ce35be
d150900
7234026
89be4fb
6e69e9c
9081430
021f883
1817de1
9a34dc6
3604e73
1e6b111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /vm/.artifacts/ | ||
| /.yarf/ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import os | ||
|
|
||
| from robot.api.deco import keyword, library # type: ignore | ||
| from robot.libraries.Process import Process | ||
| from robot.api import logger | ||
|
|
||
| SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
|
||
| def run_command(command: str, *arguments): | ||
| result = Process().run_process(command, *arguments) | ||
| if result.rc == 0: | ||
| return | ||
|
|
||
| cmd = command if not arguments else f"{command} {' '.join(arguments)}" | ||
| message = (f"Command '{cmd}' failed:\n" | ||
| f"--- stdout ---\n{result.stdout}\n" | ||
| f"--- stderr ---\n{result.stderr}") | ||
| logger.error(message) | ||
| raise RuntimeError(f"Command '{cmd}' failed") | ||
|
|
||
|
|
||
| @library | ||
| class Browser: | ||
| @keyword | ||
| async def login(self, username: str, password: str, usercode: str, output_dir: str = "."): | ||
| """Perform device authentication with the given username, password and usercode.""" | ||
| login_script = os.path.join(SCRIPT_DIR, "browser_login.py") | ||
| run_command(login_script, username, password, usercode, output_dir) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,296 @@ | ||
| *** Settings *** | ||
| Documentation MS Entra ID specific resources for the tests | ||
|
|
||
| Resource kvm.resource | ||
| Resource ../authd/utils.resource | ||
| Library ./Browser.py AS Browser | ||
| Library Hid.py AS Hid | ||
|
|
||
| *** Variables *** | ||
| ${ENTRAID_RESOURCES} ${CURDIR} | ||
|
|
||
| ${AUTHD_BROKER_CFG} /etc/authd/brokers.d/msentraid.conf | ||
| ${ENTRAID_BROKER_CFG} /var/snap/authd-msentraid/current/broker.conf | ||
| ${ENTRAID_BROKER_CFG_DIR} /var/snap/authd-msentraid/current/broker.conf.d | ||
|
|
||
|
|
||
| *** Keywords *** | ||
| Enable Edge Broker | ||
| Open Terminal In Sudo Mode | ||
| Run Command In Terminal snap refresh authd-msentraid --edge | ||
| Close Terminal In Sudo Mode | ||
|
|
||
|
|
||
| Disable Broker And Purge Config | ||
| Open Terminal In Sudo Mode | ||
| Run Command In Terminal snap stop authd-msentraid | ||
| Run Command In Terminal rm ${AUTHD_BROKER_CFG} | ||
| Run Command In Terminal systemctl restart authd.service | ||
| Close Terminal In Sudo Mode | ||
|
|
||
|
|
||
| Log In With Remote User Through CLI: QR Code | ||
| [Arguments] ${username} ${local_password} | ||
| Start Log In With Remote User Through CLI: QR Code ${username} | ||
| Select Provider | ||
| Continue Log In With Remote User: Log In On External Browser ${username} | ||
| Continue Log In With Remote User Through CLI: Define Local Password ${username} ${local_password} | ||
|
|
||
|
|
||
| Start Log In With Remote User Through CLI: QR Code | ||
| [Arguments] ${username} | ||
| Hid.Type String machinectl login | ||
| Hid.Keys Combo Return | ||
| Match Text ubuntu login: 60 | ||
| Hid.Type String ${username} | ||
| Hid.Keys Combo Return | ||
|
|
||
| # Check that the provider selection contains the Entra ID provider | ||
| Match Text Select your provider 15 | ||
|
|
||
|
|
||
| Select Provider | ||
| # Check that the provider selection contains the Entra ID provider | ||
| Match Text Select your provider 15 | ||
| Match Text 2. Microsoft Entra ID | ||
|
|
||
| # Select the Entra ID provider | ||
| Hid.Type String 2 | ||
| Builtin.Sleep 2 | ||
|
|
||
| Regenerate QR Code | ||
| # As long as we are in the login process, we can regenerate the QR code | ||
3v1n0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Match Text Request new login code 30 | ||
| Hid.Keys Combo Return | ||
| Match Text https://microsoft.com/devicelogin 15 | ||
|
|
||
|
|
||
| Continue Log In With Remote User: Log In On External Browser | ||
| [Arguments] ${username} | ||
| # Wait until the verification URL and login code are displayed | ||
| Match Text https://microsoft.com/devicelogin | ||
| # Read the user code. | ||
| ${text} = Read Text | ||
| ${user_code} = StringUtils.First Match (https://)?microsoft.com/devicelogin\n((Login code: )?([A-Z0-9]+)) ${text} | ||
|
|
||
| Browser.Login ${username} %{E2E_PASSWORD} ${user_code} ${OUTPUT DIR} | ||
| Builtin.Sleep 5 | ||
|
|
||
|
|
||
| Continue Log In With Remote User Through CLI: Define Local Password | ||
| [Arguments] ${username} ${local_password} | ||
| # The terminal should now be visible and focused again. | ||
| # Check that we're prompted to set a local password. | ||
| Match Text New password: 60 | ||
|
|
||
| # Set a local password | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| # Confirm the local password | ||
| Match Text Confirm password: | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| # Wait for the login to complete | ||
| ${timeout_sec} = Set Variable 30 | ||
| Match Text ${username}@ubuntu ${timeout_sec} | ||
|
|
||
|
|
||
| Log In With Remote User Through CLI: Local Password | ||
| [Arguments] ${username} ${local_password} | ||
| Hid.Type String machinectl login | ||
| Hid.Keys Combo Return | ||
| Match Text ubuntu login: 60 | ||
| Hid.Type String ${username} | ||
| Hid.Keys Combo Return | ||
| Builtin.Sleep 2 | ||
| Match Text Enter your local password: 30 | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
| Builtin.Sleep 2 | ||
| Match Text ${username}@ubuntu:~$ 30 | ||
|
|
||
|
|
||
| # Uses sed to change the broker configuration. | ||
| # It should match both commented and uncommented lines. | ||
| # The full commands looks like: | ||
| # sed -i 's/#*${config_key} = .*/${config_key} = ${config_value}/g' ${ENTRAID_BROKER_CFG} | ||
| Change Broker Configuration | ||
| [Arguments] ${config_key} ${config_value} | ||
| Open Terminal In Sudo Mode | ||
| Hid.Type String sed -i 's/#*${config_key} = .*/${config_key} = ${config_value}/g' ${ENTRAID_BROKER_CFG} | ||
| Hid.Keys Combo Return | ||
| Run Command In Terminal snap restart authd-msentraid | ||
| Close Terminal In Sudo Mode | ||
|
|
||
|
|
||
| # Pretty much the same as the function above, but since YARF does not have support for | ||
| # shifted characters yet, we need to do some workarounds. | ||
| Change allowed_users In Broker Configuration | ||
| [Arguments] ${config_value} | ||
| Run Command In Terminal sudo sed -i 's/#*allowed_users = .*/allowed_users = ${config_value}/g' ${ENTRAID_BROKER_CFG} | ||
| Run Command In Terminal snap restart authd-msentraid | ||
|
|
||
|
|
||
| Comment Key In Broker Configuration | ||
| [Arguments] ${config_key} | ||
| Run Command In Terminal sudo sed -i 's/#*${config_key} = .*/#${config_key} = .*/g' ${ENTRAID_BROKER_CFG} | ||
| Run Command In Terminal snap restart authd-msentraid | ||
|
|
||
|
|
||
| Log In With Remote User Through SSH: QR Code | ||
| [Arguments] ${username} ${local_password} | ||
| Start Log In With Remote User Through SSH: QR Code ${username} | ||
| Select Provider through SSH | ||
| Continue Log In With Remote User: Log In On External Browser ${username} | ||
| Continue Log In With Remote User Through SSH: QR Code | ||
| Continue Log In With Remote User Through SSH: Define Local Password ${username} ${local_password} | ||
|
|
||
|
|
||
| Start Log In With Remote User Through SSH: QR Code | ||
| [Arguments] ${username} | ||
| Hid.Type String ssh ${username}@localhost | ||
| Hid.Keys Combo Return | ||
| Builtin.Sleep 2 | ||
| Hid.Type String yes | ||
| Hid.Keys Combo Return | ||
|
|
||
|
|
||
| Select Provider through SSH | ||
| Match Text 2. Microsoft Entra ID 30 | ||
| Match Text Choose your provider: 30 | ||
| Hid.Type String 2 | ||
| Hid.Keys Combo Return | ||
|
|
||
|
|
||
| Continue Log In With Remote User Through SSH: QR Code | ||
| Match Text Choose action: 30 | ||
| Hid.Type String 1 | ||
| Hid.Keys Combo Return | ||
|
|
||
|
|
||
| Continue Log In With Remote User Through SSH: Define Local Password | ||
| [Arguments] ${username} ${local_password} | ||
| Match Text Create a local password: 30 | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| Match Text Confirm Password: 30 | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| Match Text ${username}@ubuntu:~$ 30 | ||
|
|
||
|
|
||
| Log In With Remote User Through SSH: Local Password | ||
| [Arguments] ${username} ${local_password} | ||
| Hid.Type String ssh ${username}@localhost | ||
| Hid.Keys Combo Return | ||
| Match Text Enter your local password: 30 | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
| Match Text ${username}@ubuntu:~$ 30 | ||
|
|
||
|
|
||
| Log In With Remote User Through GDM: QR Code | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, isn't this common to all brokers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of. The broker name on the list of brokers will change, and if we ever release brokers with different authentication modes, it will complicate things (if we move this to authd.resource), so I think it's better to keep it this way for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but the GDM ui won't change depending on that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to keep authentication-related "functions" in their respective brokers' resources. I know it will create some code duplication, but a little copy here keeps things easier to understand and to find. |
||
| [Arguments] ${username} ${local_password} | ||
| Start Log In With Remote User Through GDM: QR Code ${username} | ||
| Select Broker Through GDM | ||
| Continue Log In With Remote User: Log In On External Browser ${username} | ||
| Continue Log In With Remote User Through GDM: Define Local Password ${local_password} | ||
|
|
||
denisonbarbosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Start Log In With Remote User Through GDM: QR Code | ||
| [Arguments] ${username} | ||
| Match Text Not listed 180 | ||
| Move Pointer To Not Listed | ||
| Left Button Click | ||
|
|
||
| # Enter the username | ||
| Match Text Username | ||
| Hid.Type String ${username} | ||
| Hid.Keys Combo Return | ||
|
|
||
|
|
||
| Select Broker Through GDM | ||
| Match Text Select the broker 30 | ||
| Move Pointer To Microsoft Entra ID | ||
| Left Button Click | ||
| Builtin.Sleep 1 | ||
|
|
||
|
|
||
| Continue Log In With Remote User Through GDM: Define Local Password | ||
| [Arguments] ${local_password} | ||
| Match Text Create a local password 30 | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| Match Text Please, type the new passphrase again 30 | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| Hid.Move Pointer To Proportional 0 1 | ||
| Match Text Show Apps 60 | ||
|
|
||
|
|
||
| Log In With Remote User Through GDM: Local Password | ||
| [Arguments] ${username} ${local_password} | ||
| Match Text Not listed 180 | ||
| Move Pointer To Not Listed | ||
| Left Button Click | ||
| # Enter the username | ||
| Match Text Username | ||
| Hid.Type String ${username} | ||
| Hid.Keys Combo Return | ||
|
|
||
| # Enter the password | ||
| Match Text Password | ||
| Hid.Type String ${local_password} | ||
| Hid.Keys Combo Return | ||
|
|
||
| Hid.Move Pointer To Proportional 0 1 | ||
| Match Text Show Apps 60 | ||
|
|
||
|
|
||
| Check User Information | ||
| [Arguments] ${username} | ||
| Match Text ${username}:x: 30 | ||
|
|
||
|
|
||
| Check User Groups | ||
| [Arguments] ${username} ${remote_group} | ||
| Match Text ${username} sudo ${remote_group} 30 | ||
|
|
||
|
|
||
| Check Configuration Value | ||
| [Arguments] ${config_key} ${expected_value} | ||
| Hid.Type String cat ${ENTRAID_BROKER_CFG} | ||
| # TODO: Even though the Hid.Type String works for most characters now, it seems like there are still issues with | ||
| # some special characters like `|`, so we still need the workaround here. | ||
| Hid.Keys Combo Shift_L | | ||
| Hid.Type String grep ${config_key} | ||
| Hid.Keys Combo Return | ||
| Match Text ${expected_value} 30 | ||
|
|
||
|
|
||
| Check If Owner Was Registered | ||
| [Arguments] ${username} | ||
| Hid.Type String cat ${ENTRAID_BROKER_CFG_DIR}/20-owner-autoregistration.conf | ||
| Hid.Keys Combo Return | ||
| Match Text owner = ${username} 30 | ||
|
|
||
|
|
||
| Check Home Directory | ||
| [Arguments] ${username} | ||
| Hid.Type String echo $HOME | ||
| Hid.Keys Combo Return | ||
| Match Text /home/${username} 30 | ||
| Hid.Type String ls -l | ||
| Hid.Keys Combo Return | ||
| Match Text ${username} ${username} | ||
|
|
||
|
|
||
| Check That Remote User Is Not Allowed To Log In | ||
| Match Text authentication failure: user not allowed in broker configuration 60 | ||
Uh oh!
There was an error while loading. Please reload this page.