Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions generator/filegen/filegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -120,7 +119,7 @@ func TestFileLogGeneratorFileMode(t *testing.T) {
logger := zaptest.NewLogger(t)

// Create a temporary file with test data
tmpfile, err := ioutil.TempFile("", "test*.log")
tmpfile, err := os.CreateTemp("", "test*.log")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())

Expand Down Expand Up @@ -160,7 +159,7 @@ func TestFileLogGeneratorDirectoryMode(t *testing.T) {
logger := zaptest.NewLogger(t)

// Create a temporary directory with test files
tmpdir, err := ioutil.TempDir("", "testdir")
tmpdir, err := os.MkdirTemp("", "testdir")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)

Expand All @@ -176,7 +175,7 @@ func TestFileLogGeneratorDirectoryMode(t *testing.T) {

for _, f := range files {
path := filepath.Join(tmpdir, f.name)
err := ioutil.WriteFile(path, []byte(f.data), 0644)
err := os.WriteFile(path, []byte(f.data), 0644)
require.NoError(t, err)
}

Expand Down Expand Up @@ -216,7 +215,7 @@ func TestFileLogGeneratorNonexistentFile(t *testing.T) {
func TestFileLogGeneratorStop(t *testing.T) {
logger := zaptest.NewLogger(t)

tmpfile, err := ioutil.TempFile("", "test*.log")
tmpfile, err := os.CreateTemp("", "test*.log")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())

Expand All @@ -243,7 +242,7 @@ func TestFileLogGeneratorStop(t *testing.T) {
func TestFileLogGeneratorWriteError(t *testing.T) {
logger := zaptest.NewLogger(t)

tmpfile, err := ioutil.TempFile("", "test*.log")
tmpfile, err := os.CreateTemp("", "test*.log")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())

Expand Down Expand Up @@ -271,11 +270,11 @@ func TestFileLogGeneratorWriteError(t *testing.T) {
func TestFileLogGeneratorMultipleWorkers(t *testing.T) {
logger := zaptest.NewLogger(t)

tmpfile, err := ioutil.TempFile("", "test*.log")
tmpfile, err := os.CreateTemp("", "test*.log")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())

for i := 0; i < 10; i++ {
for i := range 10 {
_, err := tmpfile.WriteString("Thu Jan 13 15:30:45 2026 test line " + string(rune(i)) + "\n")
require.NoError(t, err)
}
Expand Down Expand Up @@ -304,7 +303,7 @@ func TestFileLogGeneratorMultipleWorkers(t *testing.T) {
func TestTimestampProcessing(t *testing.T) {
logger := zaptest.NewLogger(t)
// Create a temporary file for the generator to use
tmpFile, err := ioutil.TempFile(t.TempDir(), "test*.log")
tmpFile, err := os.CreateTemp(t.TempDir(), "test*.log")
require.NoError(t, err)
tmpFile.Close()

Expand Down
2 changes: 1 addition & 1 deletion generator/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestJSONGenerator_MultipleStartStop(t *testing.T) {
writer := newMockWriter()

// Start and stop multiple times with new generator instances
for i := 0; i < 3; i++ {
for range 3 {
generator, err := New(logger, 2, 20*time.Millisecond, "default")
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions generator/okta/okta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestOktaGenerator_FailureOutcomeHasReason(t *testing.T) {
require.NoError(t, err)

// Generate enough logs to get some failures
for i := 0; i < 200; i++ {
for range 200 {
logRecord, err := generator.generateOktaLog(r)
require.NoError(t, err)

Expand All @@ -282,7 +282,7 @@ func TestOktaGenerator_MultipleStartStop(t *testing.T) {
logger := zaptest.NewLogger(t)
writer := newMockWriter()

for i := 0; i < 3; i++ {
for range 3 {
generator, err := New(logger, 2, 20*time.Millisecond)
require.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions generator/paloalto/paloalto.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,18 @@ func generateNumericSessionID() string {
// Generate a numeric session ID like "01606001116" or "1606001116"
// Length varies between 9-11 digits
length := randInt(9, 11)
sessionID := ""
for i := 0; i < length; i++ {
var sessionID strings.Builder
for i := range length {
// First digit can be 0 for IDs with length > 9, otherwise 1-9
if i == 0 && length > 9 {
digit := randInt(0, 9)
sessionID += strconv.Itoa(digit)
sessionID.WriteString(strconv.Itoa(digit))
} else {
digit := randInt(0, 9)
sessionID += strconv.Itoa(digit)
sessionID.WriteString(strconv.Itoa(digit))
}
}
return sessionID
return sessionID.String()
}

func randInt(min, max int) int {
Expand Down
10 changes: 5 additions & 5 deletions generator/paloalto/paloalto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestGenerator_ConcurrentWorkers(t *testing.T) {
func TestGeneratePaloAltoLog_Format(t *testing.T) {
// Generate multiple logs to test variety
logs := make([]string, 100)
for i := 0; i < 100; i++ {
for i := range 100 {
logs[i] = generatePaloAltoLog()
}

Expand Down Expand Up @@ -248,7 +248,7 @@ func TestGeneratePaloAltoLog_Format(t *testing.T) {

func TestGenerateRandomIP(t *testing.T) {
ips := make(map[string]bool)
for i := 0; i < 100; i++ {
for range 100 {
ip := generateRandomIP()
// Verify IP format
parts := strings.Split(ip, ".")
Expand All @@ -261,7 +261,7 @@ func TestGenerateRandomIP(t *testing.T) {

func TestGenerateRandomPort(t *testing.T) {
ports := make(map[string]bool)
for i := 0; i < 100; i++ {
for range 100 {
port := generateRandomPort()
// Port should be a valid string representation of a number
assert.NotEmpty(t, port, "Port should not be empty")
Expand All @@ -273,7 +273,7 @@ func TestGenerateRandomPort(t *testing.T) {

func TestGenerateRandomSessionID(t *testing.T) {
sessionIDs := make(map[string]bool)
for i := 0; i < 100; i++ {
for range 100 {
sessionID := generateRandomSessionID()
// Session ID should be 12 characters (6 bytes hex encoded)
assert.Equal(t, 12, len(sessionID), "Session ID should be 12 characters")
Expand All @@ -293,7 +293,7 @@ func TestGenerator_MultipleStartStop(t *testing.T) {
writer := newMockWriter()

// Start and stop multiple times with new generator instances
for i := 0; i < 3; i++ {
for range 3 {
generator, err := New(logger, 2, 20*time.Millisecond)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions generator/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ func formatAsPostgres(data *postgresLogData) (output.LogRecord, error) {
}

// Parse user=...,db=...,app=...,client=... from prefix
prefixFields := strings.Split(prefixPart, ",")
for _, field := range prefixFields {
prefixFields := strings.SplitSeq(prefixPart, ",")
for field := range prefixFields {
if strings.Contains(field, "user=") {
parsed["user"] = strings.TrimPrefix(field[strings.Index(field, "user="):], "user=")
}
Expand Down
2 changes: 1 addition & 1 deletion generator/winevt/winevt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestRenderTemplate_RandomSelection(t *testing.T) {
successfulLogonCount := 0

// Generate 150 templates with random selection
for i := 0; i < 150; i++ {
for range 150 {
result, err := templates.RenderTemplate(templates.RenderOptions{})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/observiq/blitz

go 1.25.1
go 1.26.0

tool github.com/mgechev/revive

Expand Down
6 changes: 3 additions & 3 deletions internal/config/override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ func TestOverrideCoverage(t *testing.T) {

// Build sets of tested flags and env vars for quick lookup
testedFlagSet := make(map[string]bool)
for i := 0; i < len(testedFlags); i++ {
if strings.HasPrefix(testedFlags[i], "--") {
flagName := strings.TrimPrefix(testedFlags[i], "--")
for i := range testedFlags {
if after, ok := strings.CutPrefix(testedFlags[i], "--"); ok {
flagName := after
// Handle both --flag value and --flag=value formats
if idx := strings.Index(flagName, "="); idx != -1 {
flagName = flagName[:idx]
Expand Down
81 changes: 43 additions & 38 deletions internal/generator/logtypes/pii.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logtypes
import (
"fmt"
"math/rand"
"strings"
"time"
)

Expand Down Expand Up @@ -139,7 +140,7 @@ func generateCreditCard(r *rand.Rand) string {
remaining := 16 - len(prefix) - 1 // -1 for check digit

number := prefix
for i := 0; i < remaining; i++ {
for range remaining {
number += fmt.Sprintf("%d", r.Intn(10))
}
// Add a random check digit (not Luhn-valid, but looks realistic)
Expand Down Expand Up @@ -239,8 +240,8 @@ func generateDriversLicense(r *rand.Rand) string {
func generateNationalID(r *rand.Rand) string {
// Various formats: UK NI, Canadian SIN, etc.
formats := []string{
fmt.Sprintf("AB%06dC", r.Intn(1000000)), // UK National Insurance
fmt.Sprintf("%03d-%03d-%03d", r.Intn(1000), r.Intn(1000), r.Intn(1000)), // Canadian SIN
fmt.Sprintf("AB%06dC", r.Intn(1000000)), // UK National Insurance
fmt.Sprintf("%03d-%03d-%03d", r.Intn(1000), r.Intn(1000), r.Intn(1000)), // Canadian SIN
fmt.Sprintf("%02d%02d%02d-%05d", r.Intn(100), r.Intn(13), r.Intn(32), r.Intn(100000)), // Various EU
}
return formats[r.Intn(len(formats))]
Expand All @@ -250,11 +251,11 @@ func generateNationalID(r *rand.Rand) string {
func generateBankAccount(r *rand.Rand) string {
// 8-17 digits typical
length := 8 + r.Intn(10)
account := ""
for i := 0; i < length; i++ {
account += fmt.Sprintf("%d", r.Intn(10))
var account strings.Builder
for range length {
account.WriteString(fmt.Sprintf("%d", r.Intn(10)))
}
return account
return account.String()
}

// generateRoutingNumber generates a random ABA routing number
Expand All @@ -270,12 +271,13 @@ func generateCryptoWallet(r *rand.Rand) string {
prefixes := []string{"1", "3", "bc1q"}
prefix := prefixes[r.Intn(len(prefixes))]
chars := "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
addr := prefix
var addr strings.Builder
addr.WriteString(prefix)
length := 26 + r.Intn(10)
for i := 0; i < length; i++ {
addr += string(chars[r.Intn(len(chars))])
for range length {
addr.WriteString(string(chars[r.Intn(len(chars))]))
}
return addr
return addr.String()
}
// Ethereum (starts with 0x, 40 hex chars)
return fmt.Sprintf("0x%040x", r.Uint64())
Expand All @@ -299,11 +301,11 @@ func generateHealthInsurance(r *rand.Rand) string {
func generateVIN(r *rand.Rand) string {
// VIN is 17 characters, excludes I, O, Q
chars := "ABCDEFGHJKLMNPRSTUVWXYZ0123456789"
vin := ""
for i := 0; i < 17; i++ {
vin += string(chars[r.Intn(len(chars))])
var vin strings.Builder
for range 17 {
vin.WriteString(string(chars[r.Intn(len(chars))]))
}
return vin
return vin.String()
}

// generateLicensePlate generates a random license plate
Expand Down Expand Up @@ -337,35 +339,38 @@ func generateUsername(r *rand.Rand) string {
func generatePasswordHash(r *rand.Rand) string {
// Looks like bcrypt hash
chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"
hash := "$2a$10$"
for i := 0; i < 53; i++ {
hash += string(chars[r.Intn(len(chars))])
var hash strings.Builder
hash.WriteString("$2a$10$")
for range 53 {
hash.WriteString(string(chars[r.Intn(len(chars))]))
}
return hash
return hash.String()
}

// generateAPIKey generates a random API key
func generateAPIKey(r *rand.Rand) string {
prefixes := []string{"apikey_", "secret_", "token_", "key_", "access_key_"}
prefix := prefixes[r.Intn(len(prefixes))]
chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
key := prefix
for i := 0; i < 32; i++ {
key += string(chars[r.Intn(len(chars))])
var key strings.Builder
key.WriteString(prefix)
for range 32 {
key.WriteString(string(chars[r.Intn(len(chars))]))
}
return key
return key.String()
}

// generateAWSAccessKey generates a random AWS Access Key ID
func generateAWSAccessKey(r *rand.Rand) string {
// AWS Access Key IDs start with AKIA, ABIA, ACCA, or ASIA
prefixes := []string{"AKIA", "ABIA", "ACCA", "ASIA"}
chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
key := prefixes[r.Intn(len(prefixes))]
for i := 0; i < 16; i++ {
key += string(chars[r.Intn(len(chars))])
var key strings.Builder
key.WriteString(prefixes[r.Intn(len(prefixes))])
for range 16 {
key.WriteString(string(chars[r.Intn(len(chars))]))
}
return key
return key.String()
}

// generatePrivateKey generates a partial private key representation
Expand All @@ -379,15 +384,15 @@ func generateJWTToken(r *rand.Rand) string {
// Generate fake but realistic-looking JWT
chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
header := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
payload := ""
for i := 0; i < 36; i++ {
payload += string(chars[r.Intn(len(chars))])
var payload strings.Builder
for range 36 {
payload.WriteString(string(chars[r.Intn(len(chars))]))
}
signature := ""
for i := 0; i < 43; i++ {
signature += string(chars[r.Intn(len(chars))])
var signature strings.Builder
for range 43 {
signature.WriteString(string(chars[r.Intn(len(chars))]))
}
return fmt.Sprintf("%s.%s.%s", header, payload, signature)
return fmt.Sprintf("%s.%s.%s", header, payload.String(), signature.String())
}

// generateGPSCoords generates random GPS coordinates
Expand All @@ -400,12 +405,12 @@ func generateGPSCoords(r *rand.Rand) string {
// generateGeohash generates a random geohash
func generateGeohash(r *rand.Rand) string {
chars := "0123456789bcdefghjkmnpqrstuvwxyz"
hash := ""
var hash strings.Builder
length := 6 + r.Intn(6) // 6-12 characters
for i := 0; i < length; i++ {
hash += string(chars[r.Intn(len(chars))])
for range length {
hash.WriteString(string(chars[r.Intn(len(chars))]))
}
return hash
return hash.String()
}

// generateFullName generates a random full name
Expand Down
Loading