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() diff --git a/tests/helper.py b/tests/helper.py index 0b08e4d6..276f40ef 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -25,13 +25,16 @@ 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"), 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!" )