Reject validator changes to secret classification
This commit is contained in:
@@ -226,3 +226,25 @@ func TestDynamicConcreteTagsRemainSecretThroughHistory(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorCannotChangeDynamicSensitivityWithoutChangingText(t *testing.T) {
|
||||
type sensitive struct {
|
||||
Token string `yaml:"token" configkit:"secret"`
|
||||
}
|
||||
type cfg struct {
|
||||
Payload any `yaml:"payload"`
|
||||
}
|
||||
_, err := Load(Bytes("base", []byte("payload: {token: disposable}\n")), Options[cfg]{Definition: Definition[cfg]{Validate: func(c *cfg, v *Validation) {
|
||||
c.Payload = sensitive{Token: c.Payload.(map[string]any)["token"].(string)}
|
||||
}}})
|
||||
var failure *LoadError
|
||||
if !errors.As(err, &failure) {
|
||||
t.Fatal("validator changed inspection sensitivity without a mutation error")
|
||||
}
|
||||
for _, d := range failure.Diagnostics() {
|
||||
if d.Code == CodeValidateMutation {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatal("missing validation mutation diagnostic")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user