Skip to content

Commit ffab165

Browse files
author
agilira
committed
feat: add comprehensive fuzz testing and vulnerability scanning
- Implement 8 fuzz test functions for robust error handling validation - Integrate govulncheck for automated vulnerability detection - Enhance build tools with security-focused Makefile improvements - Update CI/CD workflows with dependency verification - Maintain full backward compatibility with zero breaking changes
1 parent 03f25a6 commit ffab165

File tree

7 files changed

+571
-4
lines changed

7 files changed

+571
-4
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
run: |
2828
go install honnef.co/go/tools/cmd/staticcheck@latest
2929
go install github.com/securego/gosec/v2/cmd/gosec@latest
30+
go install golang.org/x/vuln/cmd/govulncheck@latest
31+
32+
- name: Verify Dependencies
33+
run: go mod verify
3034

3135
- name: Go Format Check
3236
run: |
@@ -49,6 +53,10 @@ jobs:
4953
gosec -conf .gosec.json ./... || true
5054
echo "Security scan completed"
5155
56+
- name: Vulnerability Check (govulncheck)
57+
continue-on-error: true
58+
run: govulncheck ./...
59+
5260
- name: Test with Race Detection
5361
run: go test -race -timeout 5m -v ./...
5462

.github/workflows/pr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323

2424
- name: Quick Quality Check
2525
run: |
26+
# Verify dependencies
27+
go mod verify
28+
2629
# Format check
2730
test -z "$(gofmt -l .)"
2831

Makefile

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Go Makefile - AGILira Standard
22
# Usage: make help
33

4-
.PHONY: help test race fmt vet lint security check deps clean build install tools
4+
.PHONY: help test race fmt vet lint security check deps clean build install tools fuzz govulcheck
55
.DEFAULT_GOAL := help
66

77
# Variables
@@ -66,12 +66,40 @@ gosec: ## Run gosec security scanner
6666
fi
6767
@$(TOOLS_DIR)/gosec ./... || (echo "$(YELLOW) gosec completed with warnings (may be import-related)$(NC)" && exit 0)
6868

69+
govulcheck: ## Run govulncheck for vulnerability scanning
70+
@echo "$(YELLOW)Running govulncheck for vulnerability scanning...$(NC)"
71+
@if ! command -v govulncheck >/dev/null 2>&1; then \
72+
echo "$(RED)govulncheck not found. Run 'make tools' to install.$(NC)"; \
73+
exit 1; \
74+
fi
75+
govulncheck ./...
76+
6977
lint: staticcheck errcheck ## Run all linters
7078
@echo "$(GREEN)All linters completed.$(NC)"
7179

72-
security: gosec ## Run security checks
80+
security: gosec govulcheck ## Run security checks
7381
@echo "$(GREEN)Security checks completed.$(NC)"
7482

83+
fuzz: ## Run fuzz tests for 30 seconds each
84+
@echo "$(YELLOW)Running fuzz tests...$(NC)"
85+
@echo "$(BLUE)Running FuzzNew...$(NC)"
86+
go test -fuzz=FuzzNew$$ -fuzztime=30s
87+
@echo "$(BLUE)Running FuzzNewWithField...$(NC)"
88+
go test -fuzz=FuzzNewWithField$$ -fuzztime=30s
89+
@echo "$(BLUE)Running FuzzWrap...$(NC)"
90+
go test -fuzz=FuzzWrap$$ -fuzztime=30s
91+
@echo "$(BLUE)Running FuzzWithMethods...$(NC)"
92+
go test -fuzz=FuzzWithMethods$$ -fuzztime=30s
93+
@echo "$(BLUE)Running FuzzHasCode...$(NC)"
94+
go test -fuzz=FuzzHasCode$$ -fuzztime=30s
95+
@echo "$(BLUE)Running FuzzJSONMarshal...$(NC)"
96+
go test -fuzz=FuzzJSONMarshal$$ -fuzztime=30s
97+
@echo "$(BLUE)Running FuzzValidateErrorCode...$(NC)"
98+
go test -fuzz=FuzzValidateErrorCode$$ -fuzztime=30s
99+
@echo "$(BLUE)Running FuzzStacktrace...$(NC)"
100+
go test -fuzz=FuzzStacktrace$$ -fuzztime=30s
101+
@echo "$(GREEN)Fuzz tests completed.$(NC)"
102+
75103
check: fmt vet lint security test ## Run all checks (format, vet, lint, security, test)
76104
@echo "$(GREEN)All checks passed!$(NC)"
77105

@@ -83,12 +111,15 @@ tools: ## Install development tools
83111
go install honnef.co/go/tools/cmd/staticcheck@latest
84112
go install github.com/kisielk/errcheck@latest
85113
go install github.com/securego/gosec/v2/cmd/gosec@latest
114+
go install golang.org/x/vuln/cmd/govulncheck@latest
86115
@echo "$(GREEN)Tools installed successfully!$(NC)"
87116

