Skip to content

Commit f963d3c

Browse files
authored
fix: keep test scaffolding out of the binary and bump the toolchain (#254)
gosec became blocking in the shared workflow ([netresearch/.github#312](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
2 parents 8c29c3c + c5a6da4 commit f963d3c

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module raybeam
22

3-
go 1.25.1
3+
go 1.26
4+
5+
toolchain go1.26.5
46

57
require (
68
github.com/go-ldap/ldap/v3 v3.4.14

internal/server/ldap_client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package server
2+
3+
import (
4+
ldap "github.com/netresearch/simple-ldap-go"
5+
)
6+
7+
// LDAPClient interface defines the LDAP operations needed by the server.
8+
// This interface allows for mock implementations in tests.
9+
type LDAPClient interface {
10+
FindUserBySAMAccountName(sAMAccountName string) (*ldap.User, error)
11+
FindUsersBySAMAccountNames(sAMAccountNames []string) ([]*ldap.User, error)
12+
CheckPasswordForSAMAccountName(sAMAccountName, password string) (*ldap.User, error)
13+
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ import (
1111
"go.etcd.io/bbolt"
1212
)
1313

14-
// LDAPClient interface defines the LDAP operations needed by the server.
15-
// This interface allows for mock implementations in tests.
16-
type LDAPClient interface {
17-
FindUserBySAMAccountName(sAMAccountName string) (*ldap.User, error)
18-
FindUsersBySAMAccountNames(sAMAccountNames []string) ([]*ldap.User, error)
19-
CheckPasswordForSAMAccountName(sAMAccountName, password string) (*ldap.User, error)
20-
}
21-
2214
// MockLDAP implements LDAPClient for testing.
2315
type MockLDAP struct {
2416
users map[string]*ldap.User
2517
password string // single password for all test users
2618
}
2719

2820
// setObjectDN uses reflection to set the DN field in an ldap.Object (which has unexported fields).
21+
//
22+
// simple-ldap-go exposes no constructor that takes a DN — Object.dn is written
23+
// only by objectFromEntry when decoding a directory response — so a fixture
24+
// cannot be built through the public API. This lives in a _test.go file so the
25+
// unsafe write is compiled into the test binary only.
2926
func setObjectDN(obj interface{}, dn string) {
3027
// Get the reflect.Value of the object
3128
v := reflect.ValueOf(obj).Elem()

0 commit comments

Comments
 (0)