From 105a2452398a532f63d490d406e0ec61c8a8e4aa Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Thu, 28 Aug 2025 21:17:37 +0200 Subject: [PATCH] Fix some lint and vet issues --- tesseract/genconf/env_test.go | 12 ++++++------ tesseract/genconf/html.go | 2 ++ tesseract/genconf/html_test.go | 22 +++++++++++----------- tesseract/genconf/key_test.go | 26 +++++++++++++------------- tesseract/genconf/main.go | 2 ++ tesseract/genconf/main_test.go | 4 ++-- tesseract/genconf/nginx.go | 1 + tesseract/genconf/nginx_test.go | 6 +++--- tesseract/genconf/roots.go | 1 + tesseract/genconf/roots_test.go | 12 ++++++------ 10 files changed, 47 insertions(+), 41 deletions(-) diff --git a/tesseract/genconf/env_test.go b/tesseract/genconf/env_test.go index a0951a2..f91d3a5 100644 --- a/tesseract/genconf/env_test.go +++ b/tesseract/genconf/env_test.go @@ -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") -} \ No newline at end of file +} diff --git a/tesseract/genconf/html.go b/tesseract/genconf/html.go index ae10eba..502b466 100644 --- a/tesseract/genconf/html.go +++ b/tesseract/genconf/html.go @@ -95,6 +95,7 @@ const htmlTemplate = ` ` +// 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"` diff --git a/tesseract/genconf/html_test.go b/tesseract/genconf/html_test.go index da1fda4..44ea128 100644 --- a/tesseract/genconf/html_test.go +++ b/tesseract/genconf/html_test.go @@ -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, "") { 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") -} \ No newline at end of file +} diff --git a/tesseract/genconf/key_test.go b/tesseract/genconf/key_test.go index f18549c..0a697a6 100644 --- a/tesseract/genconf/key_test.go +++ b/tesseract/genconf/key_test.go @@ -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) } -} \ No newline at end of file +} diff --git a/tesseract/genconf/main.go b/tesseract/genconf/main.go index 499e4b2..09482ac 100644 --- a/tesseract/genconf/main.go +++ b/tesseract/genconf/main.go @@ -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"` diff --git a/tesseract/genconf/main_test.go b/tesseract/genconf/main_test.go index 007fe73..c496e98 100644 --- a/tesseract/genconf/main_test.go +++ b/tesseract/genconf/main_test.go @@ -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) } -} \ No newline at end of file +} diff --git a/tesseract/genconf/nginx.go b/tesseract/genconf/nginx.go index e07e203..0b6db98 100644 --- a/tesseract/genconf/nginx.go +++ b/tesseract/genconf/nginx.go @@ -70,6 +70,7 @@ const nginxTemplate = `server { } ` +// NginxTemplateData contains the data needed to generate nginx configuration files type NginxTemplateData struct { MonitoringHost string LocalDirectory string diff --git a/tesseract/genconf/nginx_test.go b/tesseract/genconf/nginx_test.go index 072a6a0..b66544d 100644 --- a/tesseract/genconf/nginx_test.go +++ b/tesseract/genconf/nginx_test.go @@ -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") } -} \ No newline at end of file +} diff --git a/tesseract/genconf/roots.go b/tesseract/genconf/roots.go index 07eaf83..4bf3e21 100644 --- a/tesseract/genconf/roots.go +++ b/tesseract/genconf/roots.go @@ -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"` } diff --git a/tesseract/genconf/roots_test.go b/tesseract/genconf/roots_test.go index 9aec9fb..c25cd29 100644 --- a/tesseract/genconf/roots_test.go +++ b/tesseract/genconf/roots_test.go @@ -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) } -} \ No newline at end of file +}