Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: net/spdy/fuzzing/hpack_fuzz_util_test.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/fuzzing/hpack_fuzz_util.h" 5 #include "net/spdy/fuzzing/hpack_fuzz_util.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // TODO(jgraettinger): Upstream uses a seeded random generator here to pin 45 // TODO(jgraettinger): Upstream uses a seeded random generator here to pin
46 // the behavior of SampleExponential. Chromium's random generation utilities 46 // the behavior of SampleExponential. Chromium's random generation utilities
47 // are strongly secure, but provide no way to seed the generator. 47 // are strongly secure, but provide no way to seed the generator.
48 for (size_t i = 0; i != 100; ++i) { 48 for (size_t i = 0; i != 100; ++i) {
49 EXPECT_GE(30u, HpackFuzzUtil::SampleExponential(10, 30)); 49 EXPECT_GE(30u, HpackFuzzUtil::SampleExponential(10, 30));
50 } 50 }
51 } 51 }
52 52
53 TEST(HpackFuzzUtilTest, ParsesSequenceOfHeaderBlocks) { 53 TEST(HpackFuzzUtilTest, ParsesSequenceOfHeaderBlocks) {
54 char fixture[] = 54 char fixture[] =
55 "\x00\x00\x00\x05""aaaaa" 55 "\x00\x00\x00\x05"
56 "\x00\x00\x00\x04""bbbb" 56 "aaaaa"
57 "\x00\x00\x00\x03""ccc" 57 "\x00\x00\x00\x04"
58 "\x00\x00\x00\x02""dd" 58 "bbbb"
59 "\x00\x00\x00\x01""e" 59 "\x00\x00\x00\x03"
60 "\x00\x00\x00\x00""" 60 "ccc"
61 "\x00\x00\x00\x03""fin"; 61 "\x00\x00\x00\x02"
62 "dd"
63 "\x00\x00\x00\x01"
64 "e"
65 "\x00\x00\x00\x00"
66 ""
67 "\x00\x00\x00\x03"
68 "fin";
62 69
63 HpackFuzzUtil::Input input; 70 HpackFuzzUtil::Input input;
64 input.input.assign(fixture, arraysize(fixture) - 1); 71 input.input.assign(fixture, arraysize(fixture) - 1);
65 72
66 StringPiece block; 73 StringPiece block;
67 74
68 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block)); 75 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
69 EXPECT_EQ("aaaaa", block); 76 EXPECT_EQ("aaaaa", block);
70 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block)); 77 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
71 EXPECT_EQ("bbbb", block); 78 EXPECT_EQ("bbbb", block);
(...skipping 19 matching lines...) Expand all
91 98
92 TEST(HpackFuzzUtilTest, PassValidInputThroughAllStages) { 99 TEST(HpackFuzzUtilTest, PassValidInputThroughAllStages) {
93 // Example lifted from HpackDecoderTest.SectionD3RequestHuffmanExamples. 100 // Example lifted from HpackDecoderTest.SectionD3RequestHuffmanExamples.
94 char input[] = 101 char input[] =
95 "\x82\x87\x86\x04\x8b\xdb\x6d\x88\x3e\x68\xd1\xcb\x12\x25\xba\x7f"; 102 "\x82\x87\x86\x04\x8b\xdb\x6d\x88\x3e\x68\xd1\xcb\x12\x25\xba\x7f";
96 103
97 HpackFuzzUtil::FuzzerContext context; 104 HpackFuzzUtil::FuzzerContext context;
98 HpackFuzzUtil::InitializeFuzzerContext(&context); 105 HpackFuzzUtil::InitializeFuzzerContext(&context);
99 106
100 EXPECT_TRUE(HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages( 107 EXPECT_TRUE(HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(
101 &context, 108 &context, StringPiece(input, arraysize(input) - 1)));
102 StringPiece(input, arraysize(input) - 1)));
103 109
104 std::map<string, string> expect; 110 std::map<string, string> expect;
105 expect[":method"] = "GET"; 111 expect[":method"] = "GET";
106 expect[":scheme"] = "http"; 112 expect[":scheme"] = "http";
107 expect[":path"] = "/"; 113 expect[":path"] = "/";
108 expect[":authority"] = "www.example.com"; 114 expect[":authority"] = "www.example.com";
109 EXPECT_EQ(expect, context.third_stage->decoded_block()); 115 EXPECT_EQ(expect, context.third_stage->decoded_block());
110 } 116 }
111 117
112 TEST(HpackFuzzUtilTest, ValidFuzzExamplesRegressionTest) { 118 TEST(HpackFuzzUtilTest, ValidFuzzExamplesRegressionTest) {
113 base::FilePath source_root; 119 base::FilePath source_root;
114 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_root)); 120 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_root));
115 121
116 // Load the example fixtures versioned with the source tree. 122 // Load the example fixtures versioned with the source tree.
117 HpackFuzzUtil::Input input; 123 HpackFuzzUtil::Input input;
118 ASSERT_TRUE(base::ReadFileToString( 124 ASSERT_TRUE(
119 source_root.Append(FILE_PATH_LITERAL("net")) 125 base::ReadFileToString(source_root.Append(FILE_PATH_LITERAL("net"))
120 .Append(FILE_PATH_LITERAL("data")) 126 .Append(FILE_PATH_LITERAL("data"))
121 .Append(FILE_PATH_LITERAL("spdy_tests")) 127 .Append(FILE_PATH_LITERAL("spdy_tests"))
122 .Append(FILE_PATH_LITERAL("examples.hpack")), 128 .Append(FILE_PATH_LITERAL("examples.hpack")),
123 &input.input)); 129 &input.input));
124 130
125 HpackFuzzUtil::FuzzerContext context; 131 HpackFuzzUtil::FuzzerContext context;
126 HpackFuzzUtil::InitializeFuzzerContext(&context); 132 HpackFuzzUtil::InitializeFuzzerContext(&context);
127 133
128 StringPiece block; 134 StringPiece block;
129 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) { 135 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) {
130 // As these are valid examples, all fuzz stages should succeed. 136 // As these are valid examples, all fuzz stages should succeed.
131 EXPECT_TRUE(HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages( 137 EXPECT_TRUE(
132 &context, block)); 138 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, block));
133 } 139 }
134 } 140 }
135 141
136 TEST(HpackFuzzUtilTest, FlipBitsMutatesBuffer) { 142 TEST(HpackFuzzUtilTest, FlipBitsMutatesBuffer) {
137 char buffer[] = "testbuffer1234567890"; 143 char buffer[] = "testbuffer1234567890";
138 string unmodified(buffer, arraysize(buffer) - 1); 144 string unmodified(buffer, arraysize(buffer) - 1);
139 145
140 EXPECT_EQ(unmodified, buffer); 146 EXPECT_EQ(unmodified, buffer);
141 HpackFuzzUtil::FlipBits(reinterpret_cast<uint8*>(buffer), 147 HpackFuzzUtil::FlipBits(
142 arraysize(buffer) - 1, 148 reinterpret_cast<uint8*>(buffer), arraysize(buffer) - 1, 1);
143 1);
144 EXPECT_NE(unmodified, buffer); 149 EXPECT_NE(unmodified, buffer);
145 } 150 }
146 151
147 } // namespace net 152 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698