Skip to content

test: TailscaleUtil CGNAT range unit tests#2134

Open
marcdhansen wants to merge 6 commits intodebauchee:masterfrom
marcdhansen:feature/tailscale-util-tests
Open

test: TailscaleUtil CGNAT range unit tests#2134
marcdhansen wants to merge 6 commits intodebauchee:masterfrom
marcdhansen:feature/tailscale-util-tests

Conversation

@marcdhansen
Copy link
Copy Markdown

Summary

  • Exposes is_tailscale_addr() in barrier::detail namespace so it can be tested without real network interfaces
  • Adds 8 unit tests in src/test/unittests/net/TailscaleUtilTests.cpp covering:
    • First and last address in the 100.64.0.0/10 range (boundary)
    • Typical Tailscale address (100.100.100.100)
    • Addresses just below and just above the range
    • Loopback, RFC-1918, and zero address (all negative cases)

Test plan

  • Build unittests target and confirm new tests pass
  • Confirm no regression in existing net/ tests (FingerprintDatabase, SecureUtils)

🤖 Generated with Claude Code

marcdhansen and others added 4 commits April 3, 2026 01:33
Phase 2: Tailscale integration (--tailscale-mode)

Reviewed: CGNAT range verified, Windows/Unix interface detection correct, SSL controls disabled in GUI when Tailscale active, --tailscale-mode wired through ArgParser/ServerApp/ClientApp.
Expose is_tailscale_addr() in barrier::detail namespace so it can be
tested directly without requiring real network interfaces. Add 8 boundary
and edge-case tests covering the 100.64.0.0/10 CGNAT range.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Fix AddressJustBelowRange test: 0x6443FFFFu (100.67.255.255) was
  inside the CGNAT range; correct value for 100.63.255.255 is 0x643FFFFFu
- Add in-class initializer (= false) to m_TailscaleMode in AppConfig,
  consistent with m_RequireClientCertificate

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copy link
Copy Markdown
Author

@marcdhansen marcdhansen left a comment

Choose a reason for hiding this comment

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

Parallel Agent Review — 3 reviewers (code, silent-failure, test-coverage)

Blockers (resolved before posting)

AddressJustBelowRange test had wrong hex constant (flagged by all 3 agents — fixed in 268179f)
0x6443FFFFu decodes to 100.67.255.255, which is inside the Tailscale range. EXPECT_FALSE would have failed at runtime. Corrected to 0x643FFFFFu (100.63.255.255).

Important (resolved before posting)

m_TailscaleMode uninitialized in AppConfig (flagged by 2 agents — fixed in 268179f)
bool m_TailscaleMode; had no in-class initializer, unlike m_RequireClientCertificate = false on the line below. Added = false to match the convention and prevent indeterminate value if loadSettings() is not called.

Important (open — pre-existing, not introduced by this PR)

Silent failures in TailscaleUtil.cpp have no logging:

  • Unix path: getifaddrs failure returns {} silently — conflates a system error (ENOMEM, permission denied) with "Tailscale not installed"
  • Windows path: if the second GetAdaptersAddresses call fails after the buffer-overflow retry, ret is discarded with no log

These are in the Phase 2 code; suggest filing a follow-up issue.

Suggestions

  • No test for get_tailscale_address() itself — the PR is correctly scoped to white-box testing is_tailscale_addr. A brief comment in the test file explaining why (requires real network interfaces) would help future contributors.
  • PrivateRfc1918NotInRange packs 3 assertions — splitting into named tests would give cleaner failure diagnostics.
  • 0xFFFFFFFFu (all-ones/broadcast) not tested — not a correctness risk, but a common robustness canary for range functions.

Strengths

  • Boundary testing (first, last, just-below, just-above) is exactly right for a range-check function
  • Tests live in barrier::detail namespace — clean white-box approach without polluting public API
  • CMakeLists uses GLOB_RECURSE — no build system changes needed
  • Windows GetAdaptersAddresses retry pattern is correct
  • --tailscale-mode correctly sets both m_tailscaleMode = true and m_enableCrypto = false atomically

marcdhansen and others added 2 commits April 4, 2026 12:18
- Add .github/workflows/ci.yml: builds on Ubuntu 22.04, runs ctest
- Add add_test(unittests) to CMakeLists so ctest discovers the binary
- Pass -DBARRIER_BUILD_TESTS=ON to enable the test targets

The upstream Azure Pipelines config builds but never runs tests;
this fills that gap for the fork.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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