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

Side by Side Diff: components/proximity_auth/device_to_device_secure_context_unittest.cc

Issue 1912433002: Convert //components/proximity_auth from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/proximity_auth/device_to_device_secure_context.h" 5 #include "components/proximity_auth/device_to_device_secure_context.h"
6 6
7 #include <memory>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/ptr_util.h"
9 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" 11 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h"
10 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" 12 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
11 #include "components/proximity_auth/cryptauth/proto/securemessage.pb.h" 13 #include "components/proximity_auth/cryptauth/proto/securemessage.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 namespace proximity_auth { 16 namespace proximity_auth {
15 17
16 namespace { 18 namespace {
17 19
18 const char kSymmetricKey[] = "symmetric key"; 20 const char kSymmetricKey[] = "symmetric key";
19 const char kResponderAuthMessage[] = "responder_auth_message"; 21 const char kResponderAuthMessage[] = "responder_auth_message";
20 const SecureContext::ProtocolVersion kProtocolVersion = 22 const SecureContext::ProtocolVersion kProtocolVersion =
21 SecureContext::PROTOCOL_VERSION_THREE_ONE; 23 SecureContext::PROTOCOL_VERSION_THREE_ONE;
22 24
23 // Callback saving |result| to |result_out|. 25 // Callback saving |result| to |result_out|.
24 void SaveResult(std::string* result_out, const std::string& result) { 26 void SaveResult(std::string* result_out, const std::string& result) {
25 *result_out = result; 27 *result_out = result;
26 } 28 }
27 29
28 } // namespace 30 } // namespace
29 31
30 class ProximityAuthDeviceToDeviceSecureContextTest : public testing::Test { 32 class ProximityAuthDeviceToDeviceSecureContextTest : public testing::Test {
31 protected: 33 protected:
32 ProximityAuthDeviceToDeviceSecureContextTest() 34 ProximityAuthDeviceToDeviceSecureContextTest()
33 : secure_context_(make_scoped_ptr(new FakeSecureMessageDelegate()), 35 : secure_context_(base::WrapUnique(new FakeSecureMessageDelegate()),
34 kSymmetricKey, 36 kSymmetricKey,
35 kResponderAuthMessage, 37 kResponderAuthMessage,
36 kProtocolVersion) {} 38 kProtocolVersion) {}
37 39
38 DeviceToDeviceSecureContext secure_context_; 40 DeviceToDeviceSecureContext secure_context_;
39 }; 41 };
40 42
41 TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, GetProperties) { 43 TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, GetProperties) {
42 EXPECT_EQ(kResponderAuthMessage, secure_context_.GetChannelBindingData()); 44 EXPECT_EQ(kResponderAuthMessage, secure_context_.GetChannelBindingData());
43 EXPECT_EQ(kProtocolVersion, secure_context_.GetProtocolVersion()); 45 EXPECT_EQ(kProtocolVersion, secure_context_.GetProtocolVersion());
(...skipping 21 matching lines...) Expand all
65 std::string encoded_message = "invalidly encoded message"; 67 std::string encoded_message = "invalidly encoded message";
66 std::string decoded_message = "not empty"; 68 std::string decoded_message = "not empty";
67 secure_context_.Decode(encoded_message, 69 secure_context_.Decode(encoded_message,
68 base::Bind(&SaveResult, &decoded_message)); 70 base::Bind(&SaveResult, &decoded_message));
69 EXPECT_TRUE(decoded_message.empty()); 71 EXPECT_TRUE(decoded_message.empty());
70 } 72 }
71 73
72 TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, EncodeAndDecode) { 74 TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, EncodeAndDecode) {
73 // Initialize second secure channel with the same parameters as the first. 75 // Initialize second secure channel with the same parameters as the first.
74 DeviceToDeviceSecureContext secure_context2( 76 DeviceToDeviceSecureContext secure_context2(
75 make_scoped_ptr(new FakeSecureMessageDelegate()), kSymmetricKey, 77 base::WrapUnique(new FakeSecureMessageDelegate()), kSymmetricKey,
76 kResponderAuthMessage, kProtocolVersion); 78 kResponderAuthMessage, kProtocolVersion);
77 std::string message = "encrypt this message"; 79 std::string message = "encrypt this message";
78 80
79 // Pass some messages between the two secure contexts. 81 // Pass some messages between the two secure contexts.
80 for (int i = 0; i < 3; ++i) { 82 for (int i = 0; i < 3; ++i) {
81 std::string encoded_message; 83 std::string encoded_message;
82 secure_context_.Encode(message, base::Bind(&SaveResult, &encoded_message)); 84 secure_context_.Encode(message, base::Bind(&SaveResult, &encoded_message));
83 EXPECT_NE(message, encoded_message); 85 EXPECT_NE(message, encoded_message);
84 86
85 std::string decoded_message; 87 std::string decoded_message;
86 secure_context2.Decode(encoded_message, 88 secure_context2.Decode(encoded_message,
87 base::Bind(&SaveResult, &decoded_message)); 89 base::Bind(&SaveResult, &decoded_message));
88 EXPECT_EQ(message, decoded_message); 90 EXPECT_EQ(message, decoded_message);
89 } 91 }
90 } 92 }
91 93
92 TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, 94 TEST_F(ProximityAuthDeviceToDeviceSecureContextTest,
93 DecodeInvalidSequenceNumber) { 95 DecodeInvalidSequenceNumber) {
94 // Initialize second secure channel with the same parameters as the first. 96 // Initialize second secure channel with the same parameters as the first.
95 DeviceToDeviceSecureContext secure_context2( 97 DeviceToDeviceSecureContext secure_context2(
96 make_scoped_ptr(new FakeSecureMessageDelegate()), kSymmetricKey, 98 base::WrapUnique(new FakeSecureMessageDelegate()), kSymmetricKey,
97 kResponderAuthMessage, kProtocolVersion); 99 kResponderAuthMessage, kProtocolVersion);
98 100
99 // Send a few messages over the first secure context. 101 // Send a few messages over the first secure context.
100 std::string message = "encrypt this message"; 102 std::string message = "encrypt this message";
101 std::string encoded1; 103 std::string encoded1;
102 for (int i = 0; i < 3; ++i) { 104 for (int i = 0; i < 3; ++i) {
103 secure_context_.Encode(message, base::Bind(&SaveResult, &encoded1)); 105 secure_context_.Encode(message, base::Bind(&SaveResult, &encoded1));
104 } 106 }
105 107
106 // Second secure channel should not decode the message with an invalid 108 // Second secure channel should not decode the message with an invalid
107 // sequence number. 109 // sequence number.
108 std::string decoded_message = "not empty"; 110 std::string decoded_message = "not empty";
109 secure_context_.Decode(encoded1, base::Bind(&SaveResult, &decoded_message)); 111 secure_context_.Decode(encoded1, base::Bind(&SaveResult, &decoded_message));
110 EXPECT_TRUE(decoded_message.empty()); 112 EXPECT_TRUE(decoded_message.empty());
111 } 113 }
112 114
113 } // proximity_auth 115 } // proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/device_to_device_secure_context.cc ('k') | components/proximity_auth/fake_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698