mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-03 20:47:38 +03:00
feat: config parsing tests
This commit is contained in:
parent
e97a81a8a9
commit
8ca414e548
4 changed files with 253 additions and 0 deletions
74
app/cmd/client_test.go
Normal file
74
app/cmd/client_test.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// TestClientConfig tests the parsing of the client config
|
||||
func TestClientConfig(t *testing.T) {
|
||||
viper.SetConfigFile("client_test.yaml")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
t.Fatal("failed to read client config", err)
|
||||
}
|
||||
var config clientConfig
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
t.Fatal("failed to parse client config", err)
|
||||
}
|
||||
if !reflect.DeepEqual(config, clientConfig{
|
||||
Server: "example.com",
|
||||
Auth: "weak_ahh_password",
|
||||
TLS: struct {
|
||||
SNI string `mapstructure:"sni"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
CA string `mapstructure:"ca"`
|
||||
}{
|
||||
SNI: "another.example.com",
|
||||
Insecure: true,
|
||||
CA: "custom_ca.crt",
|
||||
},
|
||||
QUIC: struct {
|
||||
InitStreamReceiveWindow uint64 `mapstructure:"initStreamReceiveWindow"`
|
||||
MaxStreamReceiveWindow uint64 `mapstructure:"maxStreamReceiveWindow"`
|
||||
InitConnectionReceiveWindow uint64 `mapstructure:"initConnReceiveWindow"`
|
||||
MaxConnectionReceiveWindow uint64 `mapstructure:"maxConnReceiveWindow"`
|
||||
MaxIdleTimeout time.Duration `mapstructure:"maxIdleTimeout"`
|
||||
KeepAlivePeriod time.Duration `mapstructure:"keepAlivePeriod"`
|
||||
DisablePathMTUDiscovery bool `mapstructure:"disablePathMTUDiscovery"`
|
||||
}{
|
||||
InitStreamReceiveWindow: 1145141,
|
||||
MaxStreamReceiveWindow: 1145142,
|
||||
InitConnectionReceiveWindow: 1145143,
|
||||
MaxConnectionReceiveWindow: 1145144,
|
||||
MaxIdleTimeout: 10 * time.Second,
|
||||
KeepAlivePeriod: 4 * time.Second,
|
||||
DisablePathMTUDiscovery: true,
|
||||
},
|
||||
Bandwidth: struct {
|
||||
Up string `mapstructure:"up"`
|
||||
Down string `mapstructure:"down"`
|
||||
}{
|
||||
Up: "200 mbps",
|
||||
Down: "1 gbps",
|
||||
},
|
||||
FastOpen: true,
|
||||
SOCKS5: &socks5Config{
|
||||
Listen: "127.0.0.1:1080",
|
||||
Username: "anon",
|
||||
Password: "bro",
|
||||
DisableUDP: true,
|
||||
},
|
||||
HTTP: &httpConfig{
|
||||
Listen: "127.0.0.1:8080",
|
||||
Username: "qqq",
|
||||
Password: "bruh",
|
||||
Realm: "martian",
|
||||
},
|
||||
}) {
|
||||
t.Fatal("parsed client config is not equal to expected")
|
||||
}
|
||||
}
|
35
app/cmd/client_test.yaml
Normal file
35
app/cmd/client_test.yaml
Normal file
|
@ -0,0 +1,35 @@
|
|||
server: example.com
|
||||
|
||||
auth: weak_ahh_password
|
||||
|
||||
tls:
|
||||
sni: another.example.com
|
||||
insecure: true
|
||||
ca: custom_ca.crt
|
||||
|
||||
quic:
|
||||
initStreamReceiveWindow: 1145141
|
||||
maxStreamReceiveWindow: 1145142
|
||||
initConnReceiveWindow: 1145143
|
||||
maxConnReceiveWindow: 1145144
|
||||
maxIdleTimeout: 10s
|
||||
keepAlivePeriod: 4s
|
||||
disablePathMTUDiscovery: true
|
||||
|
||||
bandwidth:
|
||||
up: 200 mbps
|
||||
down: 1 gbps
|
||||
|
||||
fastOpen: true
|
||||
|
||||
socks5:
|
||||
listen: 127.0.0.1:1080
|
||||
username: anon
|
||||
password: bro
|
||||
disableUDP: true
|
||||
|
||||
http:
|
||||
listen: 127.0.0.1:8080
|
||||
username: qqq
|
||||
password: bruh
|
||||
realm: martian
|
100
app/cmd/server_test.go
Normal file
100
app/cmd/server_test.go
Normal file
|
@ -0,0 +1,100 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// TestServerConfig tests the parsing of the server config
|
||||
func TestServerConfig(t *testing.T) {
|
||||
viper.SetConfigFile("server_test.yaml")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
t.Fatal("failed to read server config", err)
|
||||
}
|
||||
var config serverConfig
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
t.Fatal("failed to parse server config", err)
|
||||
}
|
||||
if !reflect.DeepEqual(config, serverConfig{
|
||||
Listen: ":8443",
|
||||
TLS: &serverConfigTLS{
|
||||
Cert: "some.crt",
|
||||
Key: "some.key",
|
||||
},
|
||||
ACME: &serverConfigACME{
|
||||
Domains: []string{
|
||||
"sub1.example.com",
|
||||
"sub2.example.com",
|
||||
},
|
||||
Email: "haha@cringe.net",
|
||||
CA: "zero",
|
||||
DisableHTTP: true,
|
||||
DisableTLSALPN: true,
|
||||
AltHTTPPort: 9980,
|
||||
AltTLSALPNPort: 9443,
|
||||
Dir: "random_dir",
|
||||
},
|
||||
QUIC: struct {
|
||||
InitStreamReceiveWindow uint64 `mapstructure:"initStreamReceiveWindow"`
|
||||
MaxStreamReceiveWindow uint64 `mapstructure:"maxStreamReceiveWindow"`
|
||||
InitConnectionReceiveWindow uint64 `mapstructure:"initConnReceiveWindow"`
|
||||
MaxConnectionReceiveWindow uint64 `mapstructure:"maxConnReceiveWindow"`
|
||||
MaxIdleTimeout time.Duration `mapstructure:"maxIdleTimeout"`
|
||||
MaxIncomingStreams int64 `mapstructure:"maxIncomingStreams"`
|
||||
DisablePathMTUDiscovery bool `mapstructure:"disablePathMTUDiscovery"`
|
||||
}{
|
||||
InitStreamReceiveWindow: 77881,
|
||||
MaxStreamReceiveWindow: 77882,
|
||||
InitConnectionReceiveWindow: 77883,
|
||||
MaxConnectionReceiveWindow: 77884,
|
||||
MaxIdleTimeout: 999 * time.Second,
|
||||
MaxIncomingStreams: 256,
|
||||
DisablePathMTUDiscovery: true,
|
||||
},
|
||||
Bandwidth: struct {
|
||||
Up string `mapstructure:"up"`
|
||||
Down string `mapstructure:"down"`
|
||||
}{
|
||||
Up: "500 mbps",
|
||||
Down: "100 mbps",
|
||||
},
|
||||
DisableUDP: true,
|
||||
Auth: struct {
|
||||
Type string `mapstructure:"type"`
|
||||
Password string `mapstructure:"password"`
|
||||
}{
|
||||
Type: "password",
|
||||
Password: "goofy_ahh_password",
|
||||
},
|
||||
Masquerade: struct {
|
||||
Type string `mapstructure:"type"`
|
||||
File struct {
|
||||
Dir string `mapstructure:"dir"`
|
||||
} `mapstructure:"file"`
|
||||
Proxy struct {
|
||||
URL string `mapstructure:"url"`
|
||||
RewriteHost bool `mapstructure:"rewriteHost"`
|
||||
} `mapstructure:"proxy"`
|
||||
}{
|
||||
Type: "proxy",
|
||||
File: struct {
|
||||
Dir string `mapstructure:"dir"`
|
||||
}{
|
||||
Dir: "/www/masq",
|
||||
},
|
||||
Proxy: struct {
|
||||
URL string `mapstructure:"url"`
|
||||
RewriteHost bool `mapstructure:"rewriteHost"`
|
||||
}{
|
||||
URL: "https://some.site.net",
|
||||
RewriteHost: true,
|
||||
},
|
||||
},
|
||||
}) {
|
||||
t.Fatal("parsed server config is not equal to expected")
|
||||
}
|
||||
}
|
44
app/cmd/server_test.yaml
Normal file
44
app/cmd/server_test.yaml
Normal file
|
@ -0,0 +1,44 @@
|
|||
listen: :8443
|
||||
|
||||
tls:
|
||||
cert: some.crt
|
||||
key: some.key
|
||||
|
||||
acme:
|
||||
domains:
|
||||
- sub1.example.com
|
||||
- sub2.example.com
|
||||
email: haha@cringe.net
|
||||
ca: zero
|
||||
disableHTTP: true
|
||||
disableTLSALPN: true
|
||||
altHTTPPort: 9980
|
||||
altTLSALPNPort: 9443
|
||||
dir: random_dir
|
||||
|
||||
quic:
|
||||
initStreamReceiveWindow: 77881
|
||||
maxStreamReceiveWindow: 77882
|
||||
initConnReceiveWindow: 77883
|
||||
maxConnReceiveWindow: 77884
|
||||
maxIdleTimeout: 999s
|
||||
maxIncomingStreams: 256
|
||||
disablePathMTUDiscovery: true
|
||||
|
||||
bandwidth:
|
||||
up: 500 mbps
|
||||
down: 100 mbps
|
||||
|
||||
disableUDP: true
|
||||
|
||||
auth:
|
||||
type: password
|
||||
password: goofy_ahh_password
|
||||
|
||||
masquerade:
|
||||
type: proxy
|
||||
file:
|
||||
dir: /www/masq
|
||||
proxy:
|
||||
url: https://some.site.net
|
||||
rewriteHost: true
|
Loading…
Add table
Add a link
Reference in a new issue