From c649deb76c29ccc4c68e3deb59429cc2baa33fa0 Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Fri, 24 May 2024 09:56:33 -0300 Subject: [PATCH 1/3] Fix verification of admin user without "permissions" on JWT Change-type: patch --- tests/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/helper.py b/tests/helper.py index 0b08e4d6..e7e49f85 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -31,7 +31,7 @@ def __init__(self): algorithms=["HS256"], options={"verify_signature": False}, ) - if any("admin" in s for s in token_data["permissions"]): + if "permissions" in token_data.keys() and any("admin" in s for s in token_data["permissions"]): raise Exception( "The test is run with an admin user account. Cancelled, please try" " again with a normal account!" ) From 1eba56f11e0f5f1c22ea707ded06fddb390a3fd4 Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Fri, 24 May 2024 09:57:26 -0300 Subject: [PATCH 2/3] Fix unsubscribe for cases where logs come too early after unsubscribing Change-type: patch --- balena/logs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/balena/logs.py b/balena/logs.py index 6982d6d7..f510e1b1 100644 --- a/balena/logs.py +++ b/balena/logs.py @@ -33,6 +33,7 @@ def __init__(self, callback, error): self.callback = callback self.error = error self.pending = b"" + self.is_running = True def dataReceived(self, data): obj = {} @@ -53,7 +54,8 @@ def dataReceived(self, data): self.error(e) break - self.callback(obj) + if self.is_running: + self.callback(obj) def connectionLost(self, reason): pass @@ -66,6 +68,7 @@ def cbRequest(response, callback, error): def cbDrop(protocol): + protocol.is_running = False protocol.transport.stopProducing() protocol.transport.loseConnection() From 2a3b5a32401a5cefcfce2d33d64be10268755724 Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Fri, 24 May 2024 10:04:39 -0300 Subject: [PATCH 3/3] Force test email to contains "+testsdk" Change-type: patch --- tests/helper.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/helper.py b/tests/helper.py index e7e49f85..276f40ef 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -25,6 +25,9 @@ def __init__(self): } ) + if "+testsdk" not in self.credentials["email"]: + raise Exception("Missing environment credentials, all emails must include `+testsdk` to avoid accidental deletion") # noqa: E501 + # Stop the test if it's run by an admin user account. token_data = jwt.decode( self.balena.settings.get("token"),