@@ -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
3647func (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+
4565func (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
5074func (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
5583func (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
6092func (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
6497func (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
70108func (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
75117func (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
79133func (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
83148func (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
87167func (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
91186func (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
95201func (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
99216func (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