refactor: replace go:linkname with oidctrusttest helper package - #369
Conversation
Signed-off-by: Pawel Szelag <pablo.szel@gmail.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| // NewModule returns a TrustModule backed by the given repository. | ||
| func NewModule(repo oidctrust.TrustRepository) sessionmanager.Trust { | ||
| return oidctrust.NewModule(repo) | ||
| } |
There was a problem hiding this comment.
It just doubles oidctrust.NewModule function. Do we need this package and why can't we use the oidctrust.NewModule directly?
There was a problem hiding this comment.
It was added to follow httptest convention and signal test-only usage. Obviously, since TrustRepository and TrustModule are public types, promoting NewModule to the public API of oidctrust is all right in my eyes. I proposed the approach with oidctrusttest package to propose a compromise between unsafe approach and simply exporting, but if we find it more confusing than helpful, then I'd simply export it. Please let me know how we prefer it, curious to hear @cb80 take on this as well
There was a problem hiding this comment.
httptest does a a bit more than just calls functions from http package as they are. It wraps and modifies the input parameters, defines an implementation of some interfaces such as http.ResponseWriter, and defines a type httptest.Server which listens on in-memory network, unlike http.Server which listens on a loopback network. It makes sense in that context.
In the current implementation having oidctrusttest package does not help to incapsulate oidctrust.NewModule function. It is already publicly exported, and used as is. In my opinion, having an extra noop package as it's currently present makes the readability of the API more difficult. I think this approach would be worth it if oidctrusttest package helped to hide oidctrust.NewModule function from public API, and therefore protect it from wrong usage as the intended usage of a module is through the application lifecycle. The public oidctrust.NewModule function is a compromise and may be accepted though.
There was a problem hiding this comment.
Fair enough. Made the changes
Signed-off-by: Pawel Szelag <pablo.szel@gmail.com>
Signed-off-by: Pawel Szelag <pablo.szel@gmail.com>
Motivation
Several test packages used
//go:linknameto access the privatenewOIDCTrustModuleWithRepoconstructor inmodules/oidctrust. This required importingunsafein both the exporting and consuming files, which triggers false positives in security scanners (e.g. Checkmarx) and is generally fragile:go:linknameis a linker-level hack with no type-safety guarantees.Approach
oidctrust.NewModuleis promoted to a proper exported constructor (the types it works with,TrustRepositoryandTrustModule, were already public, so this doesn't widen the surface meaningfully). Test packages now importoidctrustand calloidctrust.NewModuledirectly.The
export.gofile and its//nolint:unusedsuppression are removed entirely.