Refactor certificate output parsing and add unit tests for parseCertOutput function

This commit is contained in:
2026-07-11 23:25:47 +00:00
parent 5d8fe6a754
commit ff6d6bbd0b
3 changed files with 61 additions and 5 deletions

View File

@@ -126,7 +126,15 @@ func (m *Manager) GetStatus(domain string) *CertStatus {
return status
}
for line := range strings.SplitSeq(string(out), "\n") {
parseCertOutput(string(out), status)
return status
}
// parseCertOutput parses the output of `openssl x509 -noout -enddate -issuer -subject`
// and populates the given CertStatus.
func parseCertOutput(output string, status *CertStatus) {
for line := range strings.SplitSeq(output, "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "notAfter=") {
dateStr := strings.TrimPrefix(line, "notAfter=")
@@ -142,13 +150,11 @@ func (m *Manager) GetStatus(domain string) *CertStatus {
status.IssuerCN = strings.TrimPrefix(line, "issuer=")
}
if strings.HasPrefix(line, "subject=") {
if strings.Contains(line, "CN = *.") {
if strings.Contains(line, "CN=*.") || strings.Contains(line, "CN = *.") {
status.Wildcard = true
}
}
}
return status
}
// CertPath returns the fullchain.pem path for a domain.