blob: 4f90b3e8a23bf2fcd371b688ecae432605002737 [file] [log] [blame]
[email protected]dd3fd0e2012-11-04 05:14:401// 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]0d10b592013-02-14 16:09:269#include "net/base/capturing_net_log.h"
[email protected]8ee611b2012-11-20 01:48:1210#include "net/base/test_completion_callback.h"
[email protected]0bbeb6972013-05-23 04:10:2111#include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
[email protected]dd3fd0e2012-11-04 05:14:4012#include "net/quic/crypto/crypto_protocol.h"
[email protected]4df69842013-02-27 06:32:1613#include "net/quic/crypto/quic_decrypter.h"
14#include "net/quic/crypto/quic_encrypter.h"
[email protected]ed3fc15d2013-03-08 18:37:4415#include "net/quic/test_tools/crypto_test_utils.h"
[email protected]899951652013-05-16 12:52:3916#include "net/quic/test_tools/quic_client_session_peer.h"
[email protected]dd3fd0e2012-11-04 05:14:4017#include "net/quic/test_tools/quic_test_utils.h"
18
19using testing::_;
20
21namespace net {
22namespace test {
23namespace {
24
[email protected]41d6b172013-01-29 16:10:5725const char kServerHostname[] = "www.example.com";
26
[email protected]dd3fd0e2012-11-04 05:14:4027class QuicClientSessionTest : public ::testing::Test {
28 protected:
29 QuicClientSessionTest()
30 : guid_(1),
[email protected]14e8106c2013-03-14 16:25:3331 connection_(new PacketSavingConnection(guid_, IPEndPoint(), false)),
[email protected]ef95114d2013-04-17 17:57:0132 session_(connection_, NULL, NULL, NULL, kServerHostname,
[email protected]899951652013-05-16 12:52:3933 QuicConfig(), &crypto_config_, &net_log_) {
[email protected]47a71542013-05-17 07:58:5434 session_.config()->SetDefaults();
[email protected]ef95114d2013-04-17 17:57:0135 crypto_config_.SetDefaults();
[email protected]899951652013-05-16 12:52:3936 QuicClientSessionPeer::SetMaxOpenStreams(&session_, 1, 1);
[email protected]dd3fd0e2012-11-04 05:14:4037 }
38
[email protected]ed3fc15d2013-03-08 18:37:4439 void CompleteCryptoHandshake() {
40 ASSERT_EQ(ERR_IO_PENDING,
41 session_.CryptoConnect(callback_.callback()));
[email protected]e8ff26842013-03-22 21:02:0542 CryptoTestUtils::HandshakeWithFakeServer(
43 connection_, session_.GetCryptoStream());
[email protected]ed3fc15d2013-03-08 18:37:4444 ASSERT_EQ(OK, callback_.WaitForResult());
[email protected]ed3fc15d2013-03-08 18:37:4445 }
46
[email protected]dd3fd0e2012-11-04 05:14:4047 QuicGuid guid_;
48 PacketSavingConnection* connection_;
[email protected]ed3fc15d2013-03-08 18:37:4449 CapturingNetLog net_log_;
[email protected]dd3fd0e2012-11-04 05:14:4050 QuicClientSession session_;
[email protected]ed3fc15d2013-03-08 18:37:4451 MockClock clock_;
52 MockRandom random_;
[email protected]dd3fd0e2012-11-04 05:14:4053 QuicConnectionVisitorInterface* visitor_;
[email protected]8ee611b2012-11-20 01:48:1254 TestCompletionCallback callback_;
[email protected]ef95114d2013-04-17 17:57:0155 QuicCryptoClientConfig crypto_config_;
[email protected]dd3fd0e2012-11-04 05:14:4056};
57
[email protected]ed3fc15d2013-03-08 18:37:4458TEST_F(QuicClientSessionTest, CryptoConnect) {
[email protected]0bbeb6972013-05-23 04:10:2159 if (!Aes128Gcm12Encrypter::IsSupported()) {
[email protected]74bda142013-03-31 02:49:1160 LOG(INFO) << "AES GCM not supported. Test skipped.";
61 return;
62 }
63
[email protected]ed3fc15d2013-03-08 18:37:4464 CompleteCryptoHandshake();
[email protected]8ee611b2012-11-20 01:48:1265}
66
67TEST_F(QuicClientSessionTest, MaxNumConnections) {
[email protected]0bbeb6972013-05-23 04:10:2168 if (!Aes128Gcm12Encrypter::IsSupported()) {
[email protected]74bda142013-03-31 02:49:1169 LOG(INFO) << "AES GCM not supported. Test skipped.";
70 return;
71 }
72
[email protected]ed3fc15d2013-03-08 18:37:4473 CompleteCryptoHandshake();
[email protected]dd3fd0e2012-11-04 05:14:4074
75 std::vector<QuicReliableClientStream*> streams;
76 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) {
77 QuicReliableClientStream* stream = session_.CreateOutgoingReliableStream();
[email protected]dd3fd0e2012-11-04 05:14:4078 EXPECT_TRUE(stream);
[email protected]f702d572012-12-04 15:56:2079 streams.push_back(stream);
[email protected]dd3fd0e2012-11-04 05:14:4080 }
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]f702d572012-12-04 15:56:2085 EXPECT_TRUE(session_.CreateOutgoingReliableStream());
[email protected]dd3fd0e2012-11-04 05:14:4086}
87
[email protected]9db443912013-02-25 05:27:0388TEST_F(QuicClientSessionTest, GoAwayReceived) {
[email protected]0bbeb6972013-05-23 04:10:2189 if (!Aes128Gcm12Encrypter::IsSupported()) {
[email protected]8ba81212013-05-03 13:11:4890 LOG(INFO) << "AES GCM not supported. Test skipped.";
91 return;
92 }
93
94 CompleteCryptoHandshake();
[email protected]9db443912013-02-25 05:27:0395
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]dd3fd0e2012-11-04 05:14:40102} // namespace
103} // namespace test
104} // namespace net