@@ -44,3 +44,308 @@ impl Display for MarkdownData {
4444        ) 
4545    } 
4646} 
47+ 
48+ #[ cfg( test) ]  
49+ mod  test { 
50+     use  super :: super :: markdown_fixable_package_table:: { 
51+         FixablePackage ,  FixablePackageTable ,  FixablePackageVulnerabilities , 
52+     } ; 
53+     use  super :: super :: markdown_policy_evaluated_table:: { PolicyEvaluated ,  PolicyEvaluatedTable } ; 
54+     use  super :: super :: markdown_summary:: MarkdownSummary ; 
55+     use  super :: super :: markdown_summary_table:: MarkdownSummaryTable ; 
56+     use  super :: super :: markdown_vulnerability_evaluated_table:: { 
57+         VulnerabilityEvaluated ,  VulnerabilityEvaluatedTable , 
58+     } ; 
59+ 
60+     use  super :: * ; 
61+ 
62+     #[ test]  
63+     fn  converts_markdown_data_to_markdown_text ( )  { 
64+         let  markdown_data = MarkdownData  { 
65+             summary :  MarkdownSummary  { 
66+                 pull_string :  "ubuntu:23.04" . to_string ( ) , 
67+                 image_id :  "sha256:f4cdeba72b994748f5eb1f525a70a9cc553b66037ec37e23645fbf3f0f5c160d" 
68+                     . to_string ( ) , 
69+                 digest :  "sha256:5a828e28de105c3d7821c4442f0f5d1c52dc16acf4999d5f31a3bc0f03f06edd" 
70+                     . to_string ( ) , 
71+                 base_os :  "ubuntu 23.04" . to_string ( ) , 
72+ 
73+                 total_vulns_found :  MarkdownSummaryTable  { 
74+                     total_found :  11 , 
75+                     critical :  0 , 
76+                     critical_fixable :  0 , 
77+                     high :  0 , 
78+                     high_fixable :  0 , 
79+                     medium :  9 , 
80+                     medium_fixable :  9 , 
81+                     low :  2 , 
82+                     low_fixable :  2 , 
83+                     negligible :  0 , 
84+                     negligible_fixable :  0 , 
85+                 } , 
86+             } , 
87+             fixable_packages :  FixablePackageTable ( vec ! [ 
88+                 FixablePackage  { 
89+                     name:  "libgnutls30" . to_string( ) , 
90+                     package_type:  "os" . to_string( ) , 
91+                     version:  "3.7.8-5ubuntu1.1" . to_string( ) , 
92+                     suggested_fix:  Some ( "3.7.8-5ubuntu1.2" . to_string( ) ) , 
93+                     vulnerabilities:  FixablePackageVulnerabilities  { 
94+                         critical:  0 , 
95+                         high:  0 , 
96+                         medium:  2 , 
97+                         low:  0 , 
98+                         negligible:  0 , 
99+                     } , 
100+                     exploits:  0 , 
101+                 } , 
102+                 FixablePackage  { 
103+                     name:  "libc-bin" . to_string( ) , 
104+                     package_type:  "os" . to_string( ) , 
105+                     version:  "2.37-0ubuntu2.1" . to_string( ) , 
106+                     suggested_fix:  Some ( "2.37-0ubuntu2.2" . to_string( ) ) , 
107+                     vulnerabilities:  FixablePackageVulnerabilities  { 
108+                         critical:  0 , 
109+                         high:  0 , 
110+                         medium:  1 , 
111+                         low:  1 , 
112+                         negligible:  0 , 
113+                     } , 
114+                     exploits:  0 , 
115+                 } , 
116+                 FixablePackage  { 
117+                     name:  "libc6" . to_string( ) , 
118+                     package_type:  "os" . to_string( ) , 
119+                     version:  "2.37-0ubuntu2.1" . to_string( ) , 
120+                     suggested_fix:  Some ( "2.37-0ubuntu2.2" . to_string( ) ) , 
121+                     vulnerabilities:  FixablePackageVulnerabilities  { 
122+                         critical:  0 , 
123+                         high:  0 , 
124+                         medium:  1 , 
125+                         low:  1 , 
126+                         negligible:  0 , 
127+                     } , 
128+                     exploits:  0 , 
129+                 } , 
130+                 FixablePackage  { 
131+                     name:  "libpam-modules" . to_string( ) , 
132+                     package_type:  "os" . to_string( ) , 
133+                     version:  "1.5.2-5ubuntu1" . to_string( ) , 
134+                     suggested_fix:  Some ( "1.5.2-5ubuntu1.1" . to_string( ) ) , 
135+                     vulnerabilities:  FixablePackageVulnerabilities  { 
136+                         critical:  0 , 
137+                         high:  0 , 
138+                         medium:  1 , 
139+                         low:  0 , 
140+                         negligible:  0 , 
141+                     } , 
142+                     exploits:  0 , 
143+                 } , 
144+                 FixablePackage  { 
145+                     name:  "libpam-modules-bin" . to_string( ) , 
146+                     package_type:  "os" . to_string( ) , 
147+                     version:  "1.5.2-5ubuntu1" . to_string( ) , 
148+                     suggested_fix:  Some ( "1.5.2-5ubuntu1.1" . to_string( ) ) , 
149+                     vulnerabilities:  FixablePackageVulnerabilities  { 
150+                         critical:  0 , 
151+                         high:  0 , 
152+                         medium:  1 , 
153+                         low:  0 , 
154+                         negligible:  0 , 
155+                     } , 
156+                     exploits:  0 , 
157+                 } , 
158+                 FixablePackage  { 
159+                     name:  "libpam-runtime" . to_string( ) , 
160+                     package_type:  "os" . to_string( ) , 
161+                     version:  "1.5.2-5ubuntu1" . to_string( ) , 
162+                     suggested_fix:  Some ( "1.5.2-5ubuntu1.1" . to_string( ) ) , 
163+                     vulnerabilities:  FixablePackageVulnerabilities  { 
164+                         critical:  0 , 
165+                         high:  0 , 
166+                         medium:  1 , 
167+                         low:  0 , 
168+                         negligible:  0 , 
169+                     } , 
170+                     exploits:  0 , 
171+                 } , 
172+                 FixablePackage  { 
173+                     name:  "libpam0g" . to_string( ) , 
174+                     package_type:  "os" . to_string( ) , 
175+                     version:  "1.5.2-5ubuntu1" . to_string( ) , 
176+                     suggested_fix:  Some ( "1.5.2-5ubuntu1.1" . to_string( ) ) , 
177+                     vulnerabilities:  FixablePackageVulnerabilities  { 
178+                         critical:  0 , 
179+                         high:  0 , 
180+                         medium:  1 , 
181+                         low:  0 , 
182+                         negligible:  0 , 
183+                     } , 
184+                     exploits:  0 , 
185+                 } , 
186+                 FixablePackage  { 
187+                     name:  "tar" . to_string( ) , 
188+                     package_type:  "os" . to_string( ) , 
189+                     version:  "1.34+dfsg-1.2ubuntu0.1" . to_string( ) , 
190+                     suggested_fix:  Some ( "1.34+dfsg-1.2ubuntu0.2" . to_string( ) ) , 
191+                     vulnerabilities:  FixablePackageVulnerabilities  { 
192+                         critical:  0 , 
193+                         high:  0 , 
194+                         medium:  1 , 
195+                         low:  0 , 
196+                         negligible:  0 , 
197+                     } , 
198+                     exploits:  0 , 
199+                 } , 
200+             ] ) , 
201+             policies :  PolicyEvaluatedTable ( vec ! [ 
202+                 PolicyEvaluated  { 
203+                     name:  "carholder policy - pk" . to_string( ) , 
204+                     passed:  false , 
205+                     failures:  1 , 
206+                     risks_accepted:  0 , 
207+                 } , 
208+                 PolicyEvaluated  { 
209+                     name:  "Critical Vulnerability Found" . to_string( ) , 
210+                     passed:  true , 
211+                     failures:  0 , 
212+                     risks_accepted:  0 , 
213+                 } , 
214+                 PolicyEvaluated  { 
215+                     name:  "Forbid Secrets in Images" . to_string( ) , 
216+                     passed:  true , 
217+                     failures:  0 , 
218+                     risks_accepted:  0 , 
219+                 } , 
220+                 PolicyEvaluated  { 
221+                     name:  "NIST SP 800-Star" . to_string( ) , 
222+                     passed:  false , 
223+                     failures:  14 , 
224+                     risks_accepted:  0 , 
225+                 } , 
226+                 PolicyEvaluated  { 
227+                     name:  "PolicyCardHolder" . to_string( ) , 
228+                     passed:  false , 
229+                     failures:  1 , 
230+                     risks_accepted:  0 , 
231+                 } , 
232+                 PolicyEvaluated  { 
233+                     name:  "Sensitive Information or Secret Found" . to_string( ) , 
234+                     passed:  true , 
235+                     failures:  0 , 
236+                     risks_accepted:  0 , 
237+                 } , 
238+                 PolicyEvaluated  { 
239+                     name:  "Sysdig Best Practices" . to_string( ) , 
240+                     passed:  true , 
241+                     failures:  0 , 
242+                     risks_accepted:  0 , 
243+                 } , 
244+             ] ) , 
245+ 
246+             vulnerabilities :  VulnerabilityEvaluatedTable ( vec ! [ 
247+                 VulnerabilityEvaluated  { 
248+                     cve:  "CVE-2023-39804" . to_string( ) , 
249+                     severity:  "Medium" . to_string( ) , 
250+                     packages_found:  1 , 
251+                     fixable:  true , 
252+                     exploitable:  false , 
253+                     accepted_risk:  false , 
254+                 } , 
255+                 VulnerabilityEvaluated  { 
256+                     cve:  "CVE-2023-4806" . to_string( ) , 
257+                     severity:  "Low" . to_string( ) , 
258+                     packages_found:  2 , 
259+                     fixable:  true , 
260+                     exploitable:  false , 
261+                     accepted_risk:  false , 
262+                 } , 
263+                 VulnerabilityEvaluated  { 
264+                     cve:  "CVE-2023-5156" . to_string( ) , 
265+                     severity:  "Medium" . to_string( ) , 
266+                     packages_found:  2 , 
267+                     fixable:  true , 
268+                     exploitable:  false , 
269+                     accepted_risk:  false , 
270+                 } , 
271+                 VulnerabilityEvaluated  { 
272+                     cve:  "CVE-2024-0553" . to_string( ) , 
273+                     severity:  "Medium" . to_string( ) , 
274+                     packages_found:  1 , 
275+                     fixable:  true , 
276+                     exploitable:  false , 
277+                     accepted_risk:  false , 
278+                 } , 
279+                 VulnerabilityEvaluated  { 
280+                     cve:  "CVE-2024-0567" . to_string( ) , 
281+                     severity:  "Medium" . to_string( ) , 
282+                     packages_found:  1 , 
283+                     fixable:  true , 
284+                     exploitable:  false , 
285+                     accepted_risk:  false , 
286+                 } , 
287+                 VulnerabilityEvaluated  { 
288+                     cve:  "CVE-2024-22365" . to_string( ) , 
289+                     severity:  "Medium" . to_string( ) , 
290+                     packages_found:  4 , 
291+                     fixable:  true , 
292+                     exploitable:  false , 
293+                     accepted_risk:  false , 
294+                 } , 
295+             ] ) , 
296+         } ; 
297+         let  expected_markdown_output = r#"## Sysdig Scan Result 
298+ ### Summary 
299+ * **PullString**: ubuntu:23.04 
300+ * **ImageID**: `sha256:f4cdeba72b994748f5eb1f525a70a9cc553b66037ec37e23645fbf3f0f5c160d` 
301+ * **Digest**: `sha256:5a828e28de105c3d7821c4442f0f5d1c52dc16acf4999d5f31a3bc0f03f06edd` 
302+ * **BaseOS**: ubuntu 23.04 
303+ 
304+ | TOTAL VULNS FOUND | CRITICAL | HIGH | MEDIUM      | LOW         | NEGLIGIBLE | 
305+ | :-------------: | :----: | :-: | :---------: | :---------: | :------: | 
306+ | 11              | 0      | 0   | 9 (9 Fixable) | 2 (2 Fixable) | 0        | 
307+ 
308+ 
309+ ### Fixable Packages 
310+ | PACKAGE          | TYPE | VERSION              | SUGGESTED FIX        | CRITICAL | HIGH | MEDIUM | LOW | NEGLIGIBLE | EXPLOIT | 
311+ | :--------------- | :-: | :------------------- | :------------------- | :----: | :-: | :--: | :-: | :------: | :---: | 
312+ | libgnutls30      | os  | 3.7.8-5ubuntu1.1     | 3.7.8-5ubuntu1.2     | -      | -   | 2    | -   | -        | -     | 
313+ | libc-bin         | os  | 2.37-0ubuntu2.1      | 2.37-0ubuntu2.2      | -      | -   | 1    | 1   | -        | -     | 
314+ | libc6            | os  | 2.37-0ubuntu2.1      | 2.37-0ubuntu2.2      | -      | -   | 1    | 1   | -        | -     | 
315+ | libpam-modules   | os  | 1.5.2-5ubuntu1       | 1.5.2-5ubuntu1.1     | -      | -   | 1    | -   | -        | -     | 
316+ | libpam-modules-bin | os  | 1.5.2-5ubuntu1       | 1.5.2-5ubuntu1.1     | -      | -   | 1    | -   | -        | -     | 
317+ | libpam-runtime   | os  | 1.5.2-5ubuntu1       | 1.5.2-5ubuntu1.1     | -      | -   | 1    | -   | -        | -     | 
318+ | libpam0g         | os  | 1.5.2-5ubuntu1       | 1.5.2-5ubuntu1.1     | -      | -   | 1    | -   | -        | -     | 
319+ | tar              | os  | 1.34+dfsg-1.2ubuntu0.1 | 1.34+dfsg-1.2ubuntu0.2 | -      | -   | 1    | -   | -        | -     | 
320+ 
321+ 
322+ ### Policy Evaluation 
323+ 
324+ | POLICY                              | STATUS | FAILURES | RISKS ACCEPTED | 
325+ | :---------------------------------- | :--: | :----: | :----------: | 
326+ | carholder policy - pk               | ❌   | 1      | 0            | 
327+ | Critical Vulnerability Found        | ✅   | 0      | 0            | 
328+ | Forbid Secrets in Images            | ✅   | 0      | 0            | 
329+ | NIST SP 800-Star                    | ❌   | 14     | 0            | 
330+ | PolicyCardHolder                    | ❌   | 1      | 0            | 
331+ | Sensitive Information or Secret Found | ✅   | 0      | 0            | 
332+ | Sysdig Best Practices               | ✅   | 0      | 0            | 
333+ 
334+ 
335+ ### Vulnerability Detail 
336+ 
337+ | VULN CVE     | SEVERITY | PACKAGES | FIXABLE | EXPLOITABLE | ACCEPTED RISK | 
338+ | :----------- | :----- | :----- | :---- | :-------- | :---------- | 
339+ | CVE-2023-39804 | Medium | 1      | ✅    | ❌        | ❌          | 
340+ | CVE-2023-4806 | Low    | 2      | ✅    | ❌        | ❌          | 
341+ | CVE-2023-5156 | Medium | 2      | ✅    | ❌        | ❌          | 
342+ | CVE-2024-0553 | Medium | 1      | ✅    | ❌        | ❌          | 
343+ | CVE-2024-0567 | Medium | 1      | ✅    | ❌        | ❌          | 
344+ | CVE-2024-22365 | Medium | 4      | ✅    | ❌        | ❌          |"# ; 
345+ 
346+         assert_eq ! ( 
347+             markdown_data. to_string( ) . trim( ) , 
348+             expected_markdown_output. trim( ) 
349+         ) ; 
350+     } 
351+ } 
0 commit comments