@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
go 65 lines 1.66 KB
Raw
1 package caddytls
2
3 import (
4 "encoding/base64"
5 "reflect"
6 "sync"
7 "testing"
8
9 "github.com/libdns/libdns"
10 )
11
12 func TestRegisterServerNamesWithALPN(t *testing.T) {
13 tlsApp := &TLS{
14 serverNames: make(map[string]serverNameRegistration),
15 serverNamesMu: new(sync.Mutex),
16 }
17
18 tlsApp.RegisterServerNames([]string{
19 "Example.com:443",
20 "example.com",
21 "127.0.0.1:443",
22 }, []string{"h2", "http/1.1"})
23 tlsApp.RegisterServerNames([]string{"EXAMPLE.COM"}, []string{"h3"})
24
25 got := tlsApp.alpnValuesForServerNames([]string{"example.com:443", "127.0.0.1:443"})
26 want := map[string][]string{
27 "example.com": {"h3", "h2", "http/1.1"},
28 }
29
30 if !reflect.DeepEqual(got, want) {
31 t.Fatalf("unexpected ALPN values: got %#v want %#v", got, want)
32 }
33 }
34
35 func TestECHDNSPublisherPublishedSvcParams(t *testing.T) {
36 dnsPub := &ECHDNSPublisher{
37 alpnByDomain: map[string][]string{
38 "example.com": {"h3", "h2", "http/1.1"},
39 },
40 }
41
42 existing := libdns.SvcParams{
43 "alpn": {"h2"},
44 "ipv4hint": {"203.0.113.10"},
45 }
46
47 got := dnsPub.publishedSvcParams("Example.com", existing, []byte{0x01, 0x02, 0x03})
48
49 if !reflect.DeepEqual(existing["alpn"], []string{"h2"}) {
50 t.Fatalf("existing params mutated: got %v", existing["alpn"])
51 }
52
53 if !reflect.DeepEqual(got["alpn"], []string{"h3", "h2", "http/1.1"}) {
54 t.Fatalf("unexpected ALPN params: got %v", got["alpn"])
55 }
56
57 if !reflect.DeepEqual(got["ipv4hint"], []string{"203.0.113.10"}) {
58 t.Fatalf("unexpected preserved params: got %v", got["ipv4hint"])
59 }
60
61 wantECH := base64.StdEncoding.EncodeToString([]byte{0x01, 0x02, 0x03})
62 if !reflect.DeepEqual(got["ech"], []string{wantECH}) {
63 t.Fatalf("unexpected ECH params: got %v want %v", got["ech"], wantECH)
64 }
65 }