88117
deps: ## Download and verify dependencies
89118
@echo "$(YELLOW)Downloading dependencies...$(NC)"
90119
go mod download
120+
@echo "$(YELLOW)Verifying dependencies...$(NC)"
91121
go mod verify
122+
@echo "$(YELLOW)Tidying dependencies...$(NC)"
92123
go mod tidy
93124

94125
clean: ## Clean build artifacts and test cache
@@ -129,4 +160,5 @@ status: ## Show status of installed tools
129160
@echo "$(BLUE)Development tools status:$(NC)"
130161
@echo -n "staticcheck: "; [ -f "$(TOOLS_DIR)/staticcheck" ] && echo "$(GREEN)✓ installed$(NC)" || echo "$(RED)✗ missing$(NC)"
131162
@echo -n "errcheck: "; [ -f "$(TOOLS_DIR)/errcheck" ] && echo "$(GREEN)✓ installed$(NC)" || echo "$(RED)✗ missing$(NC)"
132-
@echo -n "gosec: "; [ -f "$(TOOLS_DIR)/gosec" ] && echo "$(GREEN)✓ installed$(NC)" || echo "$(RED)✗ missing$(NC)"
163+
@echo -n "gosec: "; [ -f "$(TOOLS_DIR)/gosec" ] && echo "$(GREEN)✓ installed$(NC)" || echo "$(RED)✗ missing$(NC)"
164+
@echo -n "govulncheck: "; command -v govulncheck >/dev/null 2>&1 && echo "$(GREEN)✓ installed$(NC)" || echo "$(RED)✗ missing$(NC)"

Makefile.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ function Invoke-Help {
4141
Write-ColorOutput " staticcheck Run staticcheck" $Green
4242
Write-ColorOutput " errcheck Run errcheck" $Green
4343
Write-ColorOutput " gosec Run gosec security scanner" $Green
44+
Write-ColorOutput " govulcheck Run govulncheck for vulnerability scanning" $Green
4445
Write-ColorOutput " lint Run all linters" $Green
4546
Write-ColorOutput " security Run security checks" $Green
47+
Write-ColorOutput " fuzz Run fuzz tests" $Green
4648
Write-ColorOutput " check Run all checks (format, vet, lint, security, test)" $Green
4749
Write-ColorOutput " check-race Run all checks including race detector" $Green
4850
Write-ColorOutput " tools Install development tools" $Green
@@ -124,6 +126,17 @@ function Invoke-GoSec {
124126
}
125127
}
126128

