Skip to content

Commit 9056d14

Browse files
refactor: format code with gofmt and improve test mocks
- Ran gofmt across codebase to fix formatting inconsistencies - Fixed import ordering (gofmt standard) - Aligned struct field indentation - Fixed multi-line expression alignment Test improvements: - Enhanced mockResultStore with proper state management - Added savedFindingsByScan and savedScans maps for realistic storage - Added savedEvents tracking for scan event verification - Implemented proper mock methods that return stored data instea
1 parent e69ac54 commit 9056d14

131 files changed

Lines changed: 1103 additions & 812 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/auth_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ func TestAuthDiscoverCommand(t *testing.T) {
112112
}
113113

114114
// Execute command
115-
err := cmd.RunE(cmd, []string{tt.target})
115+
args := []string{}
116+
if tt.target != "" {
117+
args = []string{tt.target}
118+
}
119+
120+
err := cmd.RunE(cmd, args)
116121

117122
// Restore stdout
118123
w.Close()

cmd/boileau.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12-
"github.com/CodeMonkeyCybersecurity/artemis/pkg/cli/adapters"
1312
"github.com/CodeMonkeyCybersecurity/artemis/pkg/boileau"
13+
"github.com/CodeMonkeyCybersecurity/artemis/pkg/cli/adapters"
1414
"github.com/CodeMonkeyCybersecurity/artemis/pkg/types"
1515
"github.com/spf13/cobra"
1616
)

cmd/cert_enhanced_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"context"
66
"fmt"
77
"strings"
8-
"time"
98
"testing"
9+
"time"
1010

