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

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

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 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
« no previous file with comments | « net/spdy/fuzzing/hpack_fuzz_util.cc ('k') | net/spdy/header_coalescer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/spdy/fuzzing/hpack_fuzz_util.h"
6
7 #include <map>
8
9 #include "base/base_paths.h"
10 #include "base/files/file.h"
11 #include "base/files/file_util.h"
12 #include "base/path_service.h"
13 #include "net/spdy/spdy_test_utils.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace net {
18 namespace test {
19
20 using std::map;
21 using test::a2b_hex;
22
23 TEST(HpackFuzzUtilTest, GeneratorContextInitialization) {
24 HpackFuzzUtil::GeneratorContext context;
25 HpackFuzzUtil::InitializeGeneratorContext(&context);
26
27 // Context was seeded with initial name & value fixtures.
28 EXPECT_LT(0u, context.names.size());
29 EXPECT_LT(0u, context.values.size());
30 }
31
32 TEST(HpackFuzzUtil, GeneratorContextExpansion) {
33 HpackFuzzUtil::GeneratorContext context;
34
35 SpdyHeaderBlock headers = HpackFuzzUtil::NextGeneratedHeaderSet(&context);
36
37 // Headers were generated, and the generator context was expanded.
38 EXPECT_LT(0u, headers.size());
39 EXPECT_LT(0u, context.names.size());
40 EXPECT_LT(0u, context.values.size());
41 }
42
43 // TODO(jgraettinger): A better test would mock a random generator and
44 // evaluate SampleExponential along fixed points of the [0,1] domain.
45 TEST(HpackFuzzUtilTest, SampleExponentialRegression) {
46 // TODO(jgraettinger): Upstream uses a seeded random generator here to pin
47 // the behavior of SampleExponential. Chromium's random generation utilities
48 // are strongly secure, but provide no way to seed the generator.
49 for (size_t i = 0; i != 100; ++i) {
50 EXPECT_GE(30u, HpackFuzzUtil::SampleExponential(10, 30));
51 }
52 }
53
54 TEST(HpackFuzzUtilTest, ParsesSequenceOfHeaderBlocks) {
55 char fixture[] =
56 "\x00\x00\x00\x05""aaaaa"
57 "\x00\x00\x00\x04""bbbb"
58 "\x00\x00\x00\x03""ccc"
59 "\x00\x00\x00\x02""dd"
60 "\x00\x00\x00\x01""e"
61 "\x00\x00\x00\x00"""
62 "\x00\x00\x00\x03""fin";
63
64 HpackFuzzUtil::Input input;
65 input.input.assign(fixture, arraysize(fixture) - 1);
66
67 SpdyStringPiece block;
68
69 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
70 EXPECT_EQ("aaaaa", block);
71 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
72 EXPECT_EQ("bbbb", block);
73 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
74 EXPECT_EQ("ccc", block);
75 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
76 EXPECT_EQ("dd", block);
77 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
78 EXPECT_EQ("e", block);
79 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
80 EXPECT_EQ("", block);
81 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
82 EXPECT_EQ("fin", block);
83 EXPECT_FALSE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
84 }
85
86 TEST(HpackFuzzUtilTest, SerializedHeaderBlockPrefixes) {
87 EXPECT_EQ(SpdyString("\x00\x00\x00\x00", 4),
88 HpackFuzzUtil::HeaderBlockPrefix(0));
89 EXPECT_EQ(SpdyString("\x00\x00\x00\x05", 4),
90 HpackFuzzUtil::HeaderBlockPrefix(5));
91 EXPECT_EQ("\x4f\xb3\x0a\x91", HpackFuzzUtil::HeaderBlockPrefix(1337133713));
92 }
93
94 TEST(HpackFuzzUtilTest, PassValidInputThroughAllStages) {
95 // Example lifted from HpackDecoderTest.SectionD4RequestHuffmanExamples.
96 SpdyString input = a2b_hex("828684418cf1e3c2e5f23a6ba0ab90f4ff");
97
98 HpackFuzzUtil::FuzzerContext context;
99 HpackFuzzUtil::InitializeFuzzerContext(&context);
100
101 EXPECT_TRUE(
102 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, input));
103
104 SpdyHeaderBlock expect;
105 expect[":method"] = "GET";
106 expect[":scheme"] = "http";
107 expect[":path"] = "/";
108 expect[":authority"] = "www.example.com";
109 EXPECT_EQ(expect, context.third_stage->decoded_block());
110 }
111
112 TEST(HpackFuzzUtilTest, ValidFuzzExamplesRegressionTest) {
113 base::FilePath source_root;
114 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_root));
115
116 // Load the example fixtures versioned with the source tree.
117 HpackFuzzUtil::Input input;
118 ASSERT_TRUE(base::ReadFileToString(
119 source_root.Append(FILE_PATH_LITERAL("net"))
120 .Append(FILE_PATH_LITERAL("data"))
121 .Append(FILE_PATH_LITERAL("spdy_tests"))
122 .Append(FILE_PATH_LITERAL("examples_07.hpack")),
123 &input.input));
124
125 HpackFuzzUtil::FuzzerContext context;
126 HpackFuzzUtil::InitializeFuzzerContext(&context);
127
128 SpdyStringPiece block;
129 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) {
130 // As these are valid examples, all fuzz stages should succeed.
131 EXPECT_TRUE(HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(
132 &context, block));
133 }
134 }
135
136 TEST(HpackFuzzUtilTest, FlipBitsMutatesBuffer) {
137 char buffer[] = "testbuffer1234567890";
138 SpdyString unmodified(buffer, arraysize(buffer) - 1);
139
140 EXPECT_EQ(unmodified, buffer);
141 HpackFuzzUtil::FlipBits(reinterpret_cast<uint8_t*>(buffer),
142 arraysize(buffer) - 1, 1);
143 EXPECT_NE(unmodified, buffer);
144 }
145
146 } // namespace test
147 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/fuzzing/hpack_fuzz_util.cc ('k') | net/spdy/header_coalescer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698