Skip to content

Commit

Permalink
Fixes up test coverage when strict path validation is not enabled.
Browse files Browse the repository at this point in the history
We should have better coverage of this configuration.

PiperOrigin-RevId: 714160112
  • Loading branch information
birenroy authored and copybara-github committed Jan 10, 2025
1 parent 452e928 commit cd46f49
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions quiche/http2/adapter/header_validator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <utility>
#include <vector>

#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "quiche/common/platform/api/quiche_test.h"

Expand Down Expand Up @@ -486,9 +487,6 @@ TEST(HeaderValidatorTest, InvalidPathPseudoHeader) {
}
EXPECT_FALSE(v.FinishHeaderBlock(HeaderType::REQUEST));

// The remainder of the checks require enabling path validation.
v.SetValidatePath();

// A path that does not start with a slash should fail on finish.
v.StartHeaderBlock();
for (Header to_add : kSampleRequestPseudoheaders) {
Expand All @@ -504,11 +502,11 @@ TEST(HeaderValidatorTest, InvalidPathPseudoHeader) {

// Various valid path characters.
for (const absl::string_view c :
{"/", "?", "_", "'", "9", "&", "(", "@", ":"}) {
{"/", "?", "_", "'", "9", "&", "(", "@", ":", "<", ">", "\\", "[", "}",
"`", "\\", " ", "\t", "#"}) {
const std::string value = absl::StrCat("/shawa", c, "rma");

HeaderValidator validator;
validator.SetValidatePath();
validator.StartHeaderBlock();
for (Header to_add : kSampleRequestPseudoheaders) {
if (to_add.first == ":path") {
Expand All @@ -523,12 +521,37 @@ TEST(HeaderValidatorTest, InvalidPathPseudoHeader) {
EXPECT_TRUE(validator.FinishHeaderBlock(HeaderType::REQUEST));
}

// Various invalid path characters.
for (const absl::string_view c : {"\n", "\r"}) {
SCOPED_TRACE(absl::StrCat("char: ", absl::CEscape(c)));

const std::string value = absl::StrCat("/shawa", c, "rma");

HeaderValidator validator;
validator.StartHeaderBlock();
for (Header to_add : kSampleRequestPseudoheaders) {
if (to_add.first == ":path") {
EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID,
validator.ValidateSingleHeader(to_add.first, value));
} else {
EXPECT_EQ(HeaderValidator::HEADER_OK,
validator.ValidateSingleHeader(to_add.first, to_add.second));
}
}
validator.FinishHeaderBlock(HeaderType::REQUEST);
}
}

TEST(HeaderValidatorTest, PathStrictValidation) {
// Various invalid path characters.
for (const absl::string_view c : {"[", "<", "}", "`", "\\", " ", "\t", "#"}) {
const std::string value = absl::StrCat("/shawa", c, "rma");

HeaderValidator validator;

// Required for strict path validation.
validator.SetValidatePath();

validator.StartHeaderBlock();
for (Header to_add : kSampleRequestPseudoheaders) {
if (to_add.first == ":path") {
Expand All @@ -545,7 +568,10 @@ TEST(HeaderValidatorTest, InvalidPathPseudoHeader) {
// The fragment initial character can be explicitly allowed.
{
HeaderValidator validator;

// Required for strict path validation.
validator.SetValidatePath();

validator.SetAllowFragmentInPath();
validator.StartHeaderBlock();
for (Header to_add : kSampleRequestPseudoheaders) {
Expand Down

0 comments on commit cd46f49

Please sign in to comment.