mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-04 14:58:47 +00:00
Some checks are pending
Tests / test (./cmd/caddy/caddy, ~1.26.0, macos-14, 0, 1.26, mac) (push) Waiting to run
Tests / test (./cmd/caddy/caddy, ~1.26.0, ubuntu-latest, 0, 1.26, linux) (push) Waiting to run
Tests / test (./cmd/caddy/caddy.exe, ~1.26.0, windows-latest, True, 1.26, windows) (push) Waiting to run
Tests / test (s390x on IBM Z) (push) Waiting to run
Tests / goreleaser-check (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, aix) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, darwin) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, dragonfly) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, freebsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, illumos) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, linux) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, netbsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, openbsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, solaris) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, windows) (push) Waiting to run
Lint / lint (push) Waiting to run
Lint / lint-1 (push) Waiting to run
Lint / lint-2 (push) Waiting to run
Lint / govulncheck (push) Waiting to run
Lint / dependency-review (push) Waiting to run
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
* tls: add alpn to managed HTTPS records * tls: centralise HTTPS RR ALPN defaults and registration Reuse shared protocol defaults instead of repeating the default HTTP protocol list, unify server name registration to carry ALPN in one experimental API and reuse the TLS default ALPN ordering for HTTPS RR publication * http: centralise effective protocol resolution for HTTPS RR ALPN
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package caddytls
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"reflect"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/libdns/libdns"
|
|
)
|
|
|
|
func TestRegisterServerNamesWithALPN(t *testing.T) {
|
|
tlsApp := &TLS{
|
|
serverNames: make(map[string]serverNameRegistration),
|
|
serverNamesMu: new(sync.Mutex),
|
|
}
|
|
|
|
tlsApp.RegisterServerNames([]string{
|
|
"Example.com:443",
|
|
"example.com",
|
|
"127.0.0.1:443",
|
|
}, []string{"h2", "http/1.1"})
|
|
tlsApp.RegisterServerNames([]string{"EXAMPLE.COM"}, []string{"h3"})
|
|
|
|
got := tlsApp.alpnValuesForServerNames([]string{"example.com:443", "127.0.0.1:443"})
|
|
want := map[string][]string{
|
|
"example.com": {"h3", "h2", "http/1.1"},
|
|
}
|
|
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("unexpected ALPN values: got %#v want %#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestECHDNSPublisherPublishedSvcParams(t *testing.T) {
|
|
dnsPub := &ECHDNSPublisher{
|
|
alpnByDomain: map[string][]string{
|
|
"example.com": {"h3", "h2", "http/1.1"},
|
|
},
|
|
}
|
|
|
|
existing := libdns.SvcParams{
|
|
"alpn": {"h2"},
|
|
"ipv4hint": {"203.0.113.10"},
|
|
}
|
|
|
|
got := dnsPub.publishedSvcParams("Example.com", existing, []byte{0x01, 0x02, 0x03})
|
|
|
|
if !reflect.DeepEqual(existing["alpn"], []string{"h2"}) {
|
|
t.Fatalf("existing params mutated: got %v", existing["alpn"])
|
|
}
|
|
|
|
if !reflect.DeepEqual(got["alpn"], []string{"h3", "h2", "http/1.1"}) {
|
|
t.Fatalf("unexpected ALPN params: got %v", got["alpn"])
|
|
}
|
|
|
|
if !reflect.DeepEqual(got["ipv4hint"], []string{"203.0.113.10"}) {
|
|
t.Fatalf("unexpected preserved params: got %v", got["ipv4hint"])
|
|
}
|
|
|
|
wantECH := base64.StdEncoding.EncodeToString([]byte{0x01, 0x02, 0x03})
|
|
if !reflect.DeepEqual(got["ech"], []string{wantECH}) {
|
|
t.Fatalf("unexpected ECH params: got %v want %v", got["ech"], wantECH)
|
|
}
|
|
}
|