-
Notifications
You must be signed in to change notification settings - Fork 20
fix: move validateTrustedBots to validation.go and enforce on stdin path #2217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -365,10 +365,32 @@ func validateGatewayConfig(gateway *StdinGatewayConfig) error { | |||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Validate trustedBots per spec §4.1.3.4: must be non-empty array when present | ||||||||||||||||||||||||||||||||||||||||||
| if err := validateTrustedBots(gateway.TrustedBots); err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| logValidation.Print("Gateway config validation passed") | ||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // validateTrustedBots checks that the trusted_bots/trustedBots list conforms to spec §4.1.3.4: | ||||||||||||||||||||||||||||||||||||||||||
| // when present, it must be a non-empty array of non-empty strings. | ||||||||||||||||||||||||||||||||||||||||||
| func validateTrustedBots(bots []string) error { | ||||||||||||||||||||||||||||||||||||||||||
| if bots == nil { | ||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if len(bots) == 0 { | ||||||||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("trusted_bots must be a non-empty array when present (spec §4.1.3.4)") | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| for i, bot := range bots { | ||||||||||||||||||||||||||||||||||||||||||
| if strings.TrimSpace(bot) == "" { | ||||||||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("trusted_bots[%d] must be a non-empty string", i) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+384
to
+388
|
||||||||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("trusted_bots must be a non-empty array when present (spec §4.1.3.4)") | |
| } | |
| for i, bot := range bots { | |
| if strings.TrimSpace(bot) == "" { | |
| return fmt.Errorf("trusted_bots[%d] must be a non-empty string", i) | |
| return rules.InvalidValue( | |
| "trusted_bots", | |
| "gateway.trustedBots", | |
| "trusted_bots must be a non-empty array when present (spec §4.1.3.4)", | |
| "Remove the trusted_bots setting or provide at least one non-empty trusted bot identifier.", | |
| ) | |
| } | |
| for i, bot := range bots { | |
| if strings.TrimSpace(bot) == "" { | |
| return rules.InvalidValue( | |
| "trusted_bots", | |
| fmt.Sprintf("gateway.trustedBots[%d]", i), | |
| "trusted_bots entries must be non-empty strings", | |
| "Remove empty entries from trusted_bots or replace them with valid trusted bot identifiers.", | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateGatewayConfig now enforces the trustedBots constraint, but TestValidateGatewayConfig in validation_test.go doesn’t cover the new cases (empty slice, whitespace-only entries). Adding focused unit cases there would prevent regressions even if JSON schema behavior changes and would directly exercise the new validation branch.