Fix some lint and vet issues
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestGenerateEnv(t *testing.T) {
|
func TestGenerateEnv(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create test directories
|
// Create test directories
|
||||||
testLogDir := filepath.Join(tmpDir, "test-log")
|
testLogDir := filepath.Join(tmpDir, "test-log")
|
||||||
testLog2Dir := filepath.Join(tmpDir, "test-log-2")
|
testLog2Dir := filepath.Join(tmpDir, "test-log-2")
|
||||||
@@ -25,11 +25,11 @@ func TestGenerateEnv(t *testing.T) {
|
|||||||
// Create test roots files
|
// Create test roots files
|
||||||
rootsFile := filepath.Join(tmpDir, "roots.pem")
|
rootsFile := filepath.Join(tmpDir, "roots.pem")
|
||||||
extraRootsFile := filepath.Join(tmpDir, "extra-roots.pem")
|
extraRootsFile := filepath.Join(tmpDir, "extra-roots.pem")
|
||||||
|
|
||||||
rootsContent := `-----BEGIN CERTIFICATE-----
|
rootsContent := `-----BEGIN CERTIFICATE-----
|
||||||
MIIBkTCB+wIJAKZJ...
|
MIIBkTCB+wIJAKZJ...
|
||||||
-----END CERTIFICATE-----`
|
-----END CERTIFICATE-----`
|
||||||
|
|
||||||
extraRootsContent := `-----BEGIN CERTIFICATE-----
|
extraRootsContent := `-----BEGIN CERTIFICATE-----
|
||||||
MIIBkTCB+wIJAKZK...
|
MIIBkTCB+wIJAKZK...
|
||||||
-----END CERTIFICATE-----`
|
-----END CERTIFICATE-----`
|
||||||
@@ -80,7 +80,7 @@ logs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
envStr := string(envContent)
|
envStr := string(envContent)
|
||||||
|
|
||||||
// Check TESSERACT_ARGS contains expected values
|
// Check TESSERACT_ARGS contains expected values
|
||||||
if !strings.Contains(envStr, "TESSERACT_ARGS=") {
|
if !strings.Contains(envStr, "TESSERACT_ARGS=") {
|
||||||
t.Error("Expected TESSERACT_ARGS in .env file")
|
t.Error("Expected TESSERACT_ARGS in .env file")
|
||||||
@@ -199,7 +199,7 @@ func TestCreateCombinedRootsPemWithStatus(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenerateEnvMissingDirectory(t *testing.T) {
|
func TestGenerateEnvMissingDirectory(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create config with non-existent directory
|
// Create config with non-existent directory
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log"
|
- shortname: "test-log"
|
||||||
@@ -216,4 +216,4 @@ func TestGenerateEnvMissingDirectory(t *testing.T) {
|
|||||||
// Should call log.Fatalf which exits the program
|
// Should call log.Fatalf which exits the program
|
||||||
// We can't easily test this without subprocess, so we'll skip it
|
// We can't easily test this without subprocess, so we'll skip it
|
||||||
t.Skip("Cannot easily test log.Fatalf without subprocess")
|
t.Skip("Cannot easily test log.Fatalf without subprocess")
|
||||||
}
|
}
|
||||||
|
@@ -95,6 +95,7 @@ const htmlTemplate = `<!DOCTYPE html>
|
|||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// LogV3JSON represents the Certificate Transparency log v3 JSON metadata format
|
||||||
type LogV3JSON struct {
|
type LogV3JSON struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
SubmissionURL string `json:"submission_url"`
|
SubmissionURL string `json:"submission_url"`
|
||||||
@@ -105,6 +106,7 @@ type LogV3JSON struct {
|
|||||||
MMD int `json:"mmd"`
|
MMD int `json:"mmd"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TemporalInterval represents the time range for a Certificate Transparency log
|
||||||
type TemporalInterval struct {
|
type TemporalInterval struct {
|
||||||
StartInclusive string `json:"start_inclusive"`
|
StartInclusive string `json:"start_inclusive"`
|
||||||
EndExclusive string `json:"end_exclusive"`
|
EndExclusive string `json:"end_exclusive"`
|
||||||
|
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
func TestGenerateHTML(t *testing.T) {
|
func TestGenerateHTML(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create test directories
|
// Create test directories
|
||||||
testLogDir := filepath.Join(tmpDir, "test-log")
|
testLogDir := filepath.Join(tmpDir, "test-log")
|
||||||
err := os.MkdirAll(testLogDir, 0755)
|
err := os.MkdirAll(testLogDir, 0755)
|
||||||
@@ -75,7 +75,7 @@ logs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
htmlStr := string(htmlContent)
|
htmlStr := string(htmlContent)
|
||||||
|
|
||||||
// Check HTML contains expected elements
|
// Check HTML contains expected elements
|
||||||
if !strings.Contains(htmlStr, "<!DOCTYPE html>") {
|
if !strings.Contains(htmlStr, "<!DOCTYPE html>") {
|
||||||
t.Error("Expected HTML doctype")
|
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")
|
testTime2, _ := time.Parse("2006-01-02T15:04:05Z", "2025-01-01T00:00:00Z")
|
||||||
|
|
||||||
logEntry := Log{
|
logEntry := Log{
|
||||||
Origin: "test.example.com",
|
Origin: "test.example.com",
|
||||||
SubmissionPrefix: "https://test.example.com/submit",
|
SubmissionPrefix: "https://test.example.com/submit",
|
||||||
MonitoringPrefix: "https://test.example.com/monitor",
|
MonitoringPrefix: "https://test.example.com/monitor",
|
||||||
NotAfterStart: testTime1,
|
NotAfterStart: testTime1,
|
||||||
NotAfterLimit: testTime2,
|
NotAfterLimit: testTime2,
|
||||||
LogID: "dGVzdC1sb2ctaWQ=", // base64 encoded "test-log-id"
|
LogID: "dGVzdC1sb2ctaWQ=", // base64 encoded "test-log-id"
|
||||||
PublicKeyBase64: "dGVzdC1wdWJsaWMta2V5", // base64 encoded "test-public-key"
|
PublicKeyBase64: "dGVzdC1wdWJsaWMta2V5", // base64 encoded "test-public-key"
|
||||||
}
|
}
|
||||||
|
|
||||||
err := generateLogJSONWithStatus(logEntry, outputFile, false, true, false)
|
err := generateLogJSONWithStatus(logEntry, outputFile, false, true, false)
|
||||||
@@ -295,7 +295,7 @@ func TestGenerateLogJSONWithStatus(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenerateHTMLMissingDirectory(t *testing.T) {
|
func TestGenerateHTMLMissingDirectory(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create config with non-existent directory
|
// Create config with non-existent directory
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log"
|
- shortname: "test-log"
|
||||||
@@ -313,4 +313,4 @@ func TestGenerateHTMLMissingDirectory(t *testing.T) {
|
|||||||
// Should call log.Fatalf which exits the program
|
// Should call log.Fatalf which exits the program
|
||||||
// We can't easily test this without subprocess, so we'll skip it
|
// We can't easily test this without subprocess, so we'll skip it
|
||||||
t.Skip("Cannot easily test log.Fatalf without subprocess")
|
t.Skip("Cannot easily test log.Fatalf without subprocess")
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
func TestGenerateKeys(t *testing.T) {
|
func TestGenerateKeys(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create test directories
|
// Create test directories
|
||||||
keyDir := filepath.Join(tmpDir, "keys")
|
keyDir := filepath.Join(tmpDir, "keys")
|
||||||
err := os.MkdirAll(keyDir, 0755)
|
err := os.MkdirAll(keyDir, 0755)
|
||||||
@@ -23,7 +23,7 @@ func TestGenerateKeys(t *testing.T) {
|
|||||||
// Create test config
|
// Create test config
|
||||||
key1Path := filepath.Join(keyDir, "test-log-1.key")
|
key1Path := filepath.Join(keyDir, "test-log-1.key")
|
||||||
key2Path := filepath.Join(keyDir, "test-log-2.key")
|
key2Path := filepath.Join(keyDir, "test-log-2.key")
|
||||||
|
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log-1"
|
- shortname: "test-log-1"
|
||||||
secret: "` + key1Path + `"
|
secret: "` + key1Path + `"
|
||||||
@@ -84,7 +84,7 @@ func TestGenerateKeys(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
perm := info.Mode().Perm()
|
perm := info.Mode().Perm()
|
||||||
expected := os.FileMode(0600)
|
expected := os.FileMode(0600)
|
||||||
if perm != expected {
|
if perm != expected {
|
||||||
@@ -94,13 +94,13 @@ func TestGenerateKeys(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenerateKeysExistingKey(t *testing.T) {
|
func TestGenerateKeysExistingKey(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create existing key file
|
// Create existing key file
|
||||||
keyPath := filepath.Join(tmpDir, "existing.key")
|
keyPath := filepath.Join(tmpDir, "existing.key")
|
||||||
existingContent := `-----BEGIN EC PRIVATE KEY-----
|
existingContent := `-----BEGIN EC PRIVATE KEY-----
|
||||||
MHcCAQEEIExistingKeyContent
|
MHcCAQEEIExistingKeyContent
|
||||||
-----END EC PRIVATE KEY-----`
|
-----END EC PRIVATE KEY-----`
|
||||||
|
|
||||||
err := os.WriteFile(keyPath, []byte(existingContent), 0600)
|
err := os.WriteFile(keyPath, []byte(existingContent), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -133,9 +133,9 @@ MHcCAQEEIExistingKeyContent
|
|||||||
|
|
||||||
func TestGenerateKeysWithoutWriteFlag(t *testing.T) {
|
func TestGenerateKeysWithoutWriteFlag(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
keyPath := filepath.Join(tmpDir, "test.key")
|
keyPath := filepath.Join(tmpDir, "test.key")
|
||||||
|
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log"
|
- shortname: "test-log"
|
||||||
secret: "` + keyPath + `"`
|
secret: "` + keyPath + `"`
|
||||||
@@ -157,11 +157,11 @@ func TestGenerateKeysWithoutWriteFlag(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenerateKeysCreateDirectory(t *testing.T) {
|
func TestGenerateKeysCreateDirectory(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Key path with non-existent directory
|
// Key path with non-existent directory
|
||||||
keyDir := filepath.Join(tmpDir, "subdir", "keys")
|
keyDir := filepath.Join(tmpDir, "subdir", "keys")
|
||||||
keyPath := filepath.Join(keyDir, "test.key")
|
keyPath := filepath.Join(keyDir, "test.key")
|
||||||
|
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log"
|
- shortname: "test-log"
|
||||||
secret: "` + keyPath + `"`
|
secret: "` + keyPath + `"`
|
||||||
@@ -188,10 +188,10 @@ func TestGenerateKeysCreateDirectory(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenerateKeysMultipleRuns(t *testing.T) {
|
func TestGenerateKeysMultipleRuns(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
key1Path := filepath.Join(tmpDir, "key1.key")
|
key1Path := filepath.Join(tmpDir, "key1.key")
|
||||||
key2Path := filepath.Join(tmpDir, "key2.key")
|
key2Path := filepath.Join(tmpDir, "key2.key")
|
||||||
|
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log-1"
|
- shortname: "test-log-1"
|
||||||
secret: "` + key1Path + `"
|
secret: "` + key1Path + `"
|
||||||
@@ -244,7 +244,7 @@ func TestGenerateKeysMultipleRuns(t *testing.T) {
|
|||||||
func TestECKeyGeneration(t *testing.T) {
|
func TestECKeyGeneration(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
keyPath := filepath.Join(tmpDir, "test.key")
|
keyPath := filepath.Join(tmpDir, "test.key")
|
||||||
|
|
||||||
configContent := `logs:
|
configContent := `logs:
|
||||||
- shortname: "test-log"
|
- shortname: "test-log"
|
||||||
secret: "` + keyPath + `"`
|
secret: "` + keyPath + `"`
|
||||||
@@ -293,4 +293,4 @@ func TestECKeyGeneration(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to marshal public key: %v", err)
|
t.Errorf("Failed to marshal public key: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Config represents the main YAML configuration structure for tesseract
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Listen []string `yaml:"listen"`
|
Listen []string `yaml:"listen"`
|
||||||
Checkpoints string `yaml:"checkpoints"`
|
Checkpoints string `yaml:"checkpoints"`
|
||||||
@@ -21,6 +22,7 @@ type Config struct {
|
|||||||
Logs []Log `yaml:"logs"`
|
Logs []Log `yaml:"logs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log represents a single Certificate Transparency log configuration
|
||||||
type Log struct {
|
type Log struct {
|
||||||
ShortName string `yaml:"shortname"`
|
ShortName string `yaml:"shortname"`
|
||||||
Inception string `yaml:"inception"`
|
Inception string `yaml:"inception"`
|
||||||
|
@@ -265,9 +265,9 @@ func TestWriteFileWithStatus(t *testing.T) {
|
|||||||
func TestTimeFormats(t *testing.T) {
|
func TestTimeFormats(t *testing.T) {
|
||||||
testTime := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
|
testTime := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
|
||||||
expected := "2024-01-01T12:00:00Z"
|
expected := "2024-01-01T12:00:00Z"
|
||||||
|
|
||||||
formatted := testTime.Format("2006-01-02T15:04:05Z")
|
formatted := testTime.Format("2006-01-02T15:04:05Z")
|
||||||
if formatted != expected {
|
if formatted != expected {
|
||||||
t.Errorf("Time format = %s, want %s", formatted, expected)
|
t.Errorf("Time format = %s, want %s", formatted, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -70,6 +70,7 @@ const nginxTemplate = `server {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// NginxTemplateData contains the data needed to generate nginx configuration files
|
||||||
type NginxTemplateData struct {
|
type NginxTemplateData struct {
|
||||||
MonitoringHost string
|
MonitoringHost string
|
||||||
LocalDirectory string
|
LocalDirectory string
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestGenerateNginx(t *testing.T) {
|
func TestGenerateNginx(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
// Create test directories
|
// Create test directories
|
||||||
log1Dir := filepath.Join(tmpDir, "log1")
|
log1Dir := filepath.Join(tmpDir, "log1")
|
||||||
log2Dir := filepath.Join(tmpDir, "log2")
|
log2Dir := filepath.Join(tmpDir, "log2")
|
||||||
@@ -50,7 +50,7 @@ logs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
nginx1Str := string(nginxContent1)
|
nginx1Str := string(nginxContent1)
|
||||||
|
|
||||||
// Check server block basics
|
// Check server block basics
|
||||||
if !strings.Contains(nginx1Str, "server {") {
|
if !strings.Contains(nginx1Str, "server {") {
|
||||||
t.Error("Expected server block")
|
t.Error("Expected server block")
|
||||||
@@ -304,4 +304,4 @@ func TestGenerateNginxNoListenConfig(t *testing.T) {
|
|||||||
if !strings.Contains(nginxStr, "listen 8080;") {
|
if !strings.Contains(nginxStr, "listen 8080;") {
|
||||||
t.Error("Expected default port 8080 when no listen config provided")
|
t.Error("Expected default port 8080 when no listen config provided")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CTLogRootsResponse represents the JSON response from a CT log's get-roots endpoint
|
||||||
type CTLogRootsResponse struct {
|
type CTLogRootsResponse struct {
|
||||||
Certificates []string `json:"certificates"`
|
Certificates []string `json:"certificates"`
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ func TestGenerateRoots(t *testing.T) {
|
|||||||
if !strings.HasSuffix(r.URL.Path, "/ct/v1/get-roots") {
|
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)
|
t.Errorf("Expected path to end with /ct/v1/get-roots, got %s", r.URL.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(mockResponse)
|
json.NewEncoder(w).Encode(mockResponse)
|
||||||
}))
|
}))
|
||||||
@@ -51,7 +51,7 @@ func TestGenerateRoots(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
contentStr := string(content)
|
contentStr := string(content)
|
||||||
|
|
||||||
// Should contain PEM headers
|
// Should contain PEM headers
|
||||||
if !strings.Contains(contentStr, "-----BEGIN CERTIFICATE-----") {
|
if !strings.Contains(contentStr, "-----BEGIN CERTIFICATE-----") {
|
||||||
t.Error("Expected PEM certificate headers")
|
t.Error("Expected PEM certificate headers")
|
||||||
@@ -152,7 +152,7 @@ func TestGenerateRootsSourceURLFormatting(t *testing.T) {
|
|||||||
if r.URL.Path != expectedPath {
|
if r.URL.Path != expectedPath {
|
||||||
t.Errorf("Expected path %s, got %s", expectedPath, r.URL.Path)
|
t.Errorf("Expected path %s, got %s", expectedPath, r.URL.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(mockResponse)
|
json.NewEncoder(w).Encode(mockResponse)
|
||||||
}))
|
}))
|
||||||
@@ -202,11 +202,11 @@ func TestPEMEncoding(t *testing.T) {
|
|||||||
if block == nil {
|
if block == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if block.Type != "CERTIFICATE" {
|
if block.Type != "CERTIFICATE" {
|
||||||
t.Errorf("Expected block type 'CERTIFICATE', got %s", block.Type)
|
t.Errorf("Expected block type 'CERTIFICATE', got %s", block.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
certCount++
|
certCount++
|
||||||
remaining = rest
|
remaining = rest
|
||||||
}
|
}
|
||||||
@@ -214,4 +214,4 @@ func TestPEMEncoding(t *testing.T) {
|
|||||||
if certCount != 1 {
|
if certCount != 1 {
|
||||||
t.Errorf("Expected 1 certificate, found %d", certCount)
|
t.Errorf("Expected 1 certificate, found %d", certCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user