Skip to content

fix: cover all arbitrary HTTP methods and schemes - #596

Open
RaphaelFakhri wants to merge 1 commit into
linkerd:mainfrom
RaphaelFakhri:fix-arbitrary-http-types
Open

RaphaelFakhri wants to merge 1 commit into
linkerd:mainfrom
RaphaelFakhri:fix-arbitrary-http-types

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Problem

The arbitrary feature's Arbitrary impls for http_method::Type and scheme::Type choose a variant with a modulo whose range does not match the match arms:

  • scheme::Type uses u16::arbitrary(g) % 3 but matches 3 for Unregistered. That arm is unreachable, so the generator never produces an unregistered scheme, and one third of its values are Registered(2), which is not a valid scheme::Registered value.
  • http_method::Type uses % 9 and matches 8 for Unregistered, so it never produces the registered TRACE method (8).

Property tests that use these generators, such as the tap match tests in linkerd2-proxy, never exercise unregistered schemes or TRACE, and they often get an invalid registered scheme.

Solution

  • http_method::Type: use % 10 and match 9 for Unregistered, so 0..=8 covers every registered method.
  • scheme::Type: match 2 for Unregistered, so 0..=1 covers HTTP and HTTPS.

Validation

Two new tests (arbitrary_http_method_covers_all_types and arbitrary_scheme_covers_all_types) generate 10,000 values each. They check that every registered value is valid and that every registered variant and the unregistered variant appear.

  • cargo test --all-features --locked without the fix: 2 failed.
  • With the fix: 2 passed.
  • cargo fmt -- --check passes.

The `Arbitrary` impls for `http_method::Type` and `scheme::Type` pick a
variant with a modulo whose range does not match the match arms:

* `scheme::Type` uses `% 3` but matches `3` for `Unregistered`, so it
  never produces an unregistered scheme and produces the invalid
  `Registered(2)` for a third of the values.
* `http_method::Type` uses `% 9` and matches `8` for `Unregistered`, so
  it never produces the registered `TRACE` method (8).

This change uses `% 10` with `9` for unregistered methods and matches
`2` for unregistered schemes, so both generators cover every registered
value and the unregistered variant, and never produce an invalid
registered value.

Tests generate values from both impls and check that every registered
variant and the unregistered variant appear and that every registered
value is valid.

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant