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