diff options
author | jschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 02:20:46 +0000 |
---|---|---|
committer | jschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 02:20:46 +0000 |
commit | 5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650 (patch) | |
tree | 81e2f1a63b2109464dde8efa38b32381e2001829 /ipc/ipc_sync_channel_unittest.cc | |
parent | ab25e338556b9580c54b3f4025009eaaf6ac83d3 (diff) | |
download | chromium_src-5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650.zip chromium_src-5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650.tar.gz chromium_src-5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650.tar.bz2 |
Verify the child process with a secret hello
BUG=117627
TEST=IPCSyncChannelTest.Verified
Review URL: http://codereview.chromium.org/9692035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_sync_channel_unittest.cc')
-rw-r--r-- | ipc/ipc_sync_channel_unittest.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc index 2b74ff4..6cb7457 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -1594,4 +1594,93 @@ TEST_F(IPCSyncChannelTest, RestrictedDispatchDeadlock) { RunTest(workers); } +//----------------------------------------------------------------------------- + +// Generate a validated channel ID using Channel::GenerateVerifiedChannelID(). +namespace { + +class VerifiedServer : public Worker { + public: + VerifiedServer(base::Thread* listener_thread, + const std::string& channel_name, + const std::string& reply_text) + : Worker(channel_name, Channel::MODE_SERVER), + reply_text_(reply_text) { + Worker::OverrideThread(listener_thread); + } + + virtual void OnNestedTestMsg(Message* reply_msg) { + VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; + SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); + Send(reply_msg); + Done(); + } + + private: + std::string reply_text_; +}; + +class VerifiedClient : public Worker { + public: + VerifiedClient(base::Thread* listener_thread, + const std::string& channel_name, + const std::string& expected_text) + : Worker(channel_name, Channel::MODE_CLIENT), + expected_text_(expected_text) { + Worker::OverrideThread(listener_thread); + } + + virtual void Run() { + std::string response; + SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); + bool result = Send(msg); + DCHECK(result); + DCHECK_EQ(response, expected_text_); + + VLOG(1) << __FUNCTION__ << " Received reply: " << response; + Done(); + } + + private: + bool pump_during_send_; + std::string expected_text_; +}; + +void Verified() { + std::vector<Worker*> workers; + + // A shared worker thread for servers + base::Thread server_worker_thread("Verified_ServerListener"); + ASSERT_TRUE(server_worker_thread.Start()); + + base::Thread client_worker_thread("Verified_ClientListener"); + ASSERT_TRUE(client_worker_thread.Start()); + + std::string channel_id = Channel::GenerateVerifiedChannelID("Verified"); + Worker* worker; + + worker = new VerifiedServer(&server_worker_thread, + channel_id, + "Got first message"); + workers.push_back(worker); + + worker = new VerifiedClient(&client_worker_thread, + channel_id, + "Got first message"); + workers.push_back(worker); + + RunTest(workers); + +#if defined(OS_WIN) +#endif +} + +} // namespace + +// Windows needs to send an out-of-band secret to verify the client end of the +// channel. Test that we still connect correctly in that case. +TEST_F(IPCSyncChannelTest, Verified) { + Verified(); +} + } // namespace IPC |