1111
"github.com/CodeMonkeyCybersecurity/artemis/internal/config"
1212
"github.com/CodeMonkeyCybersecurity/artemis/internal/logger"
@@ -33,9 +33,9 @@ func TestCertEnhanced(t *testing.T) {
3333

3434
// Test with multiple domains
3535
testDomains := []string{
36-
"anthropic.com", // AI company
37-
"github.com", // Should have many SANs
38-
"cloudflare.com", // CDN with many properties
36+
"anthropic.com", // AI company
37+
"github.com", // Should have many SANs
38+
"cloudflare.com", // CDN with many properties
3939
}
4040

4141
for _, domain := range testDomains {

cmd/certificate_discovery_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ func TestCertificateDiscovery(t *testing.T) {
3838

3939
// Setup organization correlator with all features enabled
4040
corrCfg := correlation.CorrelatorConfig{
41-
EnableWhois: true,
42-
EnableCerts: true,
43-
EnableASN: true,
41+
EnableWhois: true,
42+
EnableCerts: true,
43+
EnableASN: true,
4444
EnableLinkedIn: false, // Skip for this test
45-
EnableGitHub: false, // Skip for this test
46-
CacheTTL: 1 * time.Hour,
45+
EnableGitHub: false, // Skip for this test
46+
CacheTTL: 1 * time.Hour,
4747
}
4848

4949
fmt.Println("📊 Configuration:")

cmd/internal/converters/findings.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,18 @@ func buildCorrelationSolution(insight correlation.CorrelatedInsight) string {
375375

376376
func getNetworkAuthCount(networkAuth *authdiscovery.NetworkAuthMethods) int {
377377
return len(networkAuth.SSH) + len(networkAuth.RDP) +
378-
len(networkAuth.Kerberos) + len(networkAuth.LDAP) +
379-
len(networkAuth.RADIUS) + len(networkAuth.SMB) +
380-
len(networkAuth.SMTP) + len(networkAuth.IMAP)
378+
len(networkAuth.Kerberos) + len(networkAuth.LDAP) +
379+
len(networkAuth.RADIUS) + len(networkAuth.SMB) +
380+
len(networkAuth.SMTP) + len(networkAuth.IMAP)
381381
}
382382

383383
func getWebAuthCount(webAuth *authdiscovery.WebAuthMethods) int {
384384
return len(webAuth.FormLogin) + len(webAuth.BasicAuth) +
385-
len(webAuth.OAuth2) + len(webAuth.SAML) +
386-
len(webAuth.OIDC) + len(webAuth.WebAuthn) +
387-
len(webAuth.CAS) + len(webAuth.JWT) +
388-
len(webAuth.NTLM) + len(webAuth.Cookies) +
389-
len(webAuth.Headers)
385+
len(webAuth.OAuth2) + len(webAuth.SAML) +
386+
len(webAuth.OIDC) + len(webAuth.WebAuthn) +
387+
len(webAuth.CAS) + len(webAuth.JWT) +
388+
len(webAuth.NTLM) + len(webAuth.Cookies) +
389+
len(webAuth.Headers)
390390
}
391391

392392
func getAPIAuthCount(apiAuth *authdiscovery.APIAuthMethods) int {

cmd/internal/converters/findings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func TestBuildSecretSolution(t *testing.T) {
305305
func contains(s, substr string) bool {
306306
return len(s) >= len(substr) && (s == substr || len(s) > len(substr) &&
307307
(s[:len(substr)] == substr || s[len(s)-len(substr):] == substr ||
308-
containsSubstring(s, substr)))
308+
containsSubstring(s, substr)))
309309
}
310310

311311
func containsSubstring(s, substr string) bool {

cmd/orchestrator/orchestrator_test.go

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@ type mockResultStore struct {
2525
updateScanCalled bool
2626
saveFindingsCalled bool
2727
savedFindings []types.Finding
28+
savedFindingsByScan map[string][]types.Finding
29+
savedScans map[string]*types.ScanRequest
2830
scanID string
2931
err error
3032
returnScan *types.ScanRequest
3133
returnFindings []types.Finding
3234
savedCorrelation map[string][]types.CorrelationResult
3335
savedCorrelationType map[string][]types.CorrelationResult
36+
savedEvents []storedScanEvent
37+
}
38+
39+
type storedScanEvent struct {
40+
scanID string
41+
eventType string
42+
component string
43+
message string
44+
metadata map[string]interface{}
3445
}
3546

3647
func (m *mockResultStore) ensureCorrelationMaps() {
@@ -42,61 +53,174 @@ func (m *mockResultStore) ensureCorrelationMaps() {
4253
}
4354
}
4455

56+
func (m *mockResultStore) ensureStorage() {
57+
if m.savedFindingsByScan == nil {
58+
m.savedFindingsByScan = make(map[string][]types.Finding)
59+
}
60+
if m.savedScans == nil {
61+
m.savedScans = make(map[string]*types.ScanRequest)
62+
}
63+
}
64+
4565
func (m *mockResultStore) SaveScan(ctx context.Context, scan *types.ScanRequest) error {
4666
m.saveScanCalled = true
67+
m.ensureStorage()
68+
if scan != nil {
69+
m.savedScans[scan.ID] = scan
70+
}
4771
return m.err
4872
}
4973

5074
func (m *mockResultStore) UpdateScan(ctx context.Context, scan *types.ScanRequest) error {
5175
m.updateScanCalled = true
76+
m.ensureStorage()
77+
if scan != nil {
78+
m.savedScans[scan.ID] = scan
79+
}
5280
return m.err
5381
}
5482

5583
func (m *mockResultStore) GetScan(ctx context.Context, scanID string) (*types.ScanRequest, error) {
5684
m.scanID = scanID
85+
m.ensureStorage()
86+
if scan, ok := m.savedScans[scanID]; ok {
87+
return scan, m.err
88+
}
5789
return m.returnScan, m.err
5890
}
5991

6092
func (m *mockResultStore) ListScans(ctx context.Context, filter core.ScanFilter) ([]*types.ScanRequest, error) {
93+
m.ensureStorage()
6194
return []*types.ScanRequest{m.returnScan}, m.err
6295
}
6396

6497
func (m *mockResultStore) SaveFindings(ctx context.Context, findings []types.Finding) error {
6598
m.saveFindingsCalled = true
6699
m.savedFindings = append(m.savedFindings, findings...)
100+
m.ensureStorage()
101+
if len(findings) > 0 {
102+
scanID := findings[0].ScanID
103+
m.savedFindingsByScan[scanID] = append(m.savedFindingsByScan[scanID], findings...)
104+
}
67105
return m.err
68106
}
69107

70108
func (m *mockResultStore) GetFindings(ctx context.Context, scanID string) ([]types.Finding, error) {
71109
m.scanID = scanID
110+
m.ensureStorage()
111+
if stored, ok := m.savedFindingsByScan[scanID]; ok {
112+
return stored, m.err
113+
}
72114
return m.returnFindings, m.err
73115
}
74116

75117
func (m *mockResultStore) GetFindingsBySeverity(ctx context.Context, severity types.Severity) ([]types.Finding, error) {
118+
m.ensureStorage()
119+
results := make([]types.Finding, 0)
120+
for _, findings := range m.savedFindingsByScan {
121+
for _, f := range findings {
122+
if f.Severity == severity {
123+
results = append(results, f)
124+
}
125+
}
126+
}
127+
if len(results) > 0 {
128+
return results, m.err
129+
}
76130
return m.returnFindings, m.err
77131
}
78132

79133
func (m *mockResultStore) QueryFindings(ctx context.Context, query core.FindingQuery) ([]types.Finding, error) {
134+
m.ensureStorage()
135+
results := make([]types.Finding, 0)
136+
for scanID, findings := range m.savedFindingsByScan {
137+
if query.ScanID != "" && query.ScanID != scanID {
138+
continue
139+
}
140+
results = append(results, findings...)
141+
}
142+
if len(results) > 0 {
143+
return results, m.err
144+
}
80145
return m.returnFindings, m.err
81146
}
82147

83148
func (m *mockResultStore) GetFindingStats(ctx context.Context) (*core.FindingStats, error) {
84-
return &core.FindingStats{}, m.err
149+
m.ensureStorage()
150+
stats := &core.FindingStats{
151+
Total: 0,
152+
BySeverity: make(map[types.Severity]int),
153+
ByTool: make(map[string]int),
154+
ByType: make(map[string]int),
155+
}
156+
for _, findings := range m.savedFindingsByScan {
157+
stats.Total += len(findings)
158+
for _, f := range findings {
159+
stats.BySeverity[f.Severity]++
160+
stats.ByTool[f.Tool]++
161+
stats.ByType[f.Type]++
162+
}
163+
}
164+
return stats, m.err
85165
}
86166

87167
func (m *mockResultStore) GetRecentCriticalFindings(ctx context.Context, limit int) ([]types.Finding, error) {
168+
m.ensureStorage()
169+
results := make([]types.Finding, 0)
170+
for _, findings := range m.savedFindingsByScan {
171+
for _, f := range findings {
172+
if f.Severity == types.SeverityCritical {
173+
results = append(results, f)
174+
}
175+
}
176+
}
177+
if len(results) > limit && limit > 0 {
178+
results = results[:limit]
179+
}
180+
if len(results) > 0 {
181+
return results, m.err
182+
}
88183
return m.returnFindings, m.err
89184
}
90185

91186
func (m *mockResultStore) SearchFindings(ctx context.Context, searchTerm string, limit int) ([]types.Finding, error) {
187+
m.ensureStorage()
188+
results := make([]types.Finding, 0)
189+
for _, findings := range m.savedFindingsByScan {
190+
results = append(results, findings...)
191+
}
192+
if len(results) > limit && limit > 0 {
193+
results = results[:limit]
194+
}
195+
if len(results) > 0 {
196+
return results, m.err
197+
}
92198
return m.returnFindings, m.err
93199
}
94200

95201
func (m *mockResultStore) GetSummary(ctx context.Context, scanID string) (*types.Summary, error) {
96-
return &types.Summary{}, m.err
202+
m.ensureStorage()
203+
summary := &types.Summary{
204+
BySeverity: make(map[types.Severity]int),
205+
ByTool: make(map[string]int),
206+
}
207+
findings := m.savedFindingsByScan[scanID]
208+
summary.Total = len(findings)
209+
for _, f := range findings {
210+
summary.BySeverity[f.Severity]++
211+
summary.ByTool[f.Tool]++
212+
}
213+
return summary, m.err
97214
}
98215

99216
func (m *mockResultStore) SaveScanEvent(ctx context.Context, scanID string, eventType string, component string, message string, metadata map[string]interface{}) error {
217+
m.savedEvents = append(m.savedEvents, storedScanEvent{
218+
scanID: scanID,
219+
eventType: eventType,
220+
component: component,
221+
message: message,
222+
metadata: metadata,
223+
})
100224
return m.err
101225
}
102226

0 commit comments

Comments
 (0)