129+
function Invoke-GovulnCheck {
130+
Write-ColorOutput "Running govulncheck for vulnerability scanning..." $Yellow
131+
$govulnPath = Get-Command govulncheck -ErrorAction SilentlyContinue
132+
if (-not $govulnPath) {
133+
Write-ColorOutput "govulncheck not found. Run '.\Makefile.ps1 tools' to install." $Red
134+
exit 1
135+
}
136+
govulncheck "./..."
137+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
138+
}
139+
127140
function Invoke-Lint {
128141
Invoke-StaticCheck
129142
Invoke-ErrCheck
@@ -132,9 +145,48 @@ function Invoke-Lint {
132145

133146
function Invoke-Security {
134147
Invoke-GoSec
148+
Invoke-GovulnCheck
135149
Write-ColorOutput "Security checks completed." $Green
136150
}
137151

152+
function Invoke-Fuzz {
153+
Write-ColorOutput "Running fuzz tests..." $Yellow
154+
155+
Write-ColorOutput "Running FuzzNew..." $Blue
156+
go test -fuzz='FuzzNew$' -fuzztime=30s
157+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
158+
159+
Write-ColorOutput "Running FuzzNewWithField..." $Blue
160+
go test -fuzz='FuzzNewWithField$' -fuzztime=30s
161+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
162+
163+
Write-ColorOutput "Running FuzzWrap..." $Blue
164+
go test -fuzz='FuzzWrap$' -fuzztime=30s
165+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
166+
167+
Write-ColorOutput "Running FuzzWithMethods..." $Blue
168+
go test -fuzz='FuzzWithMethods$' -fuzztime=30s
169+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
170+
171+
Write-ColorOutput "Running FuzzHasCode..." $Blue
172+
go test -fuzz='FuzzHasCode$' -fuzztime=30s
173+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
174+
175+
Write-ColorOutput "Running FuzzJSONMarshal..." $Blue
176+
go test -fuzz='FuzzJSONMarshal$' -fuzztime=30s
177+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
178+
179+
Write-ColorOutput "Running FuzzValidateErrorCode..." $Blue
180+
go test -fuzz='FuzzValidateErrorCode$' -fuzztime=30s
181+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
182+
183+
Write-ColorOutput "Running FuzzStacktrace..." $Blue
184+
go test -fuzz='FuzzStacktrace$' -fuzztime=30s
185+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
186+
187+
Write-ColorOutput "Fuzz tests completed." $Green
188+
}
189+
138190
function Invoke-Check {
139191
Invoke-Fmt
140192
Invoke-Vet
@@ -164,6 +216,9 @@ function Invoke-Tools {
164216
go install github.com/securego/gosec/v2/cmd/gosec@latest
165217
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
166218

219+
go install golang.org/x/vuln/cmd/govulncheck@latest
220+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
221+
167222
Write-ColorOutput "Tools installed successfully!" $Green
168223
}
169224

@@ -172,9 +227,11 @@ function Invoke-Deps {
172227
go mod download
173228
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
174229

230+
Write-ColorOutput "Verifying dependencies..." $Yellow
175231
go mod verify
176232
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
177233

234+
Write-ColorOutput "Tidying dependencies..." $Yellow
178235
go mod tidy
179236
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
180237
}
@@ -250,6 +307,11 @@ function Invoke-Status {
250307
$gosecColor = if (Test-ToolExists "gosec") { $Green } else { $Red }
251308
Write-Host "gosec: " -NoNewline
252309
Write-ColorOutput $gosecStatus $gosecColor
310+
311+
$govulnStatus = if (Get-Command govulncheck -ErrorAction SilentlyContinue) { "✓ installed" } else { "✗ missing" }
312+
$govulnColor = if (Get-Command govulncheck -ErrorAction SilentlyContinue) { $Green } else { $Red }
313+
Write-Host "govulncheck: " -NoNewline
314+
Write-ColorOutput $govulnStatus $govulnColor
253315
}
254316

255317
# Main execution
@@ -263,8 +325,10 @@ switch ($Command.ToLower()) {
263325
"staticcheck" { Invoke-StaticCheck }
264326
"errcheck" { Invoke-ErrCheck }
265327
"gosec" { Invoke-GoSec }
328+
"govulcheck" { Invoke-GovulnCheck }
266329
"lint" { Invoke-Lint }
267330
"security" { Invoke-Security }
331+
"fuzz" { Invoke-Fuzz }
268332
"check" { Invoke-Check }
269333
"check-race" { Invoke-CheckRace }
270334
"tools" { Invoke-Tools }

changelog/v1.1.1.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Changelog - Version 1.1.1
2+
3+
## Release Date
4+
2025-10-17
5+
6+
## Overview
7+
Security and robustness enhancement release adding comprehensive fuzz testing and vulnerability scanning to strengthen error handling reliability.
8+
9+
## New
10+
- Complete fuzz testing suite with 8 comprehensive test functions
11+
- Vulnerability scanning with govulncheck integration
12+
- Enhanced dependency verification with `go mod verify`
13+
- Improved build tooling with security-focused Makefiles
14+
15+
## Security Enhancements
16+
- FuzzNew, FuzzNewWithField, FuzzWrap - Input validation fuzzing
17+
- FuzzJSONMarshal - JSON serialization robustness testing
18+
- FuzzValidateErrorCode - Error code validation fuzzing
19+
- FuzzStacktrace - Stack trace handling edge case testing
20+
- FuzzWithMethods, FuzzHasCode - API method robustness validation
21+
- Vulnerability scanning integrated into CI/CD pipeline
22+
23+
## Build & Development
24+
- Enhanced Makefile with `fuzz`, `govulcheck`, and improved `deps` targets
25+
- Cross-platform Makefile.ps1 with equivalent Windows PowerShell support
26+
- CI/CD workflows updated with vulnerability scanning
27+
- Comprehensive tool status reporting
28+
29+
## Quality Assurance
30+
- Randomized input testing protecting against edge case failures
31+
- UTF-8 validation for all string outputs
32+
- Panic prevention validation across all public APIs
33+
- Enhanced error chain validation testing
34+
35+
## Compatibility
36+
- Maintains full backward compatibility with v1.1.0
37+
- No breaking changes to public API
38+
- Enhanced reliability through comprehensive edge case coverage
39+
- Zero additional runtime dependencies
40+
41+
## Performance
42+
- Fuzz testing validates performance under randomized stress conditions
43+
- No performance degradation from security enhancements
44+
- Efficient fuzz test execution optimized for CI environments

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
// // After
172172
// return errors.Wrap(err, ErrCodeOperation, "operation failed")
173173
//
174-
// Copyright (c) 2025 AGILira
174+
// Copyright (c) 2025 AGILira - A. Giordano
175175
// Series: an AGLIra library
176176
// SPDX-License-Identifier: MPL-2.0
177177
package errors

0 commit comments

Comments
 (0)