test(mtproto): cover single-backend DC aliases

Follow up gramsrv PR #17 with boundary coverage and public configuration docs.

Canonical-Telesrv: b4df3e72c24470e4ce09e5fc1d46e0c2944f6d3e

Reviewed-Head: e7eb07b9eb

Co-authored-by: onysd <beatvin128@gmail.com>
This commit is contained in:
iamxvbaba 2026-07-24 23:17:32 +08:00
parent 5dcdb57e4c
commit 9ef746d45e
8 changed files with 127 additions and 69 deletions

View file

@ -31,12 +31,10 @@ type Config struct {
RSAKeyPath string
// DC 是本 server 的 DC ID。
DC int
// StrictDCCheck turns on exact DC-ID validation for the permanent-key
// exchange (default off = lenient). See mtprotoedge.Options.StrictDC doc
// for the full rationale: telesrv is always a single physical backend, but
// many client forks alias dc_id 1..5 to it, so a mismatched client-chosen
// dc_id is expected, not an attack — strict mode exists only for a
// hypothetical future real multi-DC deployment.
// StrictDCCheck enables the default-off key-exchange DC-label diagnostic.
// The normal single-backend mode accepts every wire int32 label without
// partitioning auth keys, sessions, or business state. See
// mtprotoedge.Options.StrictDC for the optional strict behavior.
StrictDCCheck bool
// MTProtoMaxConnections / PerIP 覆盖 raw Accept、codec sniff、握手到认证 session
// 的完整物理连接生命周期;负数关闭对应 admission 上限。

View file

@ -49,6 +49,34 @@ func TestLoadUsesExplicitAdvertiseIP(t *testing.T) {
}
}
func TestLoadStrictDCCheck(t *testing.T) {
t.Run("defaults off", func(t *testing.T) {
disableDefaultConfigFile(t)
t.Setenv("TELESRV_STRICT_DC_CHECK", "")
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if cfg.StrictDCCheck {
t.Fatal("StrictDCCheck = true, want default false")
}
})
t.Run("explicitly enabled", func(t *testing.T) {
disableDefaultConfigFile(t)
t.Setenv("TELESRV_STRICT_DC_CHECK", "true")
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if !cfg.StrictDCCheck {
t.Fatal("StrictDCCheck = false, want true")
}
})
}
func TestLoadMTProtoAdmissionAndRPCBudgets(t *testing.T) {
disableDefaultConfigFile(t)
t.Setenv("TELESRV_MTPROTO_MAX_CONNECTIONS", "12345")