Skip to content

fix: keep test scaffolding out of the binary and bump the toolchain - #254

Merged
CybotTM merged 1 commit into
mainfrom
fix/gosec-and-toolchain
Jul 28, 2026
Merged

fix: keep test scaffolding out of the binary and bump the toolchain#254
CybotTM merged 1 commit into
mainfrom
fix/gosec-and-toolchain

Conversation

@CybotTM

@CybotTM CybotTM commented Jul 28, 2026

Copy link
Copy Markdown
Member

gosec became blocking in the shared workflow (netresearch/.github#312) and immediately failed here, as did govulncheck. Both are fixed.

gosec: test scaffolding was in the production binary

G103 (audit unsafe) pointed at internal/server/test_helpers.go. The file has no _test suffix, so it compiled into package server — the mock LDAP client, the fixture builder, and its reflect+unsafe write to ldap.Object's unexported dn field all shipped in the binary. Nothing called them, but they were there.

Split by what production actually needs: LDAPClient is the only declaration used outside tests (2 call sites) and moves to ldap_client.go; MockLDAP, NewMockLDAP, setObjectDN and newTestServer move to test_helpers_test.go. unsafe and reflect are now compiled into the test binary only.

No suppression comment. gosec runs without -tests, so the finding is gone because the code left the build — not because it was silenced. A #nosec there would have suppressed nothing while implying it had.

The unsafe write itself is unchanged and still justified: simple-ldap-go writes Object.dn only in objectFromEntry when decoding a directory response and exposes no constructor taking a DN, so a fixture cannot be built through its public API. That library gap is worth closing separately; it is not this PR's job.

govulncheck: four stdlib advisories

GO-2026-5856 (crypto/tls), GO-2026-5039 (net/textproto), GO-2026-5037 (crypto/x509), GO-2026-4971 (net). The module was on go 1.25.1 with no toolchain. It now uses go 1.26 with toolchain go1.26.5, matching ofelia.

Verification

Run with go1.26.5:

  • gosec: Issues : 0, exit 0
  • govulncheck: Your code is affected by 0 vulnerabilities, exit 0
  • go vet ./... clean, go test ./... passes
  • grep '"unsafe"' over non-test files returns nothing

gosec became blocking in the shared workflow and flagged G103 (audit unsafe)
in internal/server/test_helpers.go. The file has no _test suffix, so it
compiled into package server: the mock LDAP client, the fixture builder and
its reflect+unsafe write to ldap.Object's unexported dn field all shipped in
the production binary, reachable by nothing but reachable all the same.

Split it. LDAPClient is the only declaration production code uses (2 call
sites), so it moves to ldap_client.go; MockLDAP, NewMockLDAP, setObjectDN and
newTestServer move to test_helpers_test.go. unsafe and reflect are now
compiled into the test binary only. No suppression comment: gosec runs without
-tests, so the finding is gone because the code is gone from the build, not
because it was silenced.

The unsafe write itself stays as-is. simple-ldap-go writes Object.dn only in
objectFromEntry when decoding a directory response and exposes no constructor
taking a DN, so a fixture cannot be built through its public API.

govulncheck was failing too, on four stdlib advisories. Move the module to
go 1.26 with toolchain go1.26.5, matching ofelia.

Verified with go1.26.5: gosec 0 issues, govulncheck reports 0 affecting
vulnerabilities, go vet clean, tests pass, and no production file imports
unsafe.

Signed-off-by: Sebastian Mendel <[email protected]>
Copilot AI review requested due to automatic review settings July 28, 2026 18:22
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Mutation Testing Results

Mutation Score: 0% (threshold: 60%)

⚠️ Score is below threshold. Consider improving test coverage or test quality.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file tests labels Jul 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated approval for maintainer PR

All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.

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.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.70%. Comparing base (8c29c3c) to head (c5a6da4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #254      +/-   ##
==========================================
- Coverage   75.39%   74.70%   -0.69%     
==========================================
  Files          11       10       -1     
  Lines         512      427      -85     
==========================================
- Hits          386      319      -67     
+ Misses        101       88      -13     
+ Partials       25       20       -5     
Flag Coverage Δ
e2e 74.70% <ø> (-0.69%) ⬇️
integration 74.70% <ø> (-0.69%) ⬇️
unittests 74.70% <ø> (-0.69%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CybotTM
CybotTM added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit f963d3c Jul 28, 2026
27 of 28 checks passed
@CybotTM
CybotTM deleted the fix/gosec-and-toolchain branch July 28, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants