mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 08:41:19 -08:00
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]>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !js && !ts_omit_acme
|
|
|
|
package local
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"tailscale.com/tstest/nettest"
|
|
)
|
|
|
|
func TestCertStatusUnsupported(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
status int
|
|
wantUnsupported bool
|
|
}{
|
|
{name: "not_found", status: http.StatusNotFound, wantUnsupported: true},
|
|
{name: "server_error", status: http.StatusInternalServerError, wantUnsupported: false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
nw := nettest.GetNetwork(t)
|
|
ts := nettest.NewHTTPServer(nw, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(tt.status)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
lc := &Client{
|
|
Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
return nw.Dial(ctx, network, ts.Listener.Addr().String())
|
|
},
|
|
}
|
|
_, err := lc.CertStatus(context.Background(), "node.example.ts.net")
|
|
if err == nil {
|
|
t.Fatal("CertStatus: got nil error")
|
|
}
|
|
if got := errors.Is(err, ErrCertStatusUnsupported); got != tt.wantUnsupported {
|
|
t.Errorf("errors.Is(%v, ErrCertStatusUnsupported) = %v, want %v", err, got, tt.wantUnsupported)
|
|
}
|
|
if got := errors.Is(err, errors.ErrUnsupported); got != tt.wantUnsupported {
|
|
t.Errorf("errors.Is(%v, errors.ErrUnsupported) = %v, want %v", err, got, tt.wantUnsupported)
|
|
}
|
|
})
|
|
}
|
|
}
|