From 6d04ba8c89b1c48de205724f3f8dc7f7ced5c7ee Mon Sep 17 00:00:00 2001 From: xuans Date: Mon, 31 Aug 2026 01:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E8=AF=81=E4=B9=A6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=94=99=E8=AF=AF=E8=84=B1=E6=95=8F=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/httpapi/certificate_api_test.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/backend/internal/httpapi/certificate_api_test.go b/backend/internal/httpapi/certificate_api_test.go index 4075dd4..cd2b06c 100644 --- a/backend/internal/httpapi/certificate_api_test.go +++ b/backend/internal/httpapi/certificate_api_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "mime/multipart" "net/http" "net/http/httptest" @@ -68,6 +69,36 @@ func TestCertificateReadAPIs(t *testing.T) { } } +func TestCertificateListHidesReaderErrors(t *testing.T) { + reader := certificateReaderStub{err: errors.New("private-key-secret-path")} + repo := &stubDomainRepository{ + items: []domain.Domain{{ID: "domain-1", Name: "example.com"}}, + } + server := New(Dependencies{ + Config: readyTestConfig(t.TempDir()), + Repository: repo, + CurrentCertificate: reader, + }) + + response := httptest.NewRecorder() + serveAdminHTTP( + server, + response, + httptest.NewRequest(http.MethodGet, "/api/v1/certificates", nil), + ) + + if response.Code != http.StatusOK { + t.Fatalf("certificate list request failed: %d %s", response.Code, response.Body.String()) + } + + body := response.Body.String() + if strings.Contains(body, "private-key-secret-path") { + t.Fatalf("certificate list leaked an internal error: %s", body) + } + if !strings.Contains(body, "\u5f53\u524d\u8bc1\u4e66\u4e0d\u53ef\u7528") { + t.Fatalf("certificate list did not include the safe error message: %s", body) + } +} func TestCertificateImportAPIAcceptsMultipartFiles(t *testing.T) { var received certificate.ImportRequest importer := func(_ context.Context, request certificate.ImportRequest) (certificate.IssueResult, deployment.Report, error) {