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/test_key_pair.h" | |
awong
2010/08/02 19:53:49
ordering
Sergey Ulanov
2010/08/03 02:10:39
Done.
| |
15 #include "remoting/host/json_host_config.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 class TestConfigUpdater : | |
37 public base::RefCountedThreadSafe<TestConfigUpdater> { | |
38 public: | |
39 void DoUpdate(scoped_refptr<JsonHostConfig> target) { | |
40 target->SetString(kHostIdConfigPath, "0"); | |
41 } | |
42 }; | |
43 | |
44 virtual void SetUp() { | |
45 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | |
46 FilePath config_path = test_dir_.path().AppendASCII("test_config.json"); | |
47 config_ = new JsonHostConfig( | |
48 config_path, base::MessageLoopProxy::CreateForCurrentThread()); | |
49 scoped_refptr<TestConfigUpdater> config_updater(new TestConfigUpdater()); | |
50 config_->Update( | |
51 NewRunnableMethod(config_updater.get(), &TestConfigUpdater::DoUpdate, | |
52 config_)); | |
53 } | |
54 | |
55 MessageLoop message_loop_; | |
56 ScopedTempDir test_dir_; | |
57 scoped_refptr<JsonHostConfig> config_; | |
58 }; | |
59 | |
60 TEST_F(HostKeyPairTest, SaveLoad) { | |
61 // Save a key to a config, then load it back, and verify that we | |
62 // generate the same signature with both keys. | |
63 scoped_refptr<HostKeyPair> exported_key = new HostKeyPair(); | |
64 exported_key->LoadFromString(kTestHostKeyPair); | |
65 exported_key->Save(config_); | |
66 | |
67 scoped_refptr<HostKeyPair> imported_key = new HostKeyPair(); | |
68 imported_key->Load(config_); | |
69 | |
70 ASSERT_EQ(exported_key->GetSignature(kTestMessage), | |
71 imported_key->GetSignature(kTestMessage)); | |
72 } | |
73 | |
74 TEST_F(HostKeyPairTest, Signatures) { | |
75 // Sign a message and check that we get expected signature. | |
76 scoped_refptr<HostKeyPair> key_pair = new HostKeyPair(); | |
77 key_pair->LoadFromString(kTestHostKeyPair); | |
78 | |
79 std::string signature_base64 = key_pair->GetSignature(kTestMessage); | |
80 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); | |
81 } | |
82 | |
83 } // namespace remoting | |
OLD | NEW |