Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1355)

Unified Diff: remoting/signaling/xmpp_login_handler_unittest.cc

Issue 958703003: Remove dependency on XMPP implementation in WebRTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/signaling/xmpp_login_handler_unittest.cc
diff --git a/remoting/signaling/xmpp_login_handler_unittest.cc b/remoting/signaling/xmpp_login_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e864bef57cf05f6fe6a8c2e62076040e93ed07ea
--- /dev/null
+++ b/remoting/signaling/xmpp_login_handler_unittest.cc
@@ -0,0 +1,182 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/signaling/xmpp_login_handler.h"
+
+#include "base/base64.h"
+#include "base/message_loop/message_loop.h"
+#include "remoting/signaling/xmpp_stream_parser.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
+
+namespace remoting {
+
+char kTestUsername[] = "testUsername@gmail.com";
+char kTestToken[] = "testToken";
+
+class XmppLoginHandlerTest : public testing::Test,
+ public XmppLoginHandler::Delegate {
+ public:
+ XmppLoginHandlerTest()
+ : start_tls_called_(false), error_(SignalStrategy::OK) {}
+
+ void SendMessage(const std::string& message) override {
+ sent_data_ += message;
+ }
+
+ void StartTls() override {
+ start_tls_called_ = true;
+ }
+
+ void OnHandshakeDone(const std::string& jid,
+ scoped_ptr<XmppStreamParser> parser) override {
+ jid_ = jid;
+ parser_ = parser.Pass();
+ }
+
+ void OnLoginHandlerError(SignalStrategy::Error error) override {
+ EXPECT_NE(error, SignalStrategy::OK);
+ error_ = error;
+ }
+
+ protected:
+ void HandshakeBase();
+
+ base::MessageLoop message_loop_;
+
+ scoped_ptr<XmppLoginHandler> login_handler_;
+ std::string sent_data_;
+ bool start_tls_called_;
+ std::string jid_;
+ scoped_ptr<XmppStreamParser> parser_;
+ SignalStrategy::Error error_;
+};
+
+void XmppLoginHandlerTest::HandshakeBase() {
+ login_handler_.reset(new remoting::XmppLoginHandler(
+ "google.com", kTestUsername, kTestToken, "oauth2", false, this));
+ login_handler_->Start();
+ EXPECT_TRUE(start_tls_called_);
+
+ login_handler_->OnTlsStarted();
+ std::string cookie;
+ base::Base64Encode(
+ std::string("\0", 1) + kTestUsername + std::string("\0", 1) + kTestToken,
+ &cookie);
+ EXPECT_EQ(
+ sent_data_,
+ "<stream:stream to=\"google.com\" version=\"1.0\" "
+ "xmlns=\"jabber:client\" "
+ "xmlns:stream=\"http://etherx.jabber.org/streams\">"
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"X-OAUTH2\" "
+ "auth:service=\"oauth2\" auth:allow-generated-jid=\"true\" "
+ "auth:client-uses-full-bind-result=\"true\" "
+ "auth:allow-non-google-login=\"true\" "
+ "xmlns:auth=\"http://www.google.com/talk/protocol/auth\">" + cookie +
+ "</auth>");
+ sent_data_.clear();
+
+ login_handler_->OnDataReceived(
+ "<stream:stream from=\"google.com\" id=\"DCDDE5171CB2154A\" "
+ "version=\"1.0\" "
+ "xmlns:stream=\"http://etherx.jabber.org/streams\" "
+ "xmlns=\"jabber:client\">"
+ "<stream:features>"
+ "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "<mechanism>X-OAUTH2</mechanism>"
+ "<mechanism>X-GOOGLE-TOKEN</mechanism>"
+ "<mechanism>PLAIN</mechanism>"
+ "</mechanisms>"
+ "</stream:features>");
+}
+
+TEST_F(XmppLoginHandlerTest, SuccessfulAuth) {
+ HandshakeBase();
+
+ login_handler_->OnDataReceived(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>");
+ EXPECT_EQ(
+ sent_data_,
+ "<stream:stream to=\"google.com\" version=\"1.0\" "
+ "xmlns=\"jabber:client\" "
+ "xmlns:stream=\"http://etherx.jabber.org/streams\">"
+ "<iq type=\"set\" id=\"0\">"
+ "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"
+ "<resource>chromoting</resource>"
+ "</bind>"
+ "</iq>"
+ "<iq type=\"set\" id=\"1\">"
+ "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>"
+ "</iq>");
+ sent_data_.clear();
+
+ login_handler_->OnDataReceived(
+ "<stream:stream from=\"google.com\" id=\"104FA10576E2AA80\" "
+ "version=\"1.0\" "
+ "xmlns:stream=\"http://etherx.jabber.org/streams\" "
+ "xmlns=\"jabber:client\">"
+ "<stream:features>"
+ "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"
+ "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>"
+ "</stream:features>"
+ "<iq id=\"0\" type=\"result\">"
+ "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"
+ "<jid>" + std::string(kTestUsername) + "/chromoting52B4920E</jid>"
+ "</bind>"
+ "</iq>"
+ "<iq type=\"result\" id=\"1\"/>");
+
+ EXPECT_EQ(jid_, std::string(kTestUsername) + "/chromoting52B4920E");
+ EXPECT_TRUE(parser_);
+}
+
+TEST_F(XmppLoginHandlerTest, StartTlsHandshake) {
+ login_handler_.reset(new remoting::XmppLoginHandler(
+ "google.com", kTestUsername, kTestToken, "oauth2", true, this));
+ login_handler_->Start();
+ EXPECT_FALSE(start_tls_called_);
+
+ EXPECT_EQ(sent_data_,
+ "<stream:stream to=\"google.com\" version=\"1.0\" "
+ "xmlns=\"jabber:client\" "
+ "xmlns:stream=\"http://etherx.jabber.org/streams\">"
+ "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>");
+ sent_data_.clear();
+
+ login_handler_->OnDataReceived(
+ "<stream:stream from=\"google.com\" id=\"78A87C70559EF28A\" "
+ "version=\"1.0\" "
+ "xmlns:stream=\"http://etherx.jabber.org/streams\" "
+ "xmlns=\"jabber:client\">"
+ "<stream:features>"
+ "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">"
+ "<required/>"
+ "</starttls>"
+ "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "<mechanism>X-OAUTH2</mechanism>"
+ "<mechanism>X-GOOGLE-TOKEN</mechanism>"
+ "</mechanisms>"
+ "</stream:features>");
+
+ login_handler_->OnDataReceived(
+ "<proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>");
+ EXPECT_TRUE(start_tls_called_);
+}
+
+TEST_F(XmppLoginHandlerTest, AuthError) {
+ HandshakeBase();
+
+ login_handler_->OnDataReceived(
+ "<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "<not-authorized/></failure>");
+ EXPECT_EQ(error_, SignalStrategy::AUTHENTICATION_FAILED);
+}
+
+TEST_F(XmppLoginHandlerTest, StreamParseError) {
+ HandshakeBase();
+ login_handler_->OnDataReceived("BAD DATA");
+ EXPECT_EQ(error_, SignalStrategy::PROTOCOL_ERROR);
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698