[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/quic/quic_client_session.h" |
| 6 | |
| 7 | #include <vector> |
| 8 | |
[email protected] | 0d10b59 | 2013-02-14 16:09:26 | [diff] [blame] | 9 | #include "net/base/capturing_net_log.h" |
[email protected] | 8ee611b | 2012-11-20 01:48:12 | [diff] [blame] | 10 | #include "net/base/test_completion_callback.h" |
[email protected] | 0bbeb697 | 2013-05-23 04:10:21 | [diff] [blame^] | 11 | #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 12 | #include "net/quic/crypto/crypto_protocol.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 13 | #include "net/quic/crypto/quic_decrypter.h" |
| 14 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 15 | #include "net/quic/test_tools/crypto_test_utils.h" |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 16 | #include "net/quic/test_tools/quic_client_session_peer.h" |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 17 | #include "net/quic/test_tools/quic_test_utils.h" |
| 18 | |
| 19 | using testing::_; |
| 20 | |
| 21 | namespace net { |
| 22 | namespace test { |
| 23 | namespace { |
| 24 | |
[email protected] | 41d6b17 | 2013-01-29 16:10:57 | [diff] [blame] | 25 | const char kServerHostname[] = "www.example.com"; |
| 26 | |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 27 | class QuicClientSessionTest : public ::testing::Test { |
| 28 | protected: |
| 29 | QuicClientSessionTest() |
| 30 | : guid_(1), |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 31 | connection_(new PacketSavingConnection(guid_, IPEndPoint(), false)), |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 32 | session_(connection_, NULL, NULL, NULL, kServerHostname, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 33 | QuicConfig(), &crypto_config_, &net_log_) { |
[email protected] | 47a7154 | 2013-05-17 07:58:54 | [diff] [blame] | 34 | session_.config()->SetDefaults(); |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 35 | crypto_config_.SetDefaults(); |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 36 | QuicClientSessionPeer::SetMaxOpenStreams(&session_, 1, 1); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 37 | } |
| 38 | |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 39 | void CompleteCryptoHandshake() { |
| 40 | ASSERT_EQ(ERR_IO_PENDING, |
| 41 | session_.CryptoConnect(callback_.callback())); |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 42 | CryptoTestUtils::HandshakeWithFakeServer( |
| 43 | connection_, session_.GetCryptoStream()); |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 44 | ASSERT_EQ(OK, callback_.WaitForResult()); |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 47 | QuicGuid guid_; |
| 48 | PacketSavingConnection* connection_; |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 49 | CapturingNetLog net_log_; |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 50 | QuicClientSession session_; |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 51 | MockClock clock_; |
| 52 | MockRandom random_; |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 53 | QuicConnectionVisitorInterface* visitor_; |
[email protected] | 8ee611b | 2012-11-20 01:48:12 | [diff] [blame] | 54 | TestCompletionCallback callback_; |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 55 | QuicCryptoClientConfig crypto_config_; |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 56 | }; |
| 57 | |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 58 | TEST_F(QuicClientSessionTest, CryptoConnect) { |
[email protected] | 0bbeb697 | 2013-05-23 04:10:21 | [diff] [blame^] | 59 | if (!Aes128Gcm12Encrypter::IsSupported()) { |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 60 | LOG(INFO) << "AES GCM not supported. Test skipped."; |
| 61 | return; |
| 62 | } |
| 63 | |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 64 | CompleteCryptoHandshake(); |
[email protected] | 8ee611b | 2012-11-20 01:48:12 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | TEST_F(QuicClientSessionTest, MaxNumConnections) { |
[email protected] | 0bbeb697 | 2013-05-23 04:10:21 | [diff] [blame^] | 68 | if (!Aes128Gcm12Encrypter::IsSupported()) { |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 69 | LOG(INFO) << "AES GCM not supported. Test skipped."; |
| 70 | return; |
| 71 | } |
| 72 | |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 73 | CompleteCryptoHandshake(); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 74 | |
| 75 | std::vector<QuicReliableClientStream*> streams; |
| 76 | for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { |
| 77 | QuicReliableClientStream* stream = session_.CreateOutgoingReliableStream(); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 78 | EXPECT_TRUE(stream); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 79 | streams.push_back(stream); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 80 | } |
| 81 | EXPECT_FALSE(session_.CreateOutgoingReliableStream()); |
| 82 | |
| 83 | // Close a stream and ensure I can now open a new one. |
| 84 | session_.CloseStream(streams[0]->id()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 85 | EXPECT_TRUE(session_.CreateOutgoingReliableStream()); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 88 | TEST_F(QuicClientSessionTest, GoAwayReceived) { |
[email protected] | 0bbeb697 | 2013-05-23 04:10:21 | [diff] [blame^] | 89 | if (!Aes128Gcm12Encrypter::IsSupported()) { |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 90 | LOG(INFO) << "AES GCM not supported. Test skipped."; |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | CompleteCryptoHandshake(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 95 | |
| 96 | // After receiving a GoAway, I should no longer be able to create outgoing |
| 97 | // streams. |
| 98 | session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
| 99 | EXPECT_EQ(NULL, session_.CreateOutgoingReliableStream()); |
| 100 | } |
| 101 | |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 102 | } // namespace |
| 103 | } // namespace test |
| 104 | } // namespace net |