Skip to content

Commit

Permalink
chore: updating tests for new way of requesting JWT tokens in mender-…
Browse files Browse the repository at this point in the history
…connect

This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so `mender-connect` requests a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The proposed fix is using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation.

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <[email protected]>
  • Loading branch information
SebOpsahl committed May 26, 2024
1 parent 104298e commit 702954b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
48 changes: 27 additions & 21 deletions tests/acceptance/mocks/mock_dbus_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,32 @@
class IoMenderAuthenticationIface:
"""
<node>
<interface name="io.mender.Authentication1">
<method name="GetJwtToken">
<arg type="s" name="token" direction="out"/>
<arg type="s" name="server_url" direction="out"/>
</method>
<method name="FetchJwtToken">
<arg type="b" name="success" direction="out"/>
</method>
<interface name="io.mender.Authentication1">
<method name="GetJwtToken">
<arg type="s" name="token" direction="out"/>
<arg type="s" name="server_url" direction="out"/>
</method>
<method name="FetchJwtToken">
<arg type="b" name="success" direction="out"/>
</method>
<signal name="JwtTokenStateChange">
<arg type="s" name="token"/>
<arg type="s" name="server_url"/>
</signal>
<method name="MockSetJwtToken">
<arg type="s" name="token" direction="in"/>
<arg type="s" name="server_url" direction="in"/>
</method>
<method name="MockSetJwtTokenAndEmitSignal">
<arg type="s" name="token" direction="in"/>
<arg type="s" name="server_url" direction="in"/>
</method>
</interface>
<arg type="s" name="token"/>
<arg type="s" name="server_url"/>
</signal>
<method name="MockSetJwtToken">
<arg type="s" name="token" direction="in"/>
<arg type="s" name="server_url" direction="in"/>
</method>
<method name="MockSetJwtTokenAndEmitSignal">
<arg type="s" name="token" direction="in"/>
<arg type="s" name="server_url" direction="in"/>
</method>
<method name="MockEmitSignal">
<arg type="b" name="success" direction="out"/>
</method>
</interface>
</node>
"""
"""

def __init__(self):
self.token = ""
Expand All @@ -68,6 +71,9 @@ def MockSetJwtTokenAndEmitSignal(self, token, server_url):
self.JwtTokenStateChange(self.token, self.server_url)
return True

def MockEmitSignal(self):
self.JwtTokenStateChange(self.token, self.server_url)
return True

loop = GLib.MainLoop()
bus = SystemBus()
Expand Down
41 changes: 33 additions & 8 deletions tests/acceptance/test_mender-connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ def dbus_set_token_and_url_and_emit_signal(connection, token, server_url):
)


def dbus_emit_signal(connection):
connection.run(
"dbus-send --print-reply --system "
"--dest=io.mender.AuthenticationManager "
"/io/mender/AuthenticationManager "
"io.mender.Authentication1.MockEmitSignal "
)


def wait_for_string_in_log(connection, since, timeout, search_string):
output = ""
while qemu_system_time(connection) < since + timeout:
Expand Down Expand Up @@ -193,14 +202,22 @@ def test_mender_connect_auth_changes(
"""Test that mender-connect can re-establish the connection on D-Bus signals"""

try:
dbus_set_token_and_url(connection, "token1", "http://localhost:5000")

# start the mender-connect service
startup_time = qemu_system_time(connection)
connection.run(
"systemctl --job-mode=ignore-dependencies start mender-connect"
)

startup_time = qemu_system_time(connection)
# wait until the connection happens
wait_for_string_in_log(
connection, startup_time, 30, "Started Mender Connect service"
)

signal_time = qemu_system_time(connection)
dbus_set_token_and_url_and_emit_signal(
connection, "token1", "http://localhost:5000"
)

# wait for first connect
_ = wait_for_string_in_log(
connection,
Expand Down Expand Up @@ -277,14 +294,22 @@ def test_mender_connect_reconnect(
"""Test that mender-connect can re-establish the connection on remote errors"""

try:
dbus_set_token_and_url(connection, "badtoken", "http://localhost:12345")

# start the mender-connect service
startup_time = qemu_system_time(connection)
connection.run(
"systemctl --job-mode=ignore-dependencies start mender-connect"
)

startup_time = qemu_system_time(connection)
# wait until the connection happens
wait_for_string_in_log(
connection, startup_time, 30, "Started Mender Connect service"
)

signal_time = qemu_system_time(connection)
dbus_set_token_and_url_and_emit_signal(
connection, "badtoken", "http://localhost:12345"
)

# wait for error
if version_is_minimum(bitbake_variables, "mender-connect", "2.3.0"):
error_message = "connection manager failed to connect"
Expand All @@ -305,11 +330,11 @@ def test_mender_connect_reconnect(
)

dbus_set_token_and_url(connection, "", "")
kill_time = qemu_system_time(connection)
# kill the server and wait for error
with_mock_servers[1].kill()
kill_time = qemu_system_time(connection)
_ = wait_for_string_in_log(
connection, kill_time, 300, "error reconnecting:",
connection, kill_time, 300, "waiting for reconnect",
)

# Signal the other server
Expand Down

0 comments on commit 702954b

Please sign in to comment.