OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/fake_authenticator.h" | 5 #include "remoting/protocol/fake_authenticator.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/socket/stream_socket.h" | 10 #include "net/socket/stream_socket.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (did_write_bytes_) | 77 if (did_write_bytes_) |
78 done_callback_.Run(result_, socket_.Pass()); | 78 done_callback_.Run(result_, socket_.Pass()); |
79 } | 79 } |
80 | 80 |
81 FakeAuthenticator::FakeAuthenticator( | 81 FakeAuthenticator::FakeAuthenticator( |
82 Type type, int round_trips, Action action, bool async) | 82 Type type, int round_trips, Action action, bool async) |
83 : type_(type), | 83 : type_(type), |
84 round_trips_(round_trips), | 84 round_trips_(round_trips), |
85 action_(action), | 85 action_(action), |
86 async_(async), | 86 async_(async), |
87 messages_(0) { | 87 messages_(0), |
| 88 messages_till_started_(0) { |
88 } | 89 } |
89 | 90 |
90 FakeAuthenticator::~FakeAuthenticator() { | 91 FakeAuthenticator::~FakeAuthenticator() { |
91 } | 92 } |
92 | 93 |
| 94 void FakeAuthenticator::set_messages_till_started(int messages) { |
| 95 messages_till_started_ = messages; |
| 96 } |
| 97 |
93 Authenticator::State FakeAuthenticator::state() const { | 98 Authenticator::State FakeAuthenticator::state() const { |
94 EXPECT_LE(messages_, round_trips_ * 2); | 99 EXPECT_LE(messages_, round_trips_ * 2); |
95 if (messages_ >= round_trips_ * 2) { | 100 if (messages_ >= round_trips_ * 2) { |
96 if (action_ == REJECT) { | 101 if (action_ == REJECT) { |
97 return REJECTED; | 102 return REJECTED; |
98 } else { | 103 } else { |
99 return ACCEPTED; | 104 return ACCEPTED; |
100 } | 105 } |
101 } | 106 } |
102 | 107 |
103 // Don't send the last message if this is a host that wants to | 108 // Don't send the last message if this is a host that wants to |
104 // reject a connection. | 109 // reject a connection. |
105 if (messages_ == round_trips_ * 2 - 1 && | 110 if (messages_ == round_trips_ * 2 - 1 && |
106 type_ == HOST && action_ == REJECT) { | 111 type_ == HOST && action_ == REJECT) { |
107 return REJECTED; | 112 return REJECTED; |
108 } | 113 } |
109 | 114 |
110 // We are not done yet. process next message. | 115 // We are not done yet. process next message. |
111 if ((messages_ % 2 == 0 && type_ == CLIENT) || | 116 if ((messages_ % 2 == 0 && type_ == CLIENT) || |
112 (messages_ % 2 == 1 && type_ == HOST)) { | 117 (messages_ % 2 == 1 && type_ == HOST)) { |
113 return MESSAGE_READY; | 118 return MESSAGE_READY; |
114 } else { | 119 } else { |
115 return WAITING_MESSAGE; | 120 return WAITING_MESSAGE; |
116 } | 121 } |
117 } | 122 } |
118 | 123 |
| 124 bool FakeAuthenticator::started() const { |
| 125 return messages_ > messages_till_started_; |
| 126 } |
| 127 |
119 Authenticator::RejectionReason FakeAuthenticator::rejection_reason() const { | 128 Authenticator::RejectionReason FakeAuthenticator::rejection_reason() const { |
120 EXPECT_EQ(REJECTED, state()); | 129 EXPECT_EQ(REJECTED, state()); |
121 return INVALID_CREDENTIALS; | 130 return INVALID_CREDENTIALS; |
122 } | 131 } |
123 | 132 |
124 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message, | 133 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message, |
125 const base::Closure& resume_callback) { | 134 const base::Closure& resume_callback) { |
126 EXPECT_EQ(WAITING_MESSAGE, state()); | 135 EXPECT_EQ(WAITING_MESSAGE, state()); |
127 std::string id = | 136 std::string id = |
128 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); | 137 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); |
(...skipping 17 matching lines...) Expand all Loading... |
146 } | 155 } |
147 | 156 |
148 scoped_ptr<ChannelAuthenticator> | 157 scoped_ptr<ChannelAuthenticator> |
149 FakeAuthenticator::CreateChannelAuthenticator() const { | 158 FakeAuthenticator::CreateChannelAuthenticator() const { |
150 EXPECT_EQ(ACCEPTED, state()); | 159 EXPECT_EQ(ACCEPTED, state()); |
151 return scoped_ptr<ChannelAuthenticator>( | 160 return scoped_ptr<ChannelAuthenticator>( |
152 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); | 161 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); |
153 } | 162 } |
154 | 163 |
155 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( | 164 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( |
156 int round_trips, FakeAuthenticator::Action action, bool async) | 165 int round_trips, int messages_till_started, |
| 166 FakeAuthenticator::Action action, bool async) |
157 : round_trips_(round_trips), | 167 : round_trips_(round_trips), |
| 168 messages_till_started_(messages_till_started), |
158 action_(action), async_(async) { | 169 action_(action), async_(async) { |
159 } | 170 } |
160 | 171 |
161 FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { | 172 FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { |
162 } | 173 } |
163 | 174 |
164 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( | 175 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( |
165 const std::string& local_jid, | 176 const std::string& local_jid, |
166 const std::string& remote_jid, | 177 const std::string& remote_jid, |
167 const buzz::XmlElement* first_message) { | 178 const buzz::XmlElement* first_message) { |
168 return scoped_ptr<Authenticator>(new FakeAuthenticator( | 179 FakeAuthenticator* authenticator = new FakeAuthenticator( |
169 FakeAuthenticator::HOST, round_trips_, action_, async_)); | 180 FakeAuthenticator::HOST, round_trips_, action_, async_); |
| 181 authenticator->set_messages_till_started(messages_till_started_); |
| 182 |
| 183 scoped_ptr<Authenticator> result(authenticator); |
| 184 return result.Pass(); |
170 } | 185 } |
171 | 186 |
172 } // namespace protocol | 187 } // namespace protocol |
173 } // namespace remoting | 188 } // namespace remoting |
OLD | NEW |