Commit c4bbd62
authored
refactor(cachetest): build fixtures via ldap.NewObject instead of unsafe (#633)
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.4 files changed
Lines changed: 48 additions & 78 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
239 | | - | |
240 | 238 | | |
241 | 239 | | |
242 | 240 | | |
243 | 241 | | |
244 | | - | |
245 | | - | |
246 | 242 | | |
247 | 243 | | |
248 | 244 | | |
| |||
420 | 416 | | |
421 | 417 | | |
422 | 418 | | |
423 | | - | |
424 | | - | |
| 419 | + | |
| 420 | + | |
425 | 421 | | |
426 | 422 | | |
427 | 423 | | |
| |||
498 | 494 | | |
499 | 495 | | |
500 | 496 | | |
501 | | - | |
502 | | - | |
| 497 | + | |
| 498 | + | |
503 | 499 | | |
504 | 500 | | |
505 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
| 2 | + | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | 7 | | |
12 | 8 | | |
13 | 9 | | |
14 | 10 | | |
15 | 11 | | |
16 | | - | |
17 | | - | |
| 12 | + | |
18 | 13 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
23 | 20 | | |
24 | 21 | | |
25 | | - | |
| 22 | + | |
26 | 23 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
| 30 | + | |
34 | 31 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
104 | 102 | | |
105 | 103 | | |
106 | 104 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
110 | 108 | | |
111 | | - | |
| 109 | + | |
112 | 110 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
143 | 135 | | |
0 commit comments