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

Side by Side Diff: components/cryptauth/wire_message_unittest.cc

Issue 2849493002: [EasyUnlock] Fixing the setup connection finder and message format. (Closed)
Patch Set: date Created 3 years, 7 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
« no previous file with comments | « components/cryptauth/wire_message.cc ('k') | components/proximity_auth/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/cryptauth/wire_message.h" 5 #include "components/cryptauth/wire_message.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 bool is_incomplete; 81 bool is_incomplete;
82 std::string header("\3\0\x15", 3); 82 std::string header("\3\0\x15", 3);
83 std::string bytes = 83 std::string bytes =
84 header + "[{\"payload\": \"YQ==\"}]"; 84 header + "[{\"payload\": \"YQ==\"}]";
85 std::unique_ptr<WireMessage> message = 85 std::unique_ptr<WireMessage> message =
86 WireMessage::Deserialize(bytes, &is_incomplete); 86 WireMessage::Deserialize(bytes, &is_incomplete);
87 EXPECT_FALSE(is_incomplete); 87 EXPECT_FALSE(is_incomplete);
88 EXPECT_FALSE(message); 88 EXPECT_FALSE(message);
89 } 89 }
90 90
91 TEST(CryptAuthWireMessageTest, Deserialize_BodyLacksPayload) { 91 TEST(CryptAuthWireMessageTest, Deserialize_NonEncryptedMessage) {
92 bool is_incomplete; 92 bool is_incomplete;
93 std::string header("\3\0\x02", 3); 93 std::string header("\3\0\x02", 3);
94 std::string bytes = header + "{}"; 94 std::string bytes = header + "{}";
95 std::unique_ptr<WireMessage> message = 95 std::unique_ptr<WireMessage> message =
96 WireMessage::Deserialize(bytes, &is_incomplete); 96 WireMessage::Deserialize(bytes, &is_incomplete);
97 EXPECT_FALSE(is_incomplete); 97 EXPECT_FALSE(is_incomplete);
98 EXPECT_FALSE(message); 98 ASSERT_TRUE(message);
99 EXPECT_EQ("{}", message->body());
99 } 100 }
100 101
101 TEST(CryptAuthWireMessageTest, Deserialize_BodyHasEmptyPayload) { 102 TEST(CryptAuthWireMessageTest, Deserialize_BodyHasEmptyPayload) {
102 bool is_incomplete; 103 bool is_incomplete;
103 std::string header("\3\0\x29", 3); 104 std::string header("\3\0\x29", 3);
104 std::string bytes = header 105 std::string bytes = header
105 + "{\"payload\": \"\", \"feature\": \"testFeature\"}"; 106 + "{\"payload\": \"\", \"feature\": \"testFeature\"}";
106 std::unique_ptr<WireMessage> message = 107 std::unique_ptr<WireMessage> message =
107 WireMessage::Deserialize(bytes, &is_incomplete); 108 WireMessage::Deserialize(bytes, &is_incomplete);
108 EXPECT_FALSE(is_incomplete); 109 EXPECT_FALSE(is_incomplete);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_EQ("easy_unlock", message->feature()); 206 EXPECT_EQ("easy_unlock", message->feature());
206 } 207 }
207 208
208 TEST(CryptAuthWireMessageTest, Serialize_FailsWithoutPayload) { 209 TEST(CryptAuthWireMessageTest, Serialize_FailsWithoutPayload) {
209 WireMessage message1(std::string(), "example id"); 210 WireMessage message1(std::string(), "example id");
210 std::string bytes = message1.Serialize(); 211 std::string bytes = message1.Serialize();
211 EXPECT_TRUE(bytes.empty()); 212 EXPECT_TRUE(bytes.empty());
212 } 213 }
213 214
214 } // namespace cryptauth 215 } // namespace cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/wire_message.cc ('k') | components/proximity_auth/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698