OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_crypto_client_stream.h" | 5 #include "net/quic/quic_crypto_client_stream.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
9 #include "net/quic/crypto/quic_decrypter.h" | 9 #include "net/quic/crypto/quic_decrypter.h" |
10 #include "net/quic/crypto/quic_encrypter.h" | 10 #include "net/quic/crypto/quic_encrypter.h" |
11 #include "net/quic/quic_flags.h" | 11 #include "net/quic/quic_flags.h" |
12 #include "net/quic/quic_protocol.h" | 12 #include "net/quic/quic_protocol.h" |
13 #include "net/quic/quic_server_id.h" | 13 #include "net/quic/quic_server_id.h" |
14 #include "net/quic/quic_utils.h" | 14 #include "net/quic/quic_utils.h" |
15 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
17 #include "net/quic/test_tools/simple_quic_framer.h" | 17 #include "net/quic/test_tools/simple_quic_framer.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 using std::string; | 21 using std::string; |
22 using std::vector; | 22 using std::vector; |
23 | 23 |
| 24 using testing::_; |
| 25 |
24 namespace net { | 26 namespace net { |
25 namespace test { | 27 namespace test { |
26 namespace { | 28 namespace { |
27 | 29 |
28 const char kServerHostname[] = "test.example.com"; | 30 const char kServerHostname[] = "test.example.com"; |
29 const uint16 kServerPort = 443; | 31 const uint16 kServerPort = 443; |
30 | 32 |
31 class QuicCryptoClientStreamTest : public ::testing::Test { | 33 class QuicCryptoClientStreamTest : public ::testing::Test { |
32 public: | 34 public: |
33 QuicCryptoClientStreamTest() | 35 QuicCryptoClientStreamTest() |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 77 |
76 TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) { | 78 TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) { |
77 CompleteCryptoHandshake(); | 79 CompleteCryptoHandshake(); |
78 EXPECT_TRUE(stream()->encryption_established()); | 80 EXPECT_TRUE(stream()->encryption_established()); |
79 EXPECT_TRUE(stream()->handshake_confirmed()); | 81 EXPECT_TRUE(stream()->handshake_confirmed()); |
80 } | 82 } |
81 | 83 |
82 TEST_F(QuicCryptoClientStreamTest, MessageAfterHandshake) { | 84 TEST_F(QuicCryptoClientStreamTest, MessageAfterHandshake) { |
83 CompleteCryptoHandshake(); | 85 CompleteCryptoHandshake(); |
84 | 86 |
85 EXPECT_CALL(*connection_, SendConnectionClose( | 87 EXPECT_CALL(*connection_, |
86 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE)); | 88 SendConnectionCloseWithDetails( |
| 89 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE, _)); |
87 message_.set_tag(kCHLO); | 90 message_.set_tag(kCHLO); |
88 ConstructHandshakeMessage(); | 91 ConstructHandshakeMessage(); |
89 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, | 92 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, |
90 /*offset=*/0, | 93 /*offset=*/0, |
91 message_data_->AsStringPiece())); | 94 message_data_->AsStringPiece())); |
92 } | 95 } |
93 | 96 |
94 TEST_F(QuicCryptoClientStreamTest, BadMessageType) { | 97 TEST_F(QuicCryptoClientStreamTest, BadMessageType) { |
95 stream()->CryptoConnect(); | 98 stream()->CryptoConnect(); |
96 | 99 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // Make sure that the STK and SCFG are cached correctly. | 204 // Make sure that the STK and SCFG are cached correctly. |
202 EXPECT_EQ("xstk", state->source_address_token()); | 205 EXPECT_EQ("xstk", state->source_address_token()); |
203 | 206 |
204 string cached_scfg = state->server_config(); | 207 string cached_scfg = state->server_config(); |
205 test::CompareCharArraysWithHexError( | 208 test::CompareCharArraysWithHexError( |
206 "scfg", cached_scfg.data(), cached_scfg.length(), | 209 "scfg", cached_scfg.data(), cached_scfg.length(), |
207 QuicUtils::AsChars(scfg), arraysize(scfg)); | 210 QuicUtils::AsChars(scfg), arraysize(scfg)); |
208 } | 211 } |
209 | 212 |
210 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateBeforeHandshake) { | 213 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateBeforeHandshake) { |
211 EXPECT_CALL(*connection_, SendConnectionClose( | 214 EXPECT_CALL(*connection_, |
212 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE)); | 215 SendConnectionCloseWithDetails( |
| 216 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE, _)); |
213 CryptoHandshakeMessage server_config_update; | 217 CryptoHandshakeMessage server_config_update; |
214 server_config_update.set_tag(kSCUP); | 218 server_config_update.set_tag(kSCUP); |
215 scoped_ptr<QuicData> data( | 219 scoped_ptr<QuicData> data( |
216 CryptoFramer::ConstructHandshakeMessage(server_config_update)); | 220 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
217 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, | 221 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, |
218 /*offset=*/0, data->AsStringPiece())); | 222 /*offset=*/0, data->AsStringPiece())); |
219 } | 223 } |
220 | 224 |
221 TEST_F(QuicCryptoClientStreamTest, TokenBindingNegotiation) { | 225 TEST_F(QuicCryptoClientStreamTest, TokenBindingNegotiation) { |
222 server_options_.token_binding_enabled = true; | 226 server_options_.token_binding_enabled = true; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 client_state->GetNextServerDesignatedConnectionId(); | 346 client_state->GetNextServerDesignatedConnectionId(); |
343 QuicConnectionId expected_id = | 347 QuicConnectionId expected_id = |
344 server_session_->connection()->random_generator()->RandUint64(); | 348 server_session_->connection()->random_generator()->RandUint64(); |
345 EXPECT_EQ(expected_id, server_designated_id); | 349 EXPECT_EQ(expected_id, server_designated_id); |
346 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 350 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
347 } | 351 } |
348 | 352 |
349 } // namespace | 353 } // namespace |
350 } // namespace test | 354 } // namespace test |
351 } // namespace net | 355 } // namespace net |
OLD | NEW |