Files

24 lines
811 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import "testing"
func TestDevLoopbackGuard(t *testing.T) {
// --dev 强制 loopback(§7.3-8)
if _, err := ParseStart([]string{"--dev", "--addr", ":8080"}); err == nil {
t.Error("--dev + 0.0.0.0 应拒绝启动")
}
if _, err := ParseStart([]string{"--dev", "--addr", "192.168.1.5:8080"}); err == nil {
t.Error("--dev + 局域网地址应拒绝启动")
}
if _, err := ParseStart([]string{"--dev", "--addr", "127.0.0.1:8080"}); err != nil {
t.Errorf("--dev + 127.0.0.1 应允许: %v", err)
}
if _, err := ParseStart([]string{"--dev", "--addr", "localhost:8080"}); err != nil {
t.Errorf("--dev + localhost 应允许: %v", err)
}
// 非 dev 不限制
if _, err := ParseStart([]string{"--addr", ":8080"}); err != nil {
t.Errorf("非 dev 任意地址应允许: %v", err)
}
}