Files
masyunis/cmd/anubis/sni_test.go
T
sol_bot Bot e07de898cd Import Anubis v1.28.2
Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3).
Masyunis customizations are re-applied in the following commits.
2026-11-28 14:52:26 +03:00

40 lines
973 B
Go

package main
import (
"crypto/tls"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
)
func TestAutomaticSNI(t *testing.T) {
var mu sync.Mutex
seen := map[string]string{}
target := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mu.Lock(); seen[r.Host] = r.TLS.ServerName; mu.Unlock() }))
target.TLS = &tls.Config{}
target.StartTLS()
defer target.Close()
proxy, err := makeReverseProxy(target.URL, "auto", "", true, false)
if err != nil {
t.Fatal(err)
}
var wg sync.WaitGroup
for _, host := range []string{"first.example", "second.example", "third.example:443"} {
wg.Go(func() {
r := httptest.NewRequest("GET", "https://"+host+"/", nil)
proxy.ServeHTTP(httptest.NewRecorder(), r)
})
}
wg.Wait()
for host, sni := range seen {
if sni != strings.Split(host, ":")[0] {
t.Errorf("host %s used SNI %s", host, sni)
}
}
if len(seen) != 3 {
t.Fatalf("got %d requests", len(seen))
}
}