Fix some lint and vet issues

This commit is contained in:
Pim van Pelt
2025-08-28 21:17:37 +02:00
parent 7b3639ad69
commit 105a245239
10 changed files with 47 additions and 41 deletions

View File

@@ -9,7 +9,7 @@ import (
func TestGenerateEnv(t *testing.T) {
tmpDir := t.TempDir()
// Create test directories
testLogDir := filepath.Join(tmpDir, "test-log")
testLog2Dir := filepath.Join(tmpDir, "test-log-2")
@@ -25,11 +25,11 @@ func TestGenerateEnv(t *testing.T) {
// Create test roots files
rootsFile := filepath.Join(tmpDir, "roots.pem")
extraRootsFile := filepath.Join(tmpDir, "extra-roots.pem")
rootsContent := `-----BEGIN CERTIFICATE-----
MIIBkTCB+wIJAKZJ...
-----END CERTIFICATE-----`
extraRootsContent := `-----BEGIN CERTIFICATE-----
MIIBkTCB+wIJAKZK...
-----END CERTIFICATE-----`
@@ -80,7 +80,7 @@ logs:
}
envStr := string(envContent)
// Check TESSERACT_ARGS contains expected values
if !strings.Contains(envStr, "TESSERACT_ARGS=") {
t.Error("Expected TESSERACT_ARGS in .env file")
@@ -199,7 +199,7 @@ func TestCreateCombinedRootsPemWithStatus(t *testing.T) {
func TestGenerateEnvMissingDirectory(t *testing.T) {
tmpDir := t.TempDir()
// Create config with non-existent directory
configContent := `logs:
- shortname: "test-log"
@@ -216,4 +216,4 @@ func TestGenerateEnvMissingDirectory(t *testing.T) {
// Should call log.Fatalf which exits the program
// We can't easily test this without subprocess, so we'll skip it
t.Skip("Cannot easily test log.Fatalf without subprocess")
}
}

View File

@@ -95,6 +95,7 @@ const htmlTemplate = `<!DOCTYPE html>
</html>
`
// LogV3JSON represents the Certificate Transparency log v3 JSON metadata format
type LogV3JSON struct {
Description string `json:"description"`
SubmissionURL string `json:"submission_url"`
@@ -105,6 +106,7 @@ type LogV3JSON struct {
MMD int `json:"mmd"`
}
// TemporalInterval represents the time range for a Certificate Transparency log
type TemporalInterval struct {
StartInclusive string `json:"start_inclusive"`
EndExclusive string `json:"end_exclusive"`

View File

@@ -16,7 +16,7 @@ import (
func TestGenerateHTML(t *testing.T) {
tmpDir := t.TempDir()
// Create test directories
testLogDir := filepath.Join(tmpDir, "test-log")
err := os.MkdirAll(testLogDir, 0755)
@@ -75,7 +75,7 @@ logs:
}
htmlStr := string(htmlContent)
// Check HTML contains expected elements
if !strings.Contains(htmlStr, "<!DOCTYPE html>") {
t.Error("Expected HTML doctype")
@@ -246,13 +246,13 @@ func TestGenerateLogJSONWithStatus(t *testing.T) {
testTime2, _ := time.Parse("2006-01-02T15:04:05Z", "2025-01-01T00:00:00Z")
logEntry := Log{
Origin: "test.example.com",
SubmissionPrefix: "https://test.example.com/submit",
MonitoringPrefix: "https://test.example.com/monitor",
NotAfterStart: testTime1,
NotAfterLimit: testTime2,
LogID: "dGVzdC1sb2ctaWQ=", // base64 encoded "test-log-id"
PublicKeyBase64: "dGVzdC1wdWJsaWMta2V5", // base64 encoded "test-public-key"
Origin: "test.example.com",
SubmissionPrefix: "https://test.example.com/submit",
MonitoringPrefix: "https://test.example.com/monitor",
NotAfterStart: testTime1,
NotAfterLimit: testTime2,
LogID: "dGVzdC1sb2ctaWQ=", // base64 encoded "test-log-id"
PublicKeyBase64: "dGVzdC1wdWJsaWMta2V5", // base64 encoded "test-public-key"
}
err := generateLogJSONWithStatus(logEntry, outputFile, false, true, false)
@@ -295,7 +295,7 @@ func TestGenerateLogJSONWithStatus(t *testing.T) {
func TestGenerateHTMLMissingDirectory(t *testing.T) {
tmpDir := t.TempDir()
// Create config with non-existent directory
configContent := `logs:
- shortname: "test-log"
@@ -313,4 +313,4 @@ func TestGenerateHTMLMissingDirectory(t *testing.T) {
// Should call log.Fatalf which exits the program
// We can't easily test this without subprocess, so we'll skip it
t.Skip("Cannot easily test log.Fatalf without subprocess")
}
}

View File

@@ -12,7 +12,7 @@ import (
func TestGenerateKeys(t *testing.T) {
tmpDir := t.TempDir()
// Create test directories
keyDir := filepath.Join(tmpDir, "keys")
err := os.MkdirAll(keyDir, 0755)
@@ -23,7 +23,7 @@ func TestGenerateKeys(t *testing.T) {
// Create test config
key1Path := filepath.Join(keyDir, "test-log-1.key")
key2Path := filepath.Join(keyDir, "test-log-2.key")
configContent := `logs:
- shortname: "test-log-1"
secret: "` + key1Path + `"
@@ -84,7 +84,7 @@ func TestGenerateKeys(t *testing.T) {
if err != nil {
t.Fatal(err)
}
perm := info.Mode().Perm()
expected := os.FileMode(0600)
if perm != expected {
@@ -94,13 +94,13 @@ func TestGenerateKeys(t *testing.T) {
func TestGenerateKeysExistingKey(t *testing.T) {
tmpDir := t.TempDir()
// Create existing key file
keyPath := filepath.Join(tmpDir, "existing.key")
existingContent := `-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIExistingKeyContent
-----END EC PRIVATE KEY-----`
err := os.WriteFile(keyPath, []byte(existingContent), 0600)
if err != nil {
t.Fatal(err)
@@ -133,9 +133,9 @@ MHcCAQEEIExistingKeyContent
func TestGenerateKeysWithoutWriteFlag(t *testing.T) {
tmpDir := t.TempDir()
keyPath := filepath.Join(tmpDir, "test.key")
configContent := `logs:
- shortname: "test-log"
secret: "` + keyPath + `"`
@@ -157,11 +157,11 @@ func TestGenerateKeysWithoutWriteFlag(t *testing.T) {
func TestGenerateKeysCreateDirectory(t *testing.T) {
tmpDir := t.TempDir()
// Key path with non-existent directory
keyDir := filepath.Join(tmpDir, "subdir", "keys")
keyPath := filepath.Join(keyDir, "test.key")
configContent := `logs:
- shortname: "test-log"
secret: "` + keyPath + `"`
@@ -188,10 +188,10 @@ func TestGenerateKeysCreateDirectory(t *testing.T) {
func TestGenerateKeysMultipleRuns(t *testing.T) {
tmpDir := t.TempDir()
key1Path := filepath.Join(tmpDir, "key1.key")
key2Path := filepath.Join(tmpDir, "key2.key")
configContent := `logs:
- shortname: "test-log-1"
secret: "` + key1Path + `"
@@ -244,7 +244,7 @@ func TestGenerateKeysMultipleRuns(t *testing.T) {
func TestECKeyGeneration(t *testing.T) {
tmpDir := t.TempDir()
keyPath := filepath.Join(tmpDir, "test.key")
configContent := `logs:
- shortname: "test-log"
secret: "` + keyPath + `"`
@@ -293,4 +293,4 @@ func TestECKeyGeneration(t *testing.T) {
if err != nil {
t.Errorf("Failed to marshal public key: %v", err)
}
}
}

View File

@@ -14,6 +14,7 @@ import (
"gopkg.in/yaml.v3"
)
// Config represents the main YAML configuration structure for tesseract
type Config struct {
Listen []string `yaml:"listen"`
Checkpoints string `yaml:"checkpoints"`
@@ -21,6 +22,7 @@ type Config struct {
Logs []Log `yaml:"logs"`
}
// Log represents a single Certificate Transparency log configuration
type Log struct {
ShortName string `yaml:"shortname"`
Inception string `yaml:"inception"`

View File

@@ -265,9 +265,9 @@ func TestWriteFileWithStatus(t *testing.T) {
func TestTimeFormats(t *testing.T) {
testTime := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
expected := "2024-01-01T12:00:00Z"
formatted := testTime.Format("2006-01-02T15:04:05Z")
if formatted != expected {
t.Errorf("Time format = %s, want %s", formatted, expected)
}
}
}

View File

@@ -70,6 +70,7 @@ const nginxTemplate = `server {
}
`
// NginxTemplateData contains the data needed to generate nginx configuration files
type NginxTemplateData struct {
MonitoringHost string
LocalDirectory string

View File

@@ -9,7 +9,7 @@ import (
func TestGenerateNginx(t *testing.T) {
tmpDir := t.TempDir()
// Create test directories
log1Dir := filepath.Join(tmpDir, "log1")
log2Dir := filepath.Join(tmpDir, "log2")
@@ -50,7 +50,7 @@ logs:
}
nginx1Str := string(nginxContent1)
// Check server block basics
if !strings.Contains(nginx1Str, "server {") {
t.Error("Expected server block")
@@ -304,4 +304,4 @@ func TestGenerateNginxNoListenConfig(t *testing.T) {
if !strings.Contains(nginxStr, "listen 8080;") {
t.Error("Expected default port 8080 when no listen config provided")
}
}
}

View File

@@ -12,6 +12,7 @@ import (
"strings"
)
// CTLogRootsResponse represents the JSON response from a CT log's get-roots endpoint
type CTLogRootsResponse struct {
Certificates []string `json:"certificates"`
}

View File

@@ -29,7 +29,7 @@ func TestGenerateRoots(t *testing.T) {
if !strings.HasSuffix(r.URL.Path, "/ct/v1/get-roots") {
t.Errorf("Expected path to end with /ct/v1/get-roots, got %s", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(mockResponse)
}))
@@ -51,7 +51,7 @@ func TestGenerateRoots(t *testing.T) {
}
contentStr := string(content)
// Should contain PEM headers
if !strings.Contains(contentStr, "-----BEGIN CERTIFICATE-----") {
t.Error("Expected PEM certificate headers")
@@ -152,7 +152,7 @@ func TestGenerateRootsSourceURLFormatting(t *testing.T) {
if r.URL.Path != expectedPath {
t.Errorf("Expected path %s, got %s", expectedPath, r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(mockResponse)
}))
@@ -202,11 +202,11 @@ func TestPEMEncoding(t *testing.T) {
if block == nil {
break
}
if block.Type != "CERTIFICATE" {
t.Errorf("Expected block type 'CERTIFICATE', got %s", block.Type)
}
certCount++
remaining = rest
}
@@ -214,4 +214,4 @@ func TestPEMEncoding(t *testing.T) {
if certCount != 1 {
t.Errorf("Expected 1 certificate, found %d", certCount)
}
}
}