refactor(cachetest): build fixtures via ldap.NewObject instead of unsafe - #633
Conversation
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>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files
|
There was a problem hiding this comment.
Automated approval for maintainer PR
All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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>
|
There was a problem hiding this comment.
Automated approval for maintainer PR
All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.



simple-ldap-go v1.14.0 adds
NewObject(cn, dn) Object. Until thenObject.cn/Object.dnwere written only by the package-internalobjectFromEntry, so a consumer that wanted a fixture with a known DN had no public way to build one —internal/ldap_cache/cachetestreached the fields throughreflect+unsafe.Pointer(...UnsafeAddr()), which gosec flags as G103. See netresearch/simple-ldap-go#191.The three fixture constructors (
NewUserWithDN,NewGroupWithDN,NewComputerWithDN) now set the embeddedObjectvialdap.NewObject(cn, dn)in a plain composite literal. That removessetObjectFields, thereflectandunsafeimports, and the two#nosec G103annotations together with the comment block that justified them — a suppression that no longer suppresses anything.cacheteststays an ordinary (non-_test.go) package: it is imported from another package's tests, which_test.gofiles cannot be.Dependency bumped to v1.14.0;
go mod tidyalso dropped stalego.sumlines forgofiber/storage/bboltv2.1.8,gofiber/utilsv2.1.0 andshamaton/msgpackv3.1.2, none of which were the selected versions.Not covered here:
internal/ldap_cache/test_helpers_test.gocarries a second copy of the same reflect+unsafe writer for that package's own tests. It is a_test.gofile, outside gosec's default scan set, and out of scope for this change.Verification:
go build ./...,go vet ./...,go test ./... -count=1andgolangci-lint run ./...on the branch;gosec ./...reportsIssues: 0. The fixture tests assert on DN/CN — swapping theNewObjectarguments locally made them fail, so they do pin the values the unsafe writer used to produce.