Introduce an empty auth type
authorKevin Ottens <kevin.ottens@enioka.com>
Thu, 11 Mar 2021 14:36:33 +0000 (15:36 +0100)
committerallexzander (Rebase PR Action) <allexzander@users.noreply.github.com>
Mon, 15 Mar 2021 09:38:15 +0000 (09:38 +0000)
This is necessary to be able to distinguish between "I decided on basic
by default" and "I didn't write any auth type". To make sure all the
jobs end up writing something we then implement the "I decided on basic
by default" in the slots connected to the job and we assert it in
checkAllDone()

Signed-off-by: Kevin Ottens <kevin.ottens@enioka.com>
src/libsync/networkjobs.cpp
src/libsync/networkjobs.h

index 3f5a05369e942ab4bae92ca9d5cbd0b9e5879d9e..f41bbb9aad3d490ba6d5878c30908e29bbe6ceb3 100644 (file)
@@ -920,6 +920,7 @@ void DetermineAuthTypeJob::start()
     oldFlowRequired->setIgnoreCredentialFailure(true);
 
     connect(get, &SimpleNetworkJob::finishedSignal, this, [this]() {
+        _resultGet = Basic;
         _getDone = true;
         checkAllDone();
     });
@@ -927,8 +928,13 @@ void DetermineAuthTypeJob::start()
         auto authChallenge = reply->rawHeader("WWW-Authenticate").toLower();
         if (authChallenge.contains("bearer ")) {
             _resultPropfind = OAuth;
-        } else if (authChallenge.isEmpty()) {
-            qCWarning(lcDetermineAuthTypeJob) << "Did not receive WWW-Authenticate reply to auth-test PROPFIND";
+        } else {
+            if (authChallenge.isEmpty()) {
+                qCWarning(lcDetermineAuthTypeJob) << "Did not receive WWW-Authenticate reply to auth-test PROPFIND";
+            } else {
+                qCWarning(lcDetermineAuthTypeJob) << "Unknown WWW-Authenticate reply to auth-test PROPFIND:" << authChallenge;
+            }
+            _resultPropfind = Basic;
         }
         _propfindDone = true;
         checkAllDone();
@@ -947,6 +953,8 @@ void DetermineAuthTypeJob::start()
                     }
                 }
             }
+        } else {
+            _resultOldFlow = Basic;
         }
         _oldFlowDone = true;
         checkAllDone();
@@ -962,6 +970,10 @@ void DetermineAuthTypeJob::checkAllDone()
         return;
     }
 
+    Q_ASSERT(_resultGet != NoAuthType);
+    Q_ASSERT(_resultPropfind != NoAuthType);
+    Q_ASSERT(_resultOldFlow != NoAuthType);
+
     auto result = _resultPropfind;
 
     // WebViewFlow > OAuth > Basic
index 99fd1d1f68a9d77f6ac164e468d74fb3ee18df01..c9fd92fb2879277751ee73537ce06f5f17f79a75 100644 (file)
@@ -437,6 +437,7 @@ class OWNCLOUDSYNC_EXPORT DetermineAuthTypeJob : public QObject
     Q_OBJECT
 public:
     enum AuthType {
+        NoAuthType, // used only before we got a chance to probe the server
         Basic, // also the catch-all fallback for backwards compatibility reasons
         OAuth,
         WebViewFlow,
@@ -453,9 +454,9 @@ private:
     void checkAllDone();
 
     AccountPtr _account;
-    AuthType _resultGet = Basic;
-    AuthType _resultPropfind = Basic;
-    AuthType _resultOldFlow = Basic;
+    AuthType _resultGet = NoAuthType;
+    AuthType _resultPropfind = NoAuthType;
+    AuthType _resultOldFlow = NoAuthType;
     bool _getDone = false;
     bool _propfindDone = false;
     bool _oldFlowDone = false;