OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/local_strike_register_client.h" | 5 #include "net/quic/crypto/local_strike_register_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 TEST_F(LocalStrikeRegisterClientTest, IncorrectNonceLength) { | 77 TEST_F(LocalStrikeRegisterClientTest, IncorrectNonceLength) { |
78 string valid_nonce; | 78 string valid_nonce; |
79 uint32 norder = htonl(kCurrentTimeExternalSecs); | 79 uint32 norder = htonl(kCurrentTimeExternalSecs); |
80 valid_nonce.assign(reinterpret_cast<const char*>(&norder), sizeof(norder)); | 80 valid_nonce.assign(reinterpret_cast<const char*>(&norder), sizeof(norder)); |
81 valid_nonce.append(string(reinterpret_cast<const char*>(kOrbit), kOrbitSize)); | 81 valid_nonce.append(string(reinterpret_cast<const char*>(kOrbit), kOrbitSize)); |
82 valid_nonce.append(string(20, '\x17')); // 20 'random' bytes. | 82 valid_nonce.append(string(20, '\x17')); // 20 'random' bytes. |
83 | 83 |
84 { | 84 { |
85 // Validation fails if you remove a byte from the nonce. | 85 // Validation fails if you remove a byte from the nonce. |
86 bool called; | 86 bool called = false; |
87 bool is_valid; | 87 bool is_valid = false; |
88 string short_nonce = valid_nonce.substr(0, valid_nonce.length() - 1); | 88 string short_nonce = valid_nonce.substr(0, valid_nonce.length() - 1); |
89 strike_register_->VerifyNonceIsValidAndUnique( | 89 strike_register_->VerifyNonceIsValidAndUnique( |
90 short_nonce, | 90 short_nonce, |
91 QuicWallTime::FromUNIXSeconds(kCurrentTimeExternalSecs), | 91 QuicWallTime::FromUNIXSeconds(kCurrentTimeExternalSecs), |
92 new RecordResultCallback(&called, &is_valid)); | 92 new RecordResultCallback(&called, &is_valid)); |
93 EXPECT_TRUE(called); | 93 EXPECT_TRUE(called); |
94 EXPECT_FALSE(is_valid); | 94 EXPECT_FALSE(is_valid); |
95 } | 95 } |
96 | 96 |
97 { | 97 { |
98 // Validation fails if you add a byte to the nonce. | 98 // Validation fails if you add a byte to the nonce. |
99 bool called; | 99 bool called = false; |
100 bool is_valid; | 100 bool is_valid = false; |
101 string long_nonce(valid_nonce); | 101 string long_nonce(valid_nonce); |
102 long_nonce.append("a"); | 102 long_nonce.append("a"); |
103 strike_register_->VerifyNonceIsValidAndUnique( | 103 strike_register_->VerifyNonceIsValidAndUnique( |
104 long_nonce, | 104 long_nonce, |
105 QuicWallTime::FromUNIXSeconds(kCurrentTimeExternalSecs), | 105 QuicWallTime::FromUNIXSeconds(kCurrentTimeExternalSecs), |
106 new RecordResultCallback(&called, &is_valid)); | 106 new RecordResultCallback(&called, &is_valid)); |
107 EXPECT_TRUE(called); | 107 EXPECT_TRUE(called); |
108 EXPECT_FALSE(is_valid); | 108 EXPECT_FALSE(is_valid); |
109 } | 109 } |
110 | 110 |
111 { | 111 { |
112 // Verify that the base nonce validates was valid. | 112 // Verify that the base nonce validates was valid. |
113 bool called; | 113 bool called = false; |
114 bool is_valid; | 114 bool is_valid = false; |
115 strike_register_->VerifyNonceIsValidAndUnique( | 115 strike_register_->VerifyNonceIsValidAndUnique( |
116 valid_nonce, | 116 valid_nonce, |
117 QuicWallTime::FromUNIXSeconds(kCurrentTimeExternalSecs), | 117 QuicWallTime::FromUNIXSeconds(kCurrentTimeExternalSecs), |
118 new RecordResultCallback(&called, &is_valid)); | 118 new RecordResultCallback(&called, &is_valid)); |
119 EXPECT_TRUE(called); | 119 EXPECT_TRUE(called); |
120 EXPECT_TRUE(is_valid); | 120 EXPECT_TRUE(is_valid); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 } // namespace | 124 } // namespace |
125 } // namespace test | 125 } // namespace test |
126 } // namespace net | 126 } // namespace net |
OLD | NEW |