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_util_spdy3.h" | 5 #include "net/spdy/spdy_test_util_spdy3.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "crypto/ec_private_key.h" |
| 14 #include "crypto/ec_signature_creator.h" |
13 #include "net/base/mock_cert_verifier.h" | 15 #include "net/base/mock_cert_verifier.h" |
14 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
15 #include "net/http/http_network_transaction.h" | 17 #include "net/http/http_network_transaction.h" |
16 #include "net/http/http_server_properties_impl.h" | 18 #include "net/http/http_server_properties_impl.h" |
17 #include "net/spdy/buffered_spdy_framer.h" | 19 #include "net/spdy/buffered_spdy_framer.h" |
18 #include "net/spdy/spdy_http_utils.h" | 20 #include "net/spdy/spdy_http_utils.h" |
19 #include "net/spdy/spdy_session.h" | 21 #include "net/spdy/spdy_session.h" |
20 | 22 |
21 namespace net { | 23 namespace net { |
22 | 24 |
23 namespace test_spdy3 { | 25 namespace test_spdy3 { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 // Parses a URL into the scheme, host, and path components required for a | 29 // Parses a URL into the scheme, host, and path components required for a |
28 // SPDY request. | 30 // SPDY request. |
29 void ParseUrl(const char* const url, std::string* scheme, std::string* host, | 31 void ParseUrl(const char* const url, std::string* scheme, std::string* host, |
30 std::string* path) { | 32 std::string* path) { |
31 GURL gurl(url); | 33 GURL gurl(url); |
32 path->assign(gurl.PathForRequest()); | 34 path->assign(gurl.PathForRequest()); |
33 scheme->assign(gurl.scheme()); | 35 scheme->assign(gurl.scheme()); |
34 host->assign(gurl.host()); | 36 host->assign(gurl.host()); |
35 if (gurl.has_port()) { | 37 if (gurl.has_port()) { |
36 host->append(":"); | 38 host->append(":"); |
37 host->append(gurl.port()); | 39 host->append(gurl.port()); |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
| 43 // An ECSignatureCreator that returns deterministic signatures. |
| 44 class MockECSignatureCreator : public crypto::ECSignatureCreator { |
| 45 public: |
| 46 explicit MockECSignatureCreator(crypto::ECPrivateKey* key) : key_(key) {} |
| 47 |
| 48 virtual bool Sign(const uint8* data, |
| 49 int data_len, |
| 50 std::vector<uint8>* signature) OVERRIDE { |
| 51 std::vector<uint8> private_key_value; |
| 52 key_->ExportValue(&private_key_value); |
| 53 std::string head = "fakesignature"; |
| 54 std::string tail = "/fakesignature"; |
| 55 |
| 56 signature->clear(); |
| 57 signature->insert(signature->end(), head.begin(), head.end()); |
| 58 signature->insert(signature->end(), private_key_value.begin(), |
| 59 private_key_value.end()); |
| 60 signature->insert(signature->end(), '-'); |
| 61 signature->insert(signature->end(), data, data + data_len); |
| 62 signature->insert(signature->end(), tail.begin(), tail.end()); |
| 63 return true; |
| 64 } |
| 65 |
| 66 private: |
| 67 crypto::ECPrivateKey* key_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreator); |
| 70 }; |
| 71 |
| 72 // An ECSignatureCreatorFactory creates MockECSignatureCreator. |
| 73 class MockECSignatureCreatorFactory : public crypto::ECSignatureCreatorFactory { |
| 74 public: |
| 75 MockECSignatureCreatorFactory() {} |
| 76 virtual ~MockECSignatureCreatorFactory() {} |
| 77 |
| 78 virtual crypto::ECSignatureCreator* Create( |
| 79 crypto::ECPrivateKey* key) OVERRIDE { |
| 80 return new MockECSignatureCreator(key); |
| 81 } |
| 82 |
| 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); |
| 85 }; |
| 86 |
41 } // namespace | 87 } // namespace |
42 | 88 |
43 // Chop a frame into an array of MockWrites. | 89 // Chop a frame into an array of MockWrites. |
44 // |data| is the frame to chop. | 90 // |data| is the frame to chop. |
45 // |length| is the length of the frame to chop. | 91 // |length| is the length of the frame to chop. |
46 // |num_chunks| is the number of chunks to create. | 92 // |num_chunks| is the number of chunks to create. |
47 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { | 93 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { |
48 MockWrite* chunks = new MockWrite[num_chunks]; | 94 MockWrite* chunks = new MockWrite[num_chunks]; |
49 int chunk_size = length / num_chunks; | 95 int chunk_size = length / num_chunks; |
50 for (int index = 0; index < num_chunks; index++) { | 96 for (int index = 0; index < num_chunks; index++) { |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 CONTROL_FLAG_FIN, // Control Flags | 1035 CONTROL_FLAG_FIN, // Control Flags |
990 false, // Compressed | 1036 false, // Compressed |
991 INVALID, // Status | 1037 INVALID, // Status |
992 NULL, // Data | 1038 NULL, // Data |
993 0, // Length | 1039 0, // Length |
994 DATA_FLAG_NONE // Data Flags | 1040 DATA_FLAG_NONE // Data Flags |
995 }; | 1041 }; |
996 return kHeader; | 1042 return kHeader; |
997 } | 1043 } |
998 | 1044 |
999 SpdyTestStateHelper::SpdyTestStateHelper() { | 1045 SpdyTestStateHelper::SpdyTestStateHelper() |
| 1046 : ec_signature_creator_factory_(new MockECSignatureCreatorFactory()) { |
| 1047 // Use the mock signature creator. |
| 1048 crypto::ECSignatureCreator::SetFactoryForTesting( |
| 1049 ec_signature_creator_factory_.get()); |
1000 // Pings can be non-deterministic, because they are sent via timer. | 1050 // Pings can be non-deterministic, because they are sent via timer. |
1001 SpdySession::set_enable_ping_based_connection_checking(false); | 1051 SpdySession::set_enable_ping_based_connection_checking(false); |
1002 // Avoid sending a non-default initial receive window size settings | 1052 // Avoid sending a non-default initial receive window size settings |
1003 // frame on every test. | 1053 // frame on every test. |
1004 SpdySession::set_default_initial_recv_window_size( | 1054 SpdySession::set_default_initial_recv_window_size( |
1005 kSpdyStreamInitialWindowSize); | 1055 kSpdyStreamInitialWindowSize); |
1006 // Compression is per-session which makes it impossible to create | 1056 // Compression is per-session which makes it impossible to create |
1007 // SPDY frames with static methods. | 1057 // SPDY frames with static methods. |
1008 BufferedSpdyFramer::set_enable_compression_default(false); | 1058 BufferedSpdyFramer::set_enable_compression_default(false); |
1009 } | 1059 } |
1010 | 1060 |
1011 SpdyTestStateHelper::~SpdyTestStateHelper() { | 1061 SpdyTestStateHelper::~SpdyTestStateHelper() { |
1012 SpdySession::ResetStaticSettingsToInit(); | 1062 SpdySession::ResetStaticSettingsToInit(); |
1013 // TODO(rch): save/restore this value | 1063 // TODO(rch): save/restore this value |
1014 BufferedSpdyFramer::set_enable_compression_default(true); | 1064 BufferedSpdyFramer::set_enable_compression_default(true); |
| 1065 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); |
1015 } | 1066 } |
1016 | 1067 |
1017 } // namespace test_spdy3 | 1068 } // namespace test_spdy3 |
1018 | 1069 |
1019 } // namespace net | 1070 } // namespace net |
OLD | NEW |