fix(config): reject non-positive integer settings (#102)
Some checks are pending
CI / build (push) Waiting to run
deploy / deploy (push) Waiting to run
test / test (push) Waiting to run

This commit is contained in:
RissRIce 2026-07-30 19:41:57 -06:00 committed by GitHub
parent 1849a25f10
commit 20cdb6432d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View file

@ -99,10 +99,10 @@ func env(k, def string) string {
return def
}
// envInt reads an integer environment variable, falling back to def.
// envInt reads a positive integer environment variable, falling back to def.
func envInt(k string, def int) int {
if v := os.Getenv(k); v != "" {
if n, err := strconv.Atoi(v); err == nil {
if n, err := strconv.Atoi(v); err == nil && n > 0 {
return n
}
}

View file

@ -2,6 +2,22 @@ package main
import "testing"
func TestEnvIntRequiresPositiveValue(t *testing.T) {
const key = "AGENTBBS_TEST_POSITIVE_INT"
for _, value := range []string{"", "invalid", "0", "-1"} {
t.Setenv(key, value)
if got := envInt(key, 15); got != 15 {
t.Errorf("envInt(%q, 15) with %q = %d, want 15", key, value, got)
}
}
t.Setenv(key, "30")
if got := envInt(key, 15); got != 30 {
t.Errorf("envInt(%q, 15) = %d, want 30", key, got)
}
}
func TestValidIRCServerPortRange(t *testing.T) {
for _, server := range []string{
"irc.example.com",