QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015 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/third_party/quiche/src/quic/core/crypto/crypto_handshake_message.h" |
| 6 | |
| 7 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_handshake.h" |
| 8 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_protocol.h" |
| 9 | #include "net/third_party/quiche/src/quic/platform/api/quic_endian.h" |
| 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | namespace test { |
| 14 | namespace { |
| 15 | |
| 16 | TEST(CryptoHandshakeMessageTest, DebugString) { |
| 17 | const char* str = "SHLO<\n>"; |
| 18 | |
| 19 | CryptoHandshakeMessage message; |
| 20 | message.set_tag(kSHLO); |
| 21 | EXPECT_EQ(str, message.DebugString()); |
| 22 | |
| 23 | // Test copy |
| 24 | CryptoHandshakeMessage message2(message); |
| 25 | EXPECT_EQ(str, message2.DebugString()); |
| 26 | |
| 27 | // Test move |
| 28 | CryptoHandshakeMessage message3(std::move(message)); |
| 29 | EXPECT_EQ(str, message3.DebugString()); |
| 30 | |
| 31 | // Test assign |
| 32 | CryptoHandshakeMessage message4 = message3; |
| 33 | EXPECT_EQ(str, message4.DebugString()); |
| 34 | |
| 35 | // Test move-assign |
| 36 | CryptoHandshakeMessage message5 = std::move(message3); |
| 37 | EXPECT_EQ(str, message5.DebugString()); |
| 38 | } |
| 39 | |
| 40 | TEST(CryptoHandshakeMessageTest, DebugStringWithUintVector) { |
| 41 | const char* str = |
| 42 | "REJ <\n RREJ: " |
| 43 | "SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE," |
| 44 | "CLIENT_NONCE_NOT_UNIQUE_FAILURE\n>"; |
| 45 | |
| 46 | CryptoHandshakeMessage message; |
| 47 | message.set_tag(kREJ); |
| 48 | std::vector<uint32_t> reasons = { |
| 49 | SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE, |
| 50 | CLIENT_NONCE_NOT_UNIQUE_FAILURE}; |
| 51 | message.SetVector(kRREJ, reasons); |
| 52 | EXPECT_EQ(str, message.DebugString()); |
| 53 | |
| 54 | // Test copy |
| 55 | CryptoHandshakeMessage message2(message); |
| 56 | EXPECT_EQ(str, message2.DebugString()); |
| 57 | |
| 58 | // Test move |
| 59 | CryptoHandshakeMessage message3(std::move(message)); |
| 60 | EXPECT_EQ(str, message3.DebugString()); |
| 61 | |
| 62 | // Test assign |
| 63 | CryptoHandshakeMessage message4 = message3; |
| 64 | EXPECT_EQ(str, message4.DebugString()); |
| 65 | |
| 66 | // Test move-assign |
| 67 | CryptoHandshakeMessage message5 = std::move(message3); |
| 68 | EXPECT_EQ(str, message5.DebugString()); |
| 69 | } |
| 70 | |
| 71 | TEST(CryptoHandshakeMessageTest, DebugStringWithTagVector) { |
| 72 | const char* str = "CHLO<\n COPT: 'TBBR','PAD ','BYTE'\n>"; |
| 73 | |
| 74 | CryptoHandshakeMessage message; |
| 75 | message.set_tag(kCHLO); |
| 76 | message.SetVector(kCOPT, QuicTagVector{kTBBR, kPAD, kBYTE}); |
| 77 | EXPECT_EQ(str, message.DebugString()); |
| 78 | |
| 79 | // Test copy |
| 80 | CryptoHandshakeMessage message2(message); |
| 81 | EXPECT_EQ(str, message2.DebugString()); |
| 82 | |
| 83 | // Test move |
| 84 | CryptoHandshakeMessage message3(std::move(message)); |
| 85 | EXPECT_EQ(str, message3.DebugString()); |
| 86 | |
| 87 | // Test assign |
| 88 | CryptoHandshakeMessage message4 = message3; |
| 89 | EXPECT_EQ(str, message4.DebugString()); |
| 90 | |
| 91 | // Test move-assign |
| 92 | CryptoHandshakeMessage message5 = std::move(message3); |
| 93 | EXPECT_EQ(str, message5.DebugString()); |
| 94 | } |
| 95 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 96 | TEST(CryptoHandshakeMessageTest, HasStringPiece) { |
| 97 | CryptoHandshakeMessage message; |
wub | 6810fb5 | 2019-05-23 08:34:56 -0700 | [diff] [blame] | 98 | EXPECT_FALSE(message.HasStringPiece(kALPN)); |
| 99 | message.SetStringPiece(kALPN, "foo"); |
| 100 | EXPECT_TRUE(message.HasStringPiece(kALPN)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | } // namespace |
| 104 | } // namespace test |
| 105 | } // namespace quic |