First commit Go counter service

This commit is contained in:
Dimitrije Dimitrijevic
2026-10-15 02:12:18 +02:00
commit c43ff17627
59 changed files with 11205 additions and 0 deletions
@@ -0,0 +1,45 @@
package config
import (
"os"
"path/filepath"
"testing"
)
func TestReviewB_MisconfigStarts(t *testing.T) {
dir := t.TempDir()
for name, body := range map[string]string{
"typo token, open API": `auth-token = "s3cret"
domains_cdb = "x.cdb"
allowed_cidr = ["10.0.0.0/8"]
[redis]
write_addr = "127.0.0.1:6379"`,
"sentinel without password": `auth_token = "t"
domains_cdb = "x.cdb"
[redis]
master_name = "mymaster"
sentinels = ["10.0.0.10:26379"]`,
"notify creds in URL / http basic": `auth_token = "t"
domains_cdb = "x.cdb"
[redis]
write_addr = "127.0.0.1:6379"
[notify]
org_url = "http://admin:hunter2@admin.migadu.com/api/limits?level=$LEVEL&id=$ID&flow=$FLOW&period=$PERIOD&by=$ADDRESS&count=$COUNT"
user = "u"
password = "p"`,
"public admin": `auth_token = "t"
domains_cdb = "x.cdb"
admin_addr = "0.0.0.0:9095"
[redis]
write_addr = "127.0.0.1:6379"`,
} {
p := filepath.Join(dir, "c.toml")
os.WriteFile(p, []byte(body), 0o600)
cfg, err := Load(p)
if err != nil {
t.Logf("%s: Load error: %v", name, err)
continue
}
t.Logf("%s: Load OK; AuthToken=%q prefixes=%v redis.password=%q warnings=%q", name, cfg.AuthToken, cfg.AllowedPrefixes(), cfg.Redis.Password, cfg.Warnings())
}
}