Repository navigation
test(compose): fuzz envResolverWithCase resolution semantics - #14388
TDnorthgarden wants to merge 1 commit into
Conversation
Lock the resolution invariants under Go native fuzzing: the resolver is exactly the map when case-sensitive, an exact match wins over the lower-cased fallback when case-insensitive, and a nil environment never resolves. 128k executions over the corpus found no violation. Signed-off-by: Aucoto <tdnorthgarden@gmail.com>
| // keep the two keys distinct after case folding so the lower-cased | ||
| // fallback has a single unambiguous winner | ||
| if strings.EqualFold(k1, k2) { | ||
| k2 += "#" | ||
| } | ||
| environment := map[string]string{k1: v1, k2: v2} |
There was a problem hiding this comment.
This looks to be explicitly avoiding an ... actually problematic case in the implementation; the implementation handles uppercase and lowercase correctly, but mixed case will be randomised; given, e.g.;
env := map[string]string{
"FOO": "upper",
"foo": "lower",
"Foo": "mixed",
}A direct match (on either FOO or foo, or Foo) will return a deterministic value, but a case-insensitive match will be randomised (return either upper, lower, or mixed), depending on how the Go runtime randomises the map.
The code also unconditionally allocates a new map, regardless if a direct match was found;
compose/pkg/compose/envresolver.go
Lines 49 to 65 in e18ab3d
(So given that it already loops over values, it may as well just loop over values, and do a case-insensitive (try match exact UPPER or lower first, then fallback to Equalfold if desired) only if a direct match wasn't found.
thaJeztah
left a comment
There was a problem hiding this comment.
Not sure if the fuzz-test adds much here; at least, at a glance, I don't see much that's added that cannot be added through additional cases in the existing table-test 🤔
|
Fair point — the EqualFold normalization in the corpus was dodging the very behavior worth exercising, and the invariants it pinned are just table-test cases. Closing this one. |
Add a Go native fuzz target locking the
envResolverWithCaseresolutionsemantics:
lower-cased fallback;
128k executions over the corpus found no violation.