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_unittest.cc b/buffet/xmpp/xmpp_client_unittest.cc
index 9736349..ef26f2e 100644
--- a/buffet/xmpp/xmpp_client_unittest.cc
+++ b/buffet/xmpp/xmpp_client_unittest.cc
@@ -34,8 +34,11 @@
"<required/></starttls><mechanisms "
"xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"><mechanism>X-OAUTH2</mechanism>"
"<mechanism>X-GOOGLE-TOKEN</mechanism></mechanisms></stream:features>";
-constexpr char kAuthenticationResponse[] =
+constexpr char kAuthenticationSucceededResponse[] =
"<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>";
+constexpr char kAuthenticationFailedResponse[] =
+ "<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"><not-authorized/>"
+ "</failure></stream:stream>";
constexpr char kRestartStreamResponse[] =
"<stream:stream from=\"clouddevices.gserviceaccount.com\" "
"id=\"BE7D34E0B7589E2A\" version=\"1.0\" "
@@ -143,12 +146,13 @@
XmppClient::XmppState::kAuthenticationStarted);
}
-TEST_F(XmppClientTest, HandleAuthenticationResponse) {
+TEST_F(XmppClientTest, HandleAuthenticationSucceededResponse) {
TestHelper::SetState(
xmpp_client_.get(),
XmppClient::XmppState::kAuthenticationStarted);
EXPECT_CALL(*connection_, Read(_))
- .WillOnce(DoAll(SetArgPointee<0>(kAuthenticationResponse), Return(true)));
+ .WillOnce(DoAll(SetArgPointee<0>(kAuthenticationSucceededResponse),
+ Return(true)));
EXPECT_CALL(*connection_, Write(kStartStreamMessage))
.WillOnce(Return(true));
xmpp_client_->Read();
@@ -156,6 +160,20 @@
XmppClient::XmppState::kStreamRestartedPostAuthentication);
}
+TEST_F(XmppClientTest, HandleAuthenticationFailedResponse) {
+ TestHelper::SetState(
+ xmpp_client_.get(),
+ XmppClient::XmppState::kAuthenticationStarted);
+ EXPECT_CALL(*connection_, Read(_))
+ .WillOnce(DoAll(SetArgPointee<0>(kAuthenticationFailedResponse),
+ Return(true)));
+ EXPECT_CALL(*connection_, Write(_))
+ .Times(0);
+ xmpp_client_->Read();
+ EXPECT_EQ(TestHelper::GetState(*xmpp_client_),
+ XmppClient::XmppState::kAuthenticationFailed);
+}
+
TEST_F(XmppClientTest, HandleStreamRestartedResponse) {
TestHelper::SetState(
xmpp_client_.get(),