| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "remoting/host/host_key_pair.h" | 12 #include "remoting/host/host_key_pair.h" |
| 13 #include "remoting/host/json_host_config.h" | 13 #include "remoting/host/json_host_config.h" |
| 14 #include "remoting/host/test_key_pair.h" | 14 #include "remoting/host/test_key_pair.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 const char kTestMessage[] = "Test Message"; | 21 const char kTestMessage[] = "Test Message"; |
| 22 | 22 |
| 23 // |kTestMessage| signed with the key from |kTestHostKeyPair|. | 23 // |kTestMessage| signed with the key from |kTestHostKeyPair|. |
| 24 const char kExpectedSignature[] = | 24 const char kExpectedSignature[] = |
| 25 "LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2" | 25 "LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2" |
| 26 "LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf" | 26 "LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf" |
| 27 "gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ" | 27 "gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ" |
| 28 "Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC" | 28 "Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC" |
| 29 "BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA=="; | 29 "BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA=="; |
| 30 } | 30 } // namespace |
| 31 | |
| 32 | 31 |
| 33 class HostKeyPairTest : public testing::Test { | 32 class HostKeyPairTest : public testing::Test { |
| 34 protected: | 33 protected: |
| 35 virtual void SetUp() { | 34 virtual void SetUp() { |
| 36 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 35 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 37 FilePath config_path = test_dir_.path().AppendASCII("test_config.json"); | 36 FilePath config_path = test_dir_.path().AppendASCII("test_config.json"); |
| 38 config_ = new JsonHostConfig( | 37 config_.reset(new JsonHostConfig(config_path)); |
| 39 config_path, base::MessageLoopProxy::current()); | |
| 40 } | 38 } |
| 41 | 39 |
| 42 MessageLoop message_loop_; | 40 MessageLoop message_loop_; |
| 43 ScopedTempDir test_dir_; | 41 ScopedTempDir test_dir_; |
| 44 scoped_refptr<JsonHostConfig> config_; | 42 scoped_ptr<JsonHostConfig> config_; |
| 45 }; | 43 }; |
| 46 | 44 |
| 47 TEST_F(HostKeyPairTest, SaveLoad) { | 45 TEST_F(HostKeyPairTest, SaveLoad) { |
| 48 // Save a key to a config, then load it back, and verify that we | 46 // Save a key to a config, then load it back, and verify that we |
| 49 // generate the same signature with both keys. | 47 // generate the same signature with both keys. |
| 50 HostKeyPair exported_key; | 48 HostKeyPair exported_key; |
| 51 exported_key.LoadFromString(kTestHostKeyPair); | 49 exported_key.LoadFromString(kTestHostKeyPair); |
| 52 exported_key.Save(config_); | 50 exported_key.Save(config_.get()); |
| 53 | 51 |
| 54 message_loop_.RunAllPending(); | 52 message_loop_.RunAllPending(); |
| 55 | 53 |
| 56 HostKeyPair imported_key; | 54 HostKeyPair imported_key; |
| 57 imported_key.Load(config_); | 55 imported_key.Load(*config_); |
| 58 | 56 |
| 59 ASSERT_EQ(exported_key.GetSignature(kTestMessage), | 57 ASSERT_EQ(exported_key.GetSignature(kTestMessage), |
| 60 imported_key.GetSignature(kTestMessage)); | 58 imported_key.GetSignature(kTestMessage)); |
| 61 } | 59 } |
| 62 | 60 |
| 63 TEST_F(HostKeyPairTest, Signatures) { | 61 TEST_F(HostKeyPairTest, Signatures) { |
| 64 // Sign a message and check that we get expected signature. | 62 // Sign a message and check that we get expected signature. |
| 65 HostKeyPair key_pair; | 63 HostKeyPair key_pair; |
| 66 key_pair.LoadFromString(kTestHostKeyPair); | 64 key_pair.LoadFromString(kTestHostKeyPair); |
| 67 | 65 |
| 68 std::string signature_base64 = key_pair.GetSignature(kTestMessage); | 66 std::string signature_base64 = key_pair.GetSignature(kTestMessage); |
| 69 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); | 67 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); |
| 70 } | 68 } |
| 71 | 69 |
| 72 } // namespace remoting | 70 } // namespace remoting |
| OLD | NEW |