controller (unreleased): only certificates of the household's current domain are reported (review)
gates / gates (push) Successful in 38s
gates / gates (push) Successful in 38s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
7daf3d24a7
commit
ee3b05edd0
3 files changed
+38
-7
No files matched your search
@@ -25,7 +25,7 @@ import (
|
||||
// field, not the report. (The reader itself, and that it returns no key material: infra TestReadWebCerts_*.)
|
||||
func TestWebCertsForReport_PathFieldAndBrokenStore(t *testing.T) {
|
||||
stacks := t.TempDir()
|
||||
if got := webCertsForReport(stacks, nil); got != nil {
|
||||
if got := webCertsForReport(stacks, "", nil); got != nil {
|
||||
t.Fatalf("no store: %+v", got)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(stacks, "traefik"), 0o755); err != nil {
|
||||
@@ -33,11 +33,11 @@ func TestWebCertsForReport_PathFieldAndBrokenStore(t *testing.T) {
|
||||
}
|
||||
store := filepath.Join(stacks, "traefik", "acme.json")
|
||||
_ = os.WriteFile(store, []byte("{broken"), 0o600)
|
||||
if got := webCertsForReport(stacks, nil); got != nil {
|
||||
if got := webCertsForReport(stacks, "", nil); got != nil {
|
||||
t.Fatalf("a broken store: %+v, want nil (and no panic with a nil logger)", got)
|
||||
}
|
||||
_ = os.WriteFile(store, []byte(`{"letsencrypt":{"Certificates":[]}}`), 0o600)
|
||||
r := &Report{WebCerts: webCertsForReport(stacks, nil)}
|
||||
r := &Report{WebCerts: webCertsForReport(stacks, "", nil)}
|
||||
wire, _ := json.Marshal(r)
|
||||
if strings.Contains(string(wire), "web_certs") {
|
||||
t.Fatalf("a box with no certificate must omit the field: %s", wire)
|
||||
@@ -45,7 +45,7 @@ func TestWebCertsForReport_PathFieldAndBrokenStore(t *testing.T) {
|
||||
// a real certificate in Traefik's folder is read; one in ANOTHER folder (the stacks folder itself) is not
|
||||
_ = os.WriteFile(store, testACMEStore(t, "*.example.hu", time.Date(2027, 1, 19, 1, 46, 0, 0, time.UTC)), 0o600)
|
||||
_ = os.WriteFile(filepath.Join(stacks, "acme.json"), testACMEStore(t, "decoy.example.hu", time.Date(2026, 12, 1, 0, 0, 0, 0, time.UTC)), 0o600)
|
||||
got := webCertsForReport(stacks, nil)
|
||||
got := webCertsForReport(stacks, "", nil)
|
||||
if len(got) != 1 || got[0].Domain != "*.example.hu" || got[0].NotAfter != "2027-01-19T01:46:00Z" {
|
||||
t.Fatalf("certificates read for the report = %+v, want the one in <stacks>/traefik/acme.json", got)
|
||||
}
|
||||
@@ -53,6 +53,17 @@ func TestWebCertsForReport_PathFieldAndBrokenStore(t *testing.T) {
|
||||
if !strings.Contains(string(wire), `"web_certs":[{"domain":"*.example.hu","not_after":"2027-01-19T01:46:00Z"`) {
|
||||
t.Fatalf("the field on the wire: %s", wire)
|
||||
}
|
||||
// only the household's CURRENT domain: a certificate the store still holds for a name the box no longer serves
|
||||
// (it can never renew) is not reported — the operator would be warned about a name nobody uses
|
||||
if got := webCertsForReport(stacks, "Example.hu", nil); len(got) != 1 || got[0].Domain != "*.example.hu" {
|
||||
t.Fatalf("the household's own domain: %+v", got)
|
||||
}
|
||||
if got := webCertsForReport(stacks, "other.hu", nil); len(got) != 0 {
|
||||
t.Fatalf("a certificate for ANOTHER domain was reported: %+v", got)
|
||||
}
|
||||
if got := webCertsForReport(stacks, "ample.hu", nil); len(got) != 0 {
|
||||
t.Fatalf("a domain that only ENDS the same way matched: %+v", got)
|
||||
}
|
||||
// BuildReport is what fills it (a helper nobody calls is the inert-seam defect)
|
||||
f, err := parser.ParseFile(token.NewFileSet(), "builder.go", nil, 0)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user