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

Side by Side Diff: remoting/host/it2me/it2me_host_unittest.cc

Issue 2398803002: Disconnect It2Me session if the incoming connection is invalid (Closed)
Patch Set: Prereview cleanup Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/host/it2me/it2me_host.h" 5 #include "remoting/host/it2me/it2me_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 void OnValidationComplete(const base::Closure& resume_callback, 90 void OnValidationComplete(const base::Closure& resume_callback,
91 ValidationResult validation_result); 91 ValidationResult validation_result);
92 92
93 protected: 93 protected:
94 void SetClientDomainPolicy(const std::string& policy_value); 94 void SetClientDomainPolicy(const std::string& policy_value);
95 95
96 void RunValidationCallback(const std::string& remote_jid); 96 void RunValidationCallback(const std::string& remote_jid);
97 97
98 ValidationResult validation_result_ = ValidationResult::SUCCESS; 98 ValidationResult validation_result_ = ValidationResult::SUCCESS;
99 std::string remote_user_email_;
99 100
100 // Used to set ConfirmationDialog behavior. 101 // Used to set ConfirmationDialog behavior.
101 FakeIt2MeConfirmationDialog* dialog_ = nullptr; 102 FakeIt2MeConfirmationDialog* dialog_ = nullptr;
102 103
103 private: 104 private:
104 std::unique_ptr<base::MessageLoop> message_loop_; 105 std::unique_ptr<base::MessageLoop> message_loop_;
105 std::unique_ptr<base::RunLoop> run_loop_; 106 std::unique_ptr<base::RunLoop> run_loop_;
106 107
108 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
109 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
110
107 scoped_refptr<It2MeHost> it2me_host_; 111 scoped_refptr<It2MeHost> it2me_host_;
108 112
109 std::string directory_bot_jid_; 113 std::string directory_bot_jid_;
110 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 114 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
111 115
112 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); 116 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest);
113 }; 117 };
114 118
115 void It2MeHostTest::SetUp() { 119 void It2MeHostTest::SetUp() {
116 message_loop_.reset(new base::MessageLoop()); 120 message_loop_.reset(new base::MessageLoop());
117 run_loop_.reset(new base::RunLoop()); 121 run_loop_.reset(new base::RunLoop());
118 122
119 scoped_refptr<AutoThreadTaskRunner> auto_thread_task_runner = 123 std::unique_ptr<ChromotingHostContext> host_context(
120 new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(), 124 ChromotingHostContext::Create(new AutoThreadTaskRunner(
121 run_loop_->QuitClosure()); 125 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure())));
126 network_task_runner_ = host_context->network_task_runner();
127 ui_task_runner_ = host_context->ui_task_runner();
128
122 dialog_ = new FakeIt2MeConfirmationDialog(); 129 dialog_ = new FakeIt2MeConfirmationDialog();
123 it2me_host_ = new It2MeHost( 130
124 ChromotingHostContext::Create(auto_thread_task_runner), 131 it2me_host_ =
125 /*policy_watcher=*/nullptr, base::WrapUnique(dialog_), 132 new It2MeHost(std::move(host_context), /*policy_watcher=*/nullptr,
126 /*observer=*/nullptr, xmpp_server_config_, directory_bot_jid_); 133 base::WrapUnique(dialog_), /*observer=*/nullptr,
134 xmpp_server_config_, directory_bot_jid_);
127 } 135 }
128 136
129 void It2MeHostTest::TearDown() { 137 void It2MeHostTest::TearDown() {
138 network_task_runner_ = nullptr;
139 ui_task_runner_ = nullptr;
130 it2me_host_ = nullptr; 140 it2me_host_ = nullptr;
131 run_loop_->Run(); 141 run_loop_->Run();
132 } 142 }
133 143
134 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, 144 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback,
135 ValidationResult validation_result) { 145 ValidationResult validation_result) {
136 validation_result_ = validation_result; 146 validation_result_ = validation_result;
137 resume_callback.Run(); 147 remote_user_email_ = dialog_->get_remote_user_email();
148
149 ui_task_runner_->PostTask(FROM_HERE, resume_callback);
138 } 150 }
139 151
140 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) { 152 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) {
141 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue()); 153 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue());
142 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value); 154 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value);
143 155
144 base::RunLoop run_loop; 156 base::RunLoop run_loop;
145 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure()); 157 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure());
146 run_loop.Run(); 158 run_loop.Run();
147 } 159 }
148 160
149 void It2MeHostTest::RunValidationCallback(const std::string& remote_jid) { 161 void It2MeHostTest::RunValidationCallback(const std::string& remote_jid) {
150 base::RunLoop run_loop; 162 base::RunLoop run_loop;
151 163
152 it2me_host_->GetValidationCallbackForTesting().Run( 164 network_task_runner_->PostTask(
153 remote_jid, base::Bind(&It2MeHostTest::OnValidationComplete, 165 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(),
154 base::Unretained(this), run_loop.QuitClosure())); 166 It2MeHostState::kStarting, std::string()));
167
168 network_task_runner_->PostTask(
169 FROM_HERE,
170 base::Bind(it2me_host_->GetValidationCallbackForTesting(), remote_jid,
171 base::Bind(&It2MeHostTest::OnValidationComplete,
172 base::Unretained(this), run_loop.QuitClosure())));
155 173
156 run_loop.Run(); 174 run_loop.Run();
175
176 it2me_host_->Disconnect();
157 } 177 }
158 178
159 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ValidJid) { 179 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ValidJid) {
160 RunValidationCallback(kTestClientJid); 180 RunValidationCallback(kTestClientJid);
161 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 181 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
162 } 182 }
163 183
164 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_InvalidJid) { 184 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_InvalidJid) {
165 RunValidationCallback(kTestClientUsernameNoJid); 185 RunValidationCallback(kTestClientUsernameNoJid);
166 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 186 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 229
210 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { 230 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) {
211 SetClientDomainPolicy(kMismatchedDomain1); 231 SetClientDomainPolicy(kMismatchedDomain1);
212 RunValidationCallback(kTestClientJid); 232 RunValidationCallback(kTestClientJid);
213 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 233 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
214 } 234 }
215 235
216 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { 236 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) {
217 RunValidationCallback(kTestClientJid); 237 RunValidationCallback(kTestClientJid);
218 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 238 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
219 ASSERT_STREQ(kTestClientUserName, dialog_->get_remote_user_email().c_str()); 239 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
220 } 240 }
221 241
222 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { 242 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) {
223 dialog_->set_dialog_result(DialogResult::CANCEL); 243 dialog_->set_dialog_result(DialogResult::CANCEL);
224 RunValidationCallback(kTestClientJid); 244 RunValidationCallback(kTestClientJid);
225 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); 245 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_);
226 ASSERT_STREQ(kTestClientUserName, dialog_->get_remote_user_email().c_str()); 246 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
227 } 247 }
228 248
229 } // namespace remoting 249 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698