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

Side by Side Diff: net/quic/core/crypto/crypto_secret_boxer_test.cc

Issue 2848203002: Add a platform implementation of QuicTest and QuicTestWithParam (Closed)
Patch Set: net/quic/platform/impl/quic_test_impl.cc 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "net/quic/core/crypto/crypto_secret_boxer.h" 5 #include "net/quic/core/crypto/crypto_secret_boxer.h"
6 6
7 #include "net/quic/core/crypto/quic_random.h" 7 #include "net/quic/core/crypto/quic_random.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "net/quic/platform/api/quic_test.h"
9 9
10 using std::string; 10 using std::string;
11 11
12 namespace net { 12 namespace net {
13 namespace test { 13 namespace test {
14 14
15 TEST(CryptoSecretBoxerTest, BoxAndUnbox) { 15 class CryptoSecretBoxerTest : public QuicTest {};
16
17 TEST_F(CryptoSecretBoxerTest, BoxAndUnbox) {
16 QuicStringPiece message("hello world"); 18 QuicStringPiece message("hello world");
17 19
18 CryptoSecretBoxer boxer; 20 CryptoSecretBoxer boxer;
19 boxer.SetKeys({string(CryptoSecretBoxer::GetKeySize(), 0x11)}); 21 boxer.SetKeys({string(CryptoSecretBoxer::GetKeySize(), 0x11)});
20 22
21 const string box = boxer.Box(QuicRandom::GetInstance(), message); 23 const string box = boxer.Box(QuicRandom::GetInstance(), message);
22 24
23 string storage; 25 string storage;
24 QuicStringPiece result; 26 QuicStringPiece result;
25 EXPECT_TRUE(boxer.Unbox(box, &storage, &result)); 27 EXPECT_TRUE(boxer.Unbox(box, &storage, &result));
(...skipping 14 matching lines...) Expand all
40 const string boxed = encoder.Box(QuicRandom::GetInstance(), message); 42 const string boxed = encoder.Box(QuicRandom::GetInstance(), message);
41 string storage; 43 string storage;
42 QuicStringPiece result; 44 QuicStringPiece result;
43 bool ok = decoder.Unbox(boxed, &storage, &result); 45 bool ok = decoder.Unbox(boxed, &storage, &result);
44 if (ok) { 46 if (ok) {
45 EXPECT_EQ(result, message); 47 EXPECT_EQ(result, message);
46 } 48 }
47 return ok; 49 return ok;
48 } 50 }
49 51
50 TEST(CryptoSecretBoxerTest, MultipleKeys) { 52 TEST_F(CryptoSecretBoxerTest, MultipleKeys) {
51 string key_11(CryptoSecretBoxer::GetKeySize(), 0x11); 53 string key_11(CryptoSecretBoxer::GetKeySize(), 0x11);
52 string key_12(CryptoSecretBoxer::GetKeySize(), 0x12); 54 string key_12(CryptoSecretBoxer::GetKeySize(), 0x12);
53 55
54 CryptoSecretBoxer boxer_11, boxer_12, boxer; 56 CryptoSecretBoxer boxer_11, boxer_12, boxer;
55 boxer_11.SetKeys({key_11}); 57 boxer_11.SetKeys({key_11});
56 boxer_12.SetKeys({key_12}); 58 boxer_12.SetKeys({key_12});
57 boxer.SetKeys({key_12, key_11}); 59 boxer.SetKeys({key_12, key_11});
58 60
59 // Neither single-key boxer can decode the other's tokens. 61 // Neither single-key boxer can decode the other's tokens.
60 EXPECT_FALSE(CanDecode(boxer_11, boxer_12)); 62 EXPECT_FALSE(CanDecode(boxer_11, boxer_12));
61 EXPECT_FALSE(CanDecode(boxer_12, boxer_11)); 63 EXPECT_FALSE(CanDecode(boxer_12, boxer_11));
62 64
63 // |boxer| encodes with the first key, which is key_12. 65 // |boxer| encodes with the first key, which is key_12.
64 EXPECT_TRUE(CanDecode(boxer_12, boxer)); 66 EXPECT_TRUE(CanDecode(boxer_12, boxer));
65 EXPECT_FALSE(CanDecode(boxer_11, boxer)); 67 EXPECT_FALSE(CanDecode(boxer_11, boxer));
66 68
67 // The boxer with both keys can decode tokens from either single-key boxer. 69 // The boxer with both keys can decode tokens from either single-key boxer.
68 EXPECT_TRUE(CanDecode(boxer, boxer_11)); 70 EXPECT_TRUE(CanDecode(boxer, boxer_11));
69 EXPECT_TRUE(CanDecode(boxer, boxer_12)); 71 EXPECT_TRUE(CanDecode(boxer, boxer_12));
70 72
71 // After we flush key_11 from |boxer|, it can no longer decode tokens from 73 // After we flush key_11 from |boxer|, it can no longer decode tokens from
72 // |boxer_11|. 74 // |boxer_11|.
73 boxer.SetKeys({key_12}); 75 boxer.SetKeys({key_12});
74 EXPECT_FALSE(CanDecode(boxer, boxer_11)); 76 EXPECT_FALSE(CanDecode(boxer, boxer_11));
75 } 77 }
76 78
77 } // namespace test 79 } // namespace test
78 } // namespace net 80 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/crypto_handshake_message_test.cc ('k') | net/quic/core/crypto/crypto_server_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698