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

Unified Diff: remoting/protocol/fake_authenticator.cc

Issue 8743023: Separate Authenticator and Session unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 1 month 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/protocol/fake_authenticator.cc
diff --git a/remoting/protocol/fake_authenticator.cc b/remoting/protocol/fake_authenticator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d083bd23d061331706fe0c272d0f9a1cf41577b5
--- /dev/null
+++ b/remoting/protocol/fake_authenticator.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2011 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/protocol/fake_authenticator.h"
+
+#include "base/string_number_conversions.h"
+#include "net/socket/stream_socket.h"
+#include "remoting/base/constants.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
+
+namespace remoting {
+namespace protocol {
+
+FakeChannelAuthenticator::FakeChannelAuthenticator(bool accept)
+ : accept_(accept) {
+}
+
+FakeChannelAuthenticator::~FakeChannelAuthenticator() {
+}
+
+void FakeChannelAuthenticator::SecureAndAuthenticate(
+ net::StreamSocket* socket, const DoneCallback& done_callback){
+ if (accept_) {
+ done_callback.Run(net::OK, socket);
Wez 2011/12/09 23:42:33 The ChannelAuthenticator allows asynchronous compl
Sergey Ulanov 2011/12/12 22:52:00 Done.
+ } else {
+ delete socket;
+ done_callback.Run(net::ERR_FAILED, NULL);
+ }
+}
+
+FakeAuthenticator::FakeAuthenticator(
+ Type type, Action action, int round_trips)
+ : type_(type),
+ action_(action),
+ round_trips_(round_trips),
+ messages_(0) {
+}
+
+FakeAuthenticator::~FakeAuthenticator() {
+}
+
+Authenticator::State FakeAuthenticator::state() const{
+ EXPECT_LE(messages_, round_trips_ * 2);
+ if (messages_ >= round_trips_ * 2) {
+ if (action_ == REJECT) {
+ return REJECTED;
+ } else {
+ return ACCEPTED;
+ }
+ }
+
+ // Don't send the last message if this is a host hat wants to reject
Wez 2011/12/09 23:42:33 typo: hat -> that
Sergey Ulanov 2011/12/12 22:52:00 Done.
+ // a connection.
+ if (messages_ == round_trips_ * 2 - 1 &&
+ type_ == HOST && action_ == REJECT) {
+ return REJECTED;
+ }
+
+ // We are not done yet. process next message.
+ if ((messages_ % 2 == 0 && type_ == CLIENT) ||
+ (messages_ % 2 == 1 && type_ == HOST)) {
+ return MESSAGE_READY;
+ } else {
+ return WAITING_MESSAGE;
+ }
+}
+
+void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message) {
+ EXPECT_EQ(WAITING_MESSAGE, state());
+ std::string id =
+ message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id"));
+ EXPECT_EQ(id, base::IntToString(messages_));
+ ++messages_;
+}
+
+buzz::XmlElement* FakeAuthenticator::GetNextMessage() {
+ EXPECT_EQ(MESSAGE_READY, state());
+
+ buzz::XmlElement* result = new buzz::XmlElement(
+ buzz::QName(kChromotingXmlNamespace, "authentication"));
+ buzz::XmlElement* id = new buzz::XmlElement(
+ buzz::QName(kChromotingXmlNamespace, "id"));
+ id->AddText(base::IntToString(messages_));
+ result->AddElement(id);
+
+ ++messages_;
+ return result;
+}
+
+ChannelAuthenticator*
+FakeAuthenticator::CreateChannelAuthenticator() const {
+ EXPECT_EQ(ACCEPTED, state());
+ return new FakeChannelAuthenticator(action_ != REJECT_CHANNEL);
+}
+
+FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory(
+ FakeAuthenticator::Action action, int round_trips)
+ : action_(action),
+ round_trips_(round_trips) {
+}
+
+FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() {
+}
+
+Authenticator* FakeHostAuthenticatorFactory::CreateAuthenticator(
+ const std::string& remote_jid,
+ const buzz::XmlElement* first_message) {
+ return new FakeAuthenticator(FakeAuthenticator::HOST, action_, round_trips_);
+}
+
+} // namespace protocol
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698