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

Side by Side Diff: net/quic/crypto/crypto_handshake_test.cc

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_handshake.cc ('k') | net/quic/crypto/crypto_protocol.h » ('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 (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/crypto/crypto_handshake.h" 5 #include "net/quic/crypto/crypto_handshake.h"
6 6
7 #include "net/quic/crypto/aes_128_gcm_encrypter.h" 7 #include "net/quic/crypto/aes_128_gcm_encrypter.h"
8 #include "net/quic/crypto/crypto_server_config.h" 8 #include "net/quic/crypto/crypto_server_config.h"
9 #include "net/quic/crypto/quic_random.h" 9 #include "net/quic/crypto/quic_random.h"
10 #include "net/quic/quic_time.h" 10 #include "net/quic/quic_time.h"
11 #include "net/quic/test_tools/mock_clock.h" 11 #include "net/quic/test_tools/mock_clock.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using base::StringPiece; 15 using base::StringPiece;
16 using std::string; 16 using std::string;
17 17
18 namespace net { 18 namespace net {
19 namespace test { 19 namespace test {
20 20
21 class QuicCryptoServerConfigPeer { 21 class QuicCryptoServerConfigPeer {
22 public: 22 public:
23 explicit QuicCryptoServerConfigPeer(QuicCryptoServerConfig* server_config) 23 explicit QuicCryptoServerConfigPeer(QuicCryptoServerConfig* server_config)
24 : server_config_(server_config) { 24 : server_config_(server_config) {}
25 }
26 25
27 string NewSourceAddressToken(IPEndPoint ip, 26 string NewSourceAddressToken(IPEndPoint ip,
28 QuicRandom* rand, 27 QuicRandom* rand,
29 QuicTime::Delta now) { 28 QuicWallTime now) {
30 return server_config_->NewSourceAddressToken(ip, rand, now); 29 return server_config_->NewSourceAddressToken(ip, rand, now);
31 } 30 }
32 31
33 bool ValidateSourceAddressToken(StringPiece srct, 32 bool ValidateSourceAddressToken(StringPiece srct,
34 IPEndPoint ip, 33 IPEndPoint ip,
35 QuicTime::Delta now) { 34 QuicWallTime now) {
36 return server_config_->ValidateSourceAddressToken(srct, ip, now); 35 return server_config_->ValidateSourceAddressToken(srct, ip, now);
37 } 36 }
38 37
39 private: 38 private:
40 QuicCryptoServerConfig* const server_config_; 39 QuicCryptoServerConfig* const server_config_;
41 }; 40 };
42 41
43 TEST(QuicCryptoServerConfigTest, ServerConfig) { 42 TEST(QuicCryptoServerConfigTest, ServerConfig) {
44 QuicCryptoServerConfig server("source address token secret"); 43 QuicCryptoServerConfig server("source address token secret");
45 MockClock clock; 44 MockClock clock;
46 CryptoHandshakeMessage extra_tags; 45 CryptoHandshakeMessage extra_tags;
47 46
48 scoped_ptr<CryptoHandshakeMessage>( 47 scoped_ptr<CryptoHandshakeMessage>(
49 server.AddDefaultConfig(QuicRandom::GetInstance(), &clock, extra_tags)); 48 server.AddDefaultConfig(QuicRandom::GetInstance(), &clock, extra_tags,
49 QuicCryptoServerConfig::kDefaultExpiry));
50 } 50 }
51 51
52 TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { 52 TEST(QuicCryptoServerConfigTest, SourceAddressTokens) {
53 if (!Aes128GcmEncrypter::IsSupported()) { 53 if (!Aes128GcmEncrypter::IsSupported()) {
54 LOG(INFO) << "AES GCM not supported. Test skipped."; 54 LOG(INFO) << "AES GCM not supported. Test skipped.";
55 return; 55 return;
56 } 56 }
57 57
58 QuicCryptoServerConfig server("source address token secret"); 58 QuicCryptoServerConfig server("source address token secret");
59 IPAddressNumber ip; 59 IPAddressNumber ip;
60 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); 60 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
61 IPEndPoint ip4 = IPEndPoint(ip, 1); 61 IPEndPoint ip4 = IPEndPoint(ip, 1);
62 CHECK(ParseIPLiteralToNumber("2001:db8:0::42", &ip)); 62 CHECK(ParseIPLiteralToNumber("2001:db8:0::42", &ip));
63 IPEndPoint ip6 = IPEndPoint(ip, 2); 63 IPEndPoint ip6 = IPEndPoint(ip, 2);
64 QuicRandom* rand = QuicRandom::GetInstance(); 64 QuicRandom* rand = QuicRandom::GetInstance();
65 MockClock clock; 65 MockClock clock;
66 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000));
66 QuicCryptoServerConfigPeer peer(&server); 67 QuicCryptoServerConfigPeer peer(&server);
67 68
68 QuicTime::Delta now = clock.NowAsDeltaSinceUnixEpoch(); 69 QuicWallTime now = clock.WallNow();
69 const QuicTime::Delta original_time = now; 70 const QuicWallTime original_time = now;
70 71
71 const string token4 = peer.NewSourceAddressToken(ip4, rand, now); 72 const string token4 = peer.NewSourceAddressToken(ip4, rand, now);
72 const string token6 = peer.NewSourceAddressToken(ip6, rand, now); 73 const string token6 = peer.NewSourceAddressToken(ip6, rand, now);
73 EXPECT_TRUE(peer.ValidateSourceAddressToken(token4, ip4, now)); 74 EXPECT_TRUE(peer.ValidateSourceAddressToken(token4, ip4, now));
74 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip6, now)); 75 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip6, now));
75 EXPECT_TRUE(peer.ValidateSourceAddressToken(token6, ip6, now)); 76 EXPECT_TRUE(peer.ValidateSourceAddressToken(token6, ip6, now));
76 77
77 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); 78 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7));
78 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now)); 79 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now));
79 80
80 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2)); 81 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2));
81 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now)); 82 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now));
82 } 83 }
83 84
84 } // namespace test 85 } // namespace test
85 } // namespace net 86 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_handshake.cc ('k') | net/quic/crypto/crypto_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698