refactor(test): build LDAP fixtures via ldap.NewObject instead of unsafe - #255
Merged
Conversation
simple-ldap-go v1.14.0 adds NewObject(cn, dn), so the mock LDAP fixtures no longer need reflect + unsafe.Pointer to write the unexported Object.dn field. setObjectDN is gone; the DN now comes from the struct literal. The constructor also sets cn, which setObjectDN left empty. Each fixture gets the cn from the leading RDN of its own DN (CN=admin -> "admin"). Refs: netresearch/simple-ldap-go#191 Signed-off-by: Sebastian Mendel <[email protected]>
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files
|
|
Contributor
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 #255 +/- ##
=======================================
Coverage 74.70% 74.70%
=======================================
Files 10 10
Lines 427 427
=======================================
Hits 319 319
Misses 88 88
Partials 20 20
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



simple-ldap-go v1.14.0 adds
func NewObject(cn, dn string) Object(netresearch/simple-ldap-go#191). Until thenObject.cn/Object.dnwere written only by the package-internalobjectFromEntry, so a consumer could not construct a fixture with a DN through the public API — the test helper reached forreflectplusunsafe.Pointer(dnField.UnsafeAddr()), which gosec reports as G103.Removed:
setObjectDN()and thereflect/unsafeimports ininternal/server/test_helpers_test.go. The three mock users (admin, user1, user2) now get theirObjectfromldap.NewObject(cn, dn)in the struct literal.setObjectDNonly wrotednand leftcnempty;NewObjecttakes both. Each fixture uses the leading RDN of its own DN as the cn —CN=admin,OU=Users,DC=example,DC=comgives"admin"— which is what the directory would return for these entries. Nothing in raybeam readsCN()today, so this only makes the fixtures less lopsided.go mod tidyalso dropped stale duplicate entries ingo.sum(oldergo-ldap,gofiber,asn1-berversions that no longer resolve).