Skip to content

refactor(cachetest): build fixtures via ldap.NewObject instead of unsafe - #633

Merged
CybotTM merged 2 commits into
mainfrom
fix/drop-unsafe-fixtures
Jul 29, 2026
Merged

refactor(cachetest): build fixtures via ldap.NewObject instead of unsafe#633
CybotTM merged 2 commits into
mainfrom
fix/drop-unsafe-fixtures

Conversation

@CybotTM

@CybotTM CybotTM commented Jul 29, 2026

Copy link
Copy Markdown
Member

simple-ldap-go v1.14.0 adds NewObject(cn, dn) Object. Until then Object.cn / Object.dn were written only by the package-internal objectFromEntry, so a consumer that wanted a fixture with a known DN had no public way to build one — internal/ldap_cache/cachetest reached the fields through reflect + unsafe.Pointer(...UnsafeAddr()), which gosec flags as G103. See netresearch/simple-ldap-go#191.

The three fixture constructors (NewUserWithDN, NewGroupWithDN, NewComputerWithDN) now set the embedded Object via ldap.NewObject(cn, dn) in a plain composite literal. That removes setObjectFields, the reflect and unsafe imports, and the two #nosec G103 annotations together with the comment block that justified them — a suppression that no longer suppresses anything.

cachetest stays an ordinary (non-_test.go) package: it is imported from another package's tests, which _test.go files cannot be.

Dependency bumped to v1.14.0; go mod tidy also dropped stale go.sum lines for gofiber/storage/bbolt v2.1.8, gofiber/utils v2.1.0 and shamaton/msgpack v3.1.2, none of which were the selected versions.

Not covered here: internal/ldap_cache/test_helpers_test.go carries a second copy of the same reflect+unsafe writer for that package's own tests. It is a _test.go file, outside gosec's default scan set, and out of scope for this change.

Verification: go build ./..., go vet ./..., go test ./... -count=1 and golangci-lint run ./... on the branch; gosec ./... reports Issues: 0. The fixture tests assert on DN/CN — swapping the NewObject arguments locally made them fail, so they do pin the values the unsafe writer used to produce.

simple-ldap-go v1.14.0 adds NewObject(cn, dn), so the cachetest fixture
constructors no longer need reflect + unsafe.Pointer to reach Object.dn
and Object.cn. The #nosec G103 annotations and their explanatory block go
with the unsafe writes.

Refs: netresearch/simple-ldap-go#191
Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
Copilot AI review requested due to automatic review settings July 29, 2026 00:19
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

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

OpenSSF Scorecard

PackageVersionScoreDetails
gomod/github.com/netresearch/simple-ldap-go 1.14.0 🟢 7.5
Details
CheckScoreReason
Packaging⚠️ -1packaging workflow not detected
Dependency-Update-Tool🟢 10update tool detected
Code-Review🟢 10all changesets reviewed
Security-Policy🟢 4security policy file detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Binary-Artifacts🟢 10no binaries found in the repo
Maintained🟢 1030 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Vulnerabilities🟢 73 existing vulnerabilities detected
SAST🟢 10SAST tool is run on all commits
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
License🟢 10license file detected
Fuzzing🟢 10project is fuzzed
Branch-Protection🟢 3branch protection is not maximal on development and all release branches
Contributors🟢 10project has 9 contributing companies or organizations
CI-Tests🟢 1014 out of 14 merged PRs checked by a CI test -- score normalized to 10

Scanned Files

  • go.mod

github-actions[bot]
github-actions Bot previously approved these changes Jul 29, 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.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Mutation Testing Results

Mutation Score: 0.00% (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)

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.89%. Comparing base (f68381b) to head (d0e5db6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #633      +/-   ##
==========================================
- Coverage   70.92%   70.89%   -0.03%     
==========================================
  Files          36       36              
  Lines        3570     3567       -3     
==========================================
- Hits         2532     2529       -3     
  Misses        876      876              
  Partials      162      162              
Flag Coverage Δ
e2e 58.99% <ø> (ø)
unittests 71.38% <100.00%> (-0.03%) ⬇️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

internal/ldap_cache/test_helpers_test.go carried its own copy of the
reflect+unsafe writer for the ldap_cache package's own tests. gosec never
scanned it — it runs without -tests — so it was invisible to the gate rather
than absent, and leaving it would have made this a partial fix of the pattern
NewObject exists to remove.

unsafe is now gone from the repository: grep over every .go file returns
nothing.

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@sonarqubecloud

Copy link
Copy Markdown

@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.

@CybotTM
CybotTM added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit c4bbd62 Jul 29, 2026
30 checks passed
@CybotTM
CybotTM deleted the fix/drop-unsafe-fixtures branch July 29, 2026 01:13
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