Files
tailscale/ipn/ipnlocal/cert_test.go
chaosinthecrd 408f0d2b36 ipn,feature/acme,client/local: add tests for the cert-status localapi endpoint
Tests that the localapi cert-status/ handler checks read access and returns
the status as JSON, that LocalBackend.CertStatus goes through the hook, and
that feature/acme's hook reports the same missing, valid and expired results
as the C2N /tls-cert-status handler. Also tests that Client.CertStatus
returns ErrCertStatusUnsupported for a 404 and not for other errors.

Updates tailscale/corp#38175

Signed-off-by: chaosinthecrd <[email protected]>
2026-11-10 17:37:53 +00:00

40 lines
1015 B
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package ipnlocal
import (
"errors"
"testing"
"tailscale.com/tailcfg"
)
func TestCertStatus(t *testing.T) {
b := &LocalBackend{}
if _, err := b.CertStatus("node.example.ts.net"); !errors.Is(err, errNoCerts) {
t.Fatalf("CertStatus without ACME support: err = %v, want %v", err, errNoCerts)
}
want := &tailcfg.C2NTLSCertInfo{Missing: true, Error: "no certificate"}
var gotDomain string
t.Cleanup(HookCertStatus.SetForTest(func(hb *LocalBackend, domain string) (*tailcfg.C2NTLSCertInfo, error) {
if hb != b {
t.Errorf("hook called with a different LocalBackend")
}
gotDomain = domain
return want, nil
}))
got, err := b.CertStatus("node.example.ts.net")
if err != nil {
t.Fatalf("CertStatus: %v", err)
}
if got != want {
t.Errorf("CertStatus = %+v, want %+v", got, want)
}
if gotDomain != "node.example.ts.net" {
t.Errorf("hook got domain %q, want %q", gotDomain, "node.example.ts.net")
}
}