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

Side by Side Diff: remoting/protocol/key_pair_unittest.cc

Issue 12316083: Move HostKeyPair into protocol::KeyPair. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add missing files, move TestKeyPair. Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/files/scoped_temp_dir.h" 7 #include "remoting/protocol/key_pair.h"
8 #include "base/memory/ref_counted.h" 8 #include "remoting/protocol/test_key_pair.h"
9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h"
11 #include "base/string_util.h"
12 #include "remoting/host/host_key_pair.h"
13 #include "remoting/host/json_host_config.h"
14 #include "remoting/host/test_key_pair.h"
15 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
17 11
18 namespace remoting { 12 namespace remoting {
13 namespace protocol {
19 14
20 namespace { 15 namespace {
21 const char kTestMessage[] = "Test Message"; 16 const char kTestMessage[] = "Test Message";
22 17
23 // |kTestMessage| signed with the key from |kTestHostKeyPair|. 18 // |kTestMessage| signed with the key from |kTestHostKeyPair|.
24 const char kExpectedSignature[] = 19 const char kExpectedSignature[] =
25 "LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2" 20 "LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2"
26 "LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf" 21 "LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf"
27 "gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ" 22 "gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ"
28 "Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC" 23 "Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC"
29 "BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA=="; 24 "BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA==";
30 } // namespace 25 } // namespace
31 26
32 class HostKeyPairTest : public testing::Test { 27 class KeyPairTest : public testing::Test {
33 protected:
34 virtual void SetUp() {
35 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
36 base::FilePath config_path = test_dir_.path().AppendASCII("test_config.json" );
37 config_.reset(new JsonHostConfig(config_path));
38 }
39
40 MessageLoop message_loop_;
41 base::ScopedTempDir test_dir_;
42 scoped_ptr<JsonHostConfig> config_;
43 }; 28 };
44 29
45 TEST_F(HostKeyPairTest, SaveLoad) { 30 TEST_F(KeyPairTest, SaveLoad) {
Wez 2013/02/23 03:43:20 nit: LoadSaveLoad ;)
rmsousa 2013/02/26 02:38:52 Done.
46 // Save a key to a config, then load it back, and verify that we 31 // Load a key to a string, convert to string, load again, and verify that we
47 // generate the same signature with both keys. 32 // generate the same signature with both keys.
48 HostKeyPair exported_key; 33 KeyPair exported_key;
49 exported_key.LoadFromString(kTestHostKeyPair); 34 exported_key.LoadFromString(kTestHostKeyPair);
50 exported_key.Save(config_.get()); 35 KeyPair imported_key;
51 36 imported_key.LoadFromString(exported_key.GetAsString());
52 message_loop_.RunUntilIdle();
53
54 HostKeyPair imported_key;
55 imported_key.Load(*config_);
56 37
57 ASSERT_EQ(exported_key.GetSignature(kTestMessage), 38 ASSERT_EQ(exported_key.GetSignature(kTestMessage),
58 imported_key.GetSignature(kTestMessage)); 39 imported_key.GetSignature(kTestMessage));
59 } 40 }
60 41
61 TEST_F(HostKeyPairTest, Signatures) { 42 TEST_F(KeyPairTest, Signatures) {
Wez 2013/02/23 03:43:20 nit: We should have tests that differing keys gene
Wez 2013/02/23 03:43:20 Please also add a test for Copy().
rmsousa 2013/02/26 02:38:52 Done.
rmsousa 2013/02/26 02:38:52 Done.
62 // Sign a message and check that we get expected signature. 43 // Sign a message and check that we get expected signature.
63 HostKeyPair key_pair; 44 KeyPair key_pair;
64 key_pair.LoadFromString(kTestHostKeyPair); 45 key_pair.LoadFromString(kTestHostKeyPair);
65 46
66 std::string signature_base64 = key_pair.GetSignature(kTestMessage); 47 std::string signature_base64 = key_pair.GetSignature(kTestMessage);
67 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); 48 ASSERT_EQ(signature_base64, std::string(kExpectedSignature));
68 } 49 }
69 50
51 } // namespace protocol
70 } // namespace remoting 52 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698