From 53cc9cd18848f17232689e9268e8b9baff124201 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Tue, 26 Feb 2019 11:09:57 +0100 Subject: [PATCH 1/3] Add extra validation to backup list response --- plugins/CuraDrive/src/DriveApiService.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/CuraDrive/src/DriveApiService.py b/plugins/CuraDrive/src/DriveApiService.py index 6a828e32d6..49e242d851 100644 --- a/plugins/CuraDrive/src/DriveApiService.py +++ b/plugins/CuraDrive/src/DriveApiService.py @@ -54,7 +54,13 @@ class DriveApiService: Logger.log("w", "Could not get backups list from remote: %s", backup_list_request.text) Message(catalog.i18nc("@info:backup_status", "There was an error listing your backups."), title = catalog.i18nc("@info:title", "Backup")).show() return [] - return backup_list_request.json()["data"] + + backup_list_response = backup_list_request.json() + if "data" not in backup_list_response: + Logger.log("w", "Could not get backups from remote, actual response body was: %s", str(backup_list_response)) + return [] + + return backup_list_response["data"] def createBackup(self) -> None: self.creatingStateChanged.emit(is_creating = True) From 365f67cbf8ce2489ad6b17329ec5b82527fd5485 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Wed, 27 Feb 2019 10:32:30 +0100 Subject: [PATCH 2/3] Have some overlap in token expiry to prevent unauthorized issues --- cura/OAuth2/AuthorizationService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 3c2f66d037..1a26f26e1d 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -110,7 +110,7 @@ class AuthorizationService: # We have a fallback on a date far in the past for currently stored auth data in cura.cfg. received_at = datetime.strptime(self._auth_data.received_at, TOKEN_TIMESTAMP_FORMAT) \ if self._auth_data.received_at else datetime(2000, 1, 1) - expiry_date = received_at + timedelta(seconds = float(self._auth_data.expires_in or 0)) + expiry_date = received_at + timedelta(seconds = float(self._auth_data.expires_in) - 60 or 0) if datetime.now() > expiry_date: self.refreshAccessToken() From 9ba342c54153bf5926ac1b8417856ac1737775df Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Wed, 27 Feb 2019 10:43:15 +0100 Subject: [PATCH 3/3] Fix codestyle failure on float conversion --- cura/OAuth2/AuthorizationService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 1a26f26e1d..d4ae962f7c 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -110,7 +110,7 @@ class AuthorizationService: # We have a fallback on a date far in the past for currently stored auth data in cura.cfg. received_at = datetime.strptime(self._auth_data.received_at, TOKEN_TIMESTAMP_FORMAT) \ if self._auth_data.received_at else datetime(2000, 1, 1) - expiry_date = received_at + timedelta(seconds = float(self._auth_data.expires_in) - 60 or 0) + expiry_date = received_at + timedelta(seconds = float(self._auth_data.expires_in or 0) - 60) if datetime.now() > expiry_date: self.refreshAccessToken()