buffet: Handle XMPP authentication failures

For the nightly tests there is a fake GCD server used, and as a result
the XMPP client can't authenticate with the XMPP server (since the
access_token is also fake). This simply closes the XMPP connection if we
see a read fail, so that we don't get spammed with 0 size reads.

TEST=manual and FEATURES=test emerge-whirlwind buffet
BUG=brillo:338

Change-Id: Ie8db114fcc197f816f3cb56673d6f393fa05c8e5
Reviewed-on: https://chromium-review.googlesource.com/251587
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Nathan Bullock <nathanbullock@google.com>
Tested-by: Nathan Bullock <nathanbullock@google.com>
diff --git a/buffet/xmpp/xmpp_client.cc b/buffet/xmpp/xmpp_client.cc
index d0f4a56..f98c6bb 100644
--- a/buffet/xmpp/xmpp_client.cc
+++ b/buffet/xmpp/xmpp_client.cc
@@ -61,11 +61,11 @@
 
 }  // namespace
 
-void XmppClient::Read() {
+bool XmppClient::Read() {
   std::string msg;
   if (!connection_->Read(&msg) || msg.size() <= 0) {
-    LOG(ERROR) << "Failed to read from stream";
-    return;
+    LOG(ERROR) << "Failed to read from stream. The socket was probably closed";
+    return false;
   }
 
   // TODO(nathanbullock): Need to add support for TLS (brillo:191).
@@ -82,6 +82,9 @@
       if (std::string::npos != msg.find("success")) {
         state_ = XmppState::kStreamRestartedPostAuthentication;
         connection_->Write(BuildXmppStartStreamCommand());
+      } else if (std::string::npos != msg.find("not-authorized")) {
+        state_ = XmppState::kAuthenticationFailed;
+        return false;
       }
       break;
     case XmppState::kStreamRestartedPostAuthentication:
@@ -114,6 +117,7 @@
     default:
       break;
   }
+  return true;
 }
 
 void XmppClient::StartStream() {