fix({simplequic,tls}ping): default SNI to URL's hostname (#753)

See https://github.com/ooni/probe/issues/2111
This commit is contained in:
Simone Basso 2022-05-24 16:29:13 +02:00 committed by GitHub
commit b68b8e1e8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 8 deletions

View file

@ -186,3 +186,51 @@ func generateTLSConfig() *tls.Config {
NextProtos: []string{"quic-echo-example"},
}
}
func TestConfig_sni(t *testing.T) {
type fields struct {
SNI string
}
type args struct {
address string
}
tests := []struct {
name string
fields fields
args args
want string
}{{
name: "with config.SNI being set",
fields: fields{
SNI: "x.org",
},
args: args{
address: "google.com:443",
},
want: "x.org",
}, {
name: "with invalid endpoint",
fields: fields{},
args: args{
address: "google.com",
},
want: "",
}, {
name: "with valid endpoint",
fields: fields{},
args: args{
address: "google.com:443",
},
want: "google.com",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Config{
SNI: tt.fields.SNI,
}
if got := c.sni(tt.args.address); got != tt.want {
t.Fatalf("Config.sni() = %v, want %v", got, tt.want)
}
})
}
}