watcher: an IPv6 address is written in brackets before its port (closes #270)
check / check (push) Canceled after 0s

Port and certificate keys were joined as address:port, so an IPv6
address ran into its port: 2a01:4f8:2200:fd11::1:80 is also an address
on its own. Keys are now joined with net.JoinHostPort and split with
net.SplitHostPort, giving [2a01:4f8:2200:fd11::1]:80 in the state file,
/api/v1/status, the dashboard and Port Change notifications; an IPv4
address is unchanged. A certificate key still splits at its last colon,
since a hostname has none. Tests that built IPv6 keys by hand now use
the bracketed form, and a test checks that an IPv6 address's
certificate entry is removed when its port 443 closes.

Model: opus-5-5
This commit was merged in pull request #282.
This commit is contained in:
2026-10-13 22:27:34 +02:00
parent 6b580a5a0f
commit aaccabad50
6 changed files with 115 additions and 20 deletions
+5 -3
View File
@@ -2,6 +2,7 @@ package watcher_test
import (
"maps"
"net"
"slices"
"strings"
"testing"
@@ -173,7 +174,7 @@ func TestCertificateStateForAnAddressGone(t *testing.T) {
"A": {ip1}, "AAAA": {ip6},
}),
}),
[]string{ip1 + ":443:" + host, ip6 + ":443:" + host},
[]string{ip1 + ":443:" + host, "[" + ip6 + "]:443:" + host},
},
{
"no nameserver answered",
@@ -183,7 +184,7 @@ func TestCertificateStateForAnAddressGone(t *testing.T) {
[]string{
ip1 + ":443:" + host,
ip2 + ":443:" + host,
ip6 + ":443:" + host,
"[" + ip6 + "]:443:" + host,
},
},
}
@@ -206,7 +207,8 @@ func TestCertificateStateForAnAddressGone(t *testing.T) {
for _, ip := range []string{ip1, ip2, ip6} {
deps.state.SetCertificateState(
ip+":443:"+host, &state.CertificateState{Status: "ok"},
net.JoinHostPort(ip, "443")+":"+host,
&state.CertificateState{Status: "ok"},
)
}