OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string> | |
6 | |
7 #include "remoting/base/rsa_key_pair.h" | |
8 #include "remoting/base/test_rsa_key_pair.h" | |
9 #include "testing/gmock/include/gmock/gmock.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace remoting { | |
13 | |
14 namespace { | |
15 const char kTestMessage[] = "Test Message"; | |
16 | |
17 // |kTestMessage| signed with the key from |kTestHostKeyPair|. | |
18 const char kExpectedSignature[] = | |
19 "LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2" | |
20 "LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf" | |
21 "gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ" | |
22 "Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC" | |
23 "BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA=="; | |
24 } // namespace | |
25 | |
26 class RsaKeyPairTest : public testing::Test { | |
Wez
2013/03/06 00:43:25
Why do we need a base class for these tests, since
rmsousa
2013/03/06 04:36:49
Organization - All unit tests for class X should b
| |
27 }; | |
28 | |
29 TEST_F(RsaKeyPairTest, LoadSaveLoad) { | |
Wez
2013/03/06 00:43:25
nit: LoadSaveLoad -> ImportExportImport, since loa
rmsousa
2013/03/06 04:36:49
Done.
| |
30 // Load a key to a string, convert to string, load again, and verify that we | |
31 // generate the same signature with both keys. | |
Wez
2013/03/06 00:43:25
nit: This comment seems to be out of date; we don'
rmsousa
2013/03/06 04:36:49
Done.
| |
32 scoped_refptr<RsaKeyPair> exported_key = new RsaKeyPair(); | |
33 exported_key->LoadFromString(kTestHostKeyPair); | |
34 scoped_refptr<RsaKeyPair> imported_key = new RsaKeyPair(); | |
35 imported_key->LoadFromString(exported_key->GetAsString()); | |
36 | |
37 ASSERT_EQ(exported_key->GetSignature(kTestMessage), | |
38 imported_key->GetSignature(kTestMessage)); | |
39 } | |
40 | |
41 TEST_F(RsaKeyPairTest, Signatures) { | |
42 // Sign a message and check that we get expected signature. | |
Wez
2013/03/06 00:43:25
nit: ... get the expected ...
rmsousa
2013/03/06 04:36:49
Done.
| |
43 scoped_refptr<RsaKeyPair> key_pair = new RsaKeyPair(); | |
44 key_pair->LoadFromString(kTestHostKeyPair); | |
45 | |
46 std::string signature_base64 = key_pair->GetSignature(kTestMessage); | |
47 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); | |
48 } | |
49 | |
50 TEST_F(RsaKeyPairTest, SignaturesDiffer) { | |
51 // Sign using different keys/messages and check that signatures are different. | |
52 scoped_refptr<RsaKeyPair> key_pair1 = new RsaKeyPair(); | |
53 key_pair1->Generate(); | |
54 scoped_refptr<RsaKeyPair> key_pair2 = new RsaKeyPair(); | |
55 key_pair2->Generate(); | |
Wez
2013/03/06 00:43:25
nit: Generating key pairs has an infinitesimally s
rmsousa
2013/03/06 04:36:49
Done.
| |
56 | |
57 std::string signature_kp1_msg1_base64 = key_pair1->GetSignature(kTestMessage); | |
58 std::string signature_kp2_msg1_base64 = key_pair2->GetSignature(kTestMessage); | |
59 std::string signature_kp1_msg2_base64 = key_pair1->GetSignature("Different"); | |
60 ASSERT_NE(signature_kp1_msg1_base64, signature_kp2_msg1_base64); | |
61 ASSERT_NE(signature_kp1_msg1_base64, signature_kp1_msg2_base64); | |
Wez
2013/03/06 00:43:25
nit: May as well also compare 2_1 to 1_2 while you
rmsousa
2013/03/06 04:36:49
There's no guarantee we need to assert about signi
| |
62 ASSERT_NE(key_pair1->GetPublicKey(), key_pair2->GetPublicKey()); | |
Wez
2013/03/06 00:43:25
This check is a requirement for the test to be val
rmsousa
2013/03/06 04:36:49
The *private keys* being different is the precondi
| |
63 } | |
64 | |
65 } // namespace remoting | |
OLD | NEW |