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

Unified Diff: remoting/host/host_key_pair_unittest.cc

Issue 3087003: Added HostKeyPair class, signatures for heartbeat messages. (Closed)
Patch Set: Addressed review comments in the test Created 10 years, 5 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/host/host_key_pair_unittest.cc
diff --git a/remoting/host/host_key_pair_unittest.cc b/remoting/host/host_key_pair_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e5c1e47dbd4a196cd152033fdbb70c2489c31544
--- /dev/null
+++ b/remoting/host/host_key_pair_unittest.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2010 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 <string>
+
+#include "base/base64.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/ref_counted.h"
+#include "base/scoped_temp_dir.h"
+#include "base/string_util.h"
+#include "remoting/host/host_key_pair.h"
+#include "remoting/host/test_key_pair.h"
awong 2010/08/02 19:53:49 ordering
Sergey Ulanov 2010/08/03 02:10:39 Done.
+#include "remoting/host/json_host_config.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+namespace {
+const char kTestMessage[] = "Test Message";
+
+// |kTestMessage| signed with the key from |kTestHostKeyPair|.
+const char kExpectedSignature[] =
+"LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2"
+"LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf"
+"gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ"
+"Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC"
+"BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA==";
+}
+
+
+class HostKeyPairTest : public testing::Test {
+ protected:
+ class TestConfigUpdater :
+ public base::RefCountedThreadSafe<TestConfigUpdater> {
+ public:
+ void DoUpdate(scoped_refptr<JsonHostConfig> target) {
+ target->SetString(kHostIdConfigPath, "0");
+ }
+ };
+
+ virtual void SetUp() {
+ ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
+ FilePath config_path = test_dir_.path().AppendASCII("test_config.json");
+ config_ = new JsonHostConfig(
+ config_path, base::MessageLoopProxy::CreateForCurrentThread());
+ scoped_refptr<TestConfigUpdater> config_updater(new TestConfigUpdater());
+ config_->Update(
+ NewRunnableMethod(config_updater.get(), &TestConfigUpdater::DoUpdate,
+ config_));
+ }
+
+ MessageLoop message_loop_;
+ ScopedTempDir test_dir_;
+ scoped_refptr<JsonHostConfig> config_;
+};
+
+TEST_F(HostKeyPairTest, SaveLoad) {
+ // Save a key to a config, then load it back, and verify that we
+ // generate the same signature with both keys.
+ scoped_refptr<HostKeyPair> exported_key = new HostKeyPair();
+ exported_key->LoadFromString(kTestHostKeyPair);
+ exported_key->Save(config_);
+
+ scoped_refptr<HostKeyPair> imported_key = new HostKeyPair();
+ imported_key->Load(config_);
+
+ ASSERT_EQ(exported_key->GetSignature(kTestMessage),
+ imported_key->GetSignature(kTestMessage));
+}
+
+TEST_F(HostKeyPairTest, Signatures) {
+ // Sign a message and check that we get expected signature.
+ scoped_refptr<HostKeyPair> key_pair = new HostKeyPair();
+ key_pair->LoadFromString(kTestHostKeyPair);
+
+ std::string signature_base64 = key_pair->GetSignature(kTestMessage);
+ ASSERT_EQ(signature_base64, std::string(kExpectedSignature));
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698