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/spdy/spdy_test_utils.h" | 5 #include "net/spdy/spdy_test_utils.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/sys_byteorder.h" | 14 #include "base/sys_byteorder.h" |
15 #include "net/http/transport_security_state.h" | 15 #include "net/http/transport_security_state.h" |
16 #include "net/ssl/ssl_info.h" | 16 #include "net/ssl/ssl_info.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | |
21 namespace test { | 20 namespace test { |
22 | 21 |
23 std::string HexDumpWithMarks(const unsigned char* data, int length, | 22 std::string HexDumpWithMarks(const unsigned char* data, int length, |
24 const bool* marks, int mark_length) { | 23 const bool* marks, int mark_length) { |
25 static const char kHexChars[] = "0123456789abcdef"; | 24 static const char kHexChars[] = "0123456789abcdef"; |
26 static const int kColumns = 4; | 25 static const int kColumns = 4; |
27 | 26 |
28 const int kSizeLimit = 1024; | 27 const int kSizeLimit = 1024; |
29 if (length > kSizeLimit || mark_length > kSizeLimit) { | 28 if (length > kSizeLimit || mark_length > kSizeLimit) { |
30 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes."; | 29 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes."; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 memcpy(frame->data(), | 122 memcpy(frame->data(), |
124 reinterpret_cast<char*>(&wire_length) + 1, | 123 reinterpret_cast<char*>(&wire_length) + 1, |
125 3); | 124 3); |
126 } | 125 } |
127 break; | 126 break; |
128 default: | 127 default: |
129 LOG(FATAL) << "Unsupported SPDY version."; | 128 LOG(FATAL) << "Unsupported SPDY version."; |
130 } | 129 } |
131 } | 130 } |
132 | 131 |
| 132 bool CompareSpdyHeaderBlocks(const SpdyHeaderBlock& a, |
| 133 const SpdyHeaderBlock& b) { |
| 134 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin()); |
| 135 } |
| 136 |
133 std::string a2b_hex(const char* hex_data) { | 137 std::string a2b_hex(const char* hex_data) { |
134 std::vector<uint8> output; | 138 std::vector<uint8> output; |
135 std::string result; | 139 std::string result; |
136 if (base::HexStringToBytes(hex_data, &output)) | 140 if (base::HexStringToBytes(hex_data, &output)) |
137 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); | 141 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); |
138 return result; | 142 return result; |
139 } | 143 } |
140 | 144 |
141 HashValue GetTestHashValue(uint8_t label) { | 145 HashValue GetTestHashValue(uint8_t label) { |
142 HashValue hash_value(HASH_VALUE_SHA256); | 146 HashValue hash_value(HASH_VALUE_SHA256); |
(...skipping 19 matching lines...) Expand all Loading... |
162 std::string header = "max-age = 10000; " + primary_pin + "; " + backup_pin; | 166 std::string header = "max-age = 10000; " + primary_pin + "; " + backup_pin; |
163 | 167 |
164 // Construct a fake SSLInfo that will pass AddHPKPHeader's checks. | 168 // Construct a fake SSLInfo that will pass AddHPKPHeader's checks. |
165 SSLInfo ssl_info; | 169 SSLInfo ssl_info; |
166 ssl_info.is_issued_by_known_root = true; | 170 ssl_info.is_issued_by_known_root = true; |
167 ssl_info.public_key_hashes.push_back(GetTestHashValue(primary_label)); | 171 ssl_info.public_key_hashes.push_back(GetTestHashValue(primary_label)); |
168 EXPECT_TRUE(state->AddHPKPHeader(host, header, ssl_info)); | 172 EXPECT_TRUE(state->AddHPKPHeader(host, header, ssl_info)); |
169 } | 173 } |
170 | 174 |
171 } // namespace test | 175 } // namespace test |
172 | |
173 } // namespace net | 176 } // namespace net |
OLD | NEW |