[geary/wip/714104-refine-account-dialog] Add some defensive guards against service creds in SecretMediator



commit 91be03c5e5fa315f7b200ef64912baa674b6c1a4
Author: Michael Gratton <mike vee net>
Date:   Thu Dec 20 13:58:47 2018 +1100

    Add some defensive guards against service creds in SecretMediator

 src/client/application/secret-mediator.vala | 52 +++++++++++++++--------------
 1 file changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/src/client/application/secret-mediator.vala b/src/client/application/secret-mediator.vala
index af7a5c0d..fa645e0c 100644
--- a/src/client/application/secret-mediator.vala
+++ b/src/client/application/secret-mediator.vala
@@ -51,7 +51,7 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
                                          Cancellable? cancellable)
         throws GLib.Error {
         bool loaded = false;
-        if (service.remember_password) {
+        if (service.credentials != null && service.remember_password) {
             string? password = yield Secret.password_lookupv(
                 SecretMediator.schema, new_attrs(service), cancellable
             );
@@ -82,34 +82,36 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
                                            Geary.ServiceInformation service,
                                            GLib.Cancellable? cancellable)
         throws GLib.Error {
-        // to prevent multiple dialogs from popping up at the same
-        // time, use a nonblocking mutex to serialize the code
-        int token = yield dialog_mutex.claim_async(null);
+        if (service.credentials != null) {
+            // to prevent multiple dialogs from popping up at the same
+            // time, use a nonblocking mutex to serialize the code
+            int token = yield dialog_mutex.claim_async(null);
 
-        // Ensure main window present to the window
-        this.application.present();
+            // Ensure main window present to the window
+            this.application.present();
 
-        PasswordDialog password_dialog = new PasswordDialog(
-            this.application.get_active_window(),
-            account,
-            service
-        );
-        bool result = password_dialog.run();
+            PasswordDialog password_dialog = new PasswordDialog(
+                this.application.get_active_window(),
+                account,
+                service
+            );
+            bool result = password_dialog.run();
 
-        dialog_mutex.release(ref token);
+            dialog_mutex.release(ref token);
 
-        if (result) {
-            // password_dialog.password should never be null at this
-            // point. It will only be null when password_dialog.run()
-            // returns false, in which case we have already returned.
-            service.credentials = service.credentials.copy_with_token(
-                password_dialog.password
-            );
-            service.remember_password = password_dialog.remember_password;
+            if (result) {
+                // password_dialog.password should never be null at this
+                // point. It will only be null when password_dialog.run()
+                // returns false, in which case we have already returned.
+                service.credentials = service.credentials.copy_with_token(
+                    password_dialog.password
+                );
+                service.remember_password = password_dialog.remember_password;
 
-            yield update_token(account, service, cancellable);
+                yield update_token(account, service, cancellable);
 
-            account.changed();
+                account.changed();
+            }
         }
         return true;
     }
@@ -118,7 +120,7 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
                                    Geary.ServiceInformation service,
                                    Cancellable? cancellable)
         throws Error {
-        if (service.remember_password) {
+        if (service.credentials != null && service.remember_password) {
             try {
                 yield do_store(service, service.credentials.token, cancellable);
             } catch (Error e) {
@@ -194,7 +196,7 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
     private async void do_store(Geary.ServiceInformation service,
                                 string password,
                                 Cancellable? cancellable)
-    throws Error {
+        throws Error {
         yield Secret.password_storev(
             SecretMediator.schema,
             new_attrs(service),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]