Skip to content

test(dns): expand is_hostname coverage for length, hyphen, dot, and A-label branches#2683

Open
vtushar06 wants to merge 2 commits into
sourcemeta:mainfrom
vtushar06:test-hostname-coverage
Open

test(dns): expand is_hostname coverage for length, hyphen, dot, and A-label branches#2683
vtushar06 wants to merge 2 commits into
sourcemeta:mainfrom
vtushar06:test-hostname-coverage

Conversation

@vtushar06

@vtushar06 vtushar06 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

I added 94 tests for is_hostname. Core already passes all of them, so this is coverage, not a fix.

I went through src/core/dns/hostname.cc branch by branch and wrote tests for the ones the existing 66 did not reach.

What is new

  • Total length. The existing cap tests reach 255 through four 63-byte labels. These reach it through 128 single-character labels instead, so the arithmetic is exercised rather than one shape. Plus 63/64 in both a middle and a last label, which are different code paths.
  • Hyphen placement. Leading, trailing, lone -, consecutive hyphens, and a 63-byte label that is almost all hyphens.
  • Dot structure. Empty labels, leading and trailing dots, repeated dots.
  • The xn-- A-label branch, including the case-insensitive prefix match (Xn--, xN--, XN--).
  • Line terminators, whitespace and embedded NUL. The NUL cases use an explicit-length std::string_view(..., N) - written as a plain C string literal they would truncate at the NUL and silently test a different input.
  • Non-ASCII UTF-8 in a label.
  • Three loops sweeping all 256 byte values in leading, interior and trailing position, so the accepted character set is pinned by construction rather than by sampling.

How I checked the expected values

Every input was run through the real is_hostname before I wrote the expectation down, so none of these are hand-guessed. The file compiles clean and the dns target reports 277 passed, 0 failed. clang-format is idempotent on it.

One deliberate inconsistency

The existing tests in this file assert is_idn_hostname alongside is_hostname. Mine assert is_hostname only. A few of these inputs are ones where the two predicates currently disagree, so pairing them here would have written that disagreement in as expected behaviour. I would rather raise it on its own, which I will do separately.

RFC references

Review in cubic

…-label branches

Adds 94 tests for is_hostname. Core already passes all of them, so this is
coverage, not a fix.

What is new:
- the total-length cap reached through many short labels, not just four
  63-byte ones, and the 63/64 boundary in both a middle and a last label
- hyphen placement: leading, trailing, lone, consecutive, and a 63-byte
  hyphen-heavy label
- dot structure: empty labels, leading and trailing dots, repeated dots
- the xn-- A-label branch, including the case-insensitive prefix
- line terminators, whitespace, and embedded NUL
- non-ASCII UTF-8 in a label
- three loops that sweep all 256 byte values in leading, interior and
  trailing position

How I checked the expected values: every input was run through the real
is_hostname before being written down, and the file compiles and runs
clean (277 passed, 0 failed for the dns target).

The tests assert is_hostname only, rather than following the file's
existing habit of asserting is_idn_hostname alongside it. A few of these
inputs are ones where the two predicates currently disagree, so pairing
them here would have baked that in. I will raise that separately.

RFC references:
- RFC 1123 section 2.1 (host name syntax, first-character relaxation)
- RFC 952 (the <name> grammar and its character repertoire)
- RFC 1035 sections 2.3.1 and 3.1 (letter/digit sets, length limits)

Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
Copilot AI review requested due to automatic review settings July 25, 2026 16:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@augmentcode

augmentcode Bot commented Jul 25, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR expands test coverage for sourcemeta::core::is_hostname without changing implementation behavior.

Changes:

  • Added extensive hostname-length tests covering total length (255/256) via many short labels and very-large inputs.
  • Added per-label length tests (63/64) for middle and last label positions.
  • Expanded invalid/valid hyphen-placement cases across single- and multi-label hostnames.
  • Added dot-structure tests for empty labels, leading/trailing dots, and repeated dots.
  • Added targeted tests for the xn-- A-label (ACE) branch, including case-insensitive prefix handling and “fake A-label” cases.
  • Added whitespace/line-terminator rejection cases (LF/CR/CRLF, tabs, spaces).
  • Added embedded-NUL cases using explicit-length std::string_view to prevent truncation.
  • Added exhaustive 0–255 byte sweeps for leading/interior/trailing positions to pin the accepted ASCII byte repertoire.
  • Added non-ASCII UTF-8 / confusable-character rejection cases.
  • Added additional valid-shape coverage (e.g., localhost, all-numeric labels, dotted-quad forms, uppercase-only).

Technical Notes: The new tests are structured to hit previously-unreached branches in src/core/dns/hostname.cc and to assert current is_hostname behavior without also locking in is_idn_hostname divergences.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Comment thread test/dns/hostname_test.cc Outdated
Comment thread test/dns/hostname_test.cc Outdated
jviotti asked for two changes:

- drop the multi-line section-banner comments and go back to the file's
  own convention, one concise RFC-citation line directly above each
  test (or a tight 2-3 test cluster where they are genuinely the same
  rule, matching how the existing MIDDLE DOT/GERESH tests already do
  this)
- replace the three loop-based byte-alphabet sweeps with literal
  sequential EXPECT_TRUE/FALSE calls, split into groups rather than one
  256-assertion test. I grouped by ASCII structure (controls, digits,
  uppercase, lowercase, punctuation, non-ASCII in four quarters), 12
  groups per position, 36 tests total, still covering all 256 byte
  values at each of the three positions

Generated the literal expansion from the real is_hostname output so
nothing here is hand-guessed, same as the rest of the file. That
generation caught a bug in itself: a byte value of 0 written as a
plain concatenated string literal truncates on the implicit
const char* -> string_view conversion, so a candidate like
"a" "\x00" "b" only reaches is_hostname as "a". Fixed by using an
explicit-length std::string_view for the three NUL cases, matching
how the file's existing embedded-NUL tests already do it.

310 passed, 0 failed on the dns target. clang-format is a stable
fixed point. Mutation-checked by flipping three expectations and
confirming exactly three failures.

Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
@vtushar06

vtushar06 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@jviotti I have addressed both - dropped the section banners for one line per test, and expanded the byte sweep into literal calls grouped by ASCII range.

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.

3 participants