1
+ import json
2
+
1
3
from datetime import datetime
2
4
from time import sleep , time
3
5
9
11
10
12
from test .test_utils import get_framework_and_version_from_tag
11
13
from test .test_utils import ecr as ecr_utils
14
+ from test .test_utils .ecr import CVESeverity
12
15
13
16
14
17
@pytest .mark .model ("N/A" )
@@ -50,11 +53,7 @@ def test_ecr_scan(image, ecr_client):
50
53
:param image: str Image URI for image to be tested
51
54
:param ecr_client: boto3 Client for ECR
52
55
"""
53
- # TODO: Unskip this test for TF 2.4.1 images
54
- framework , version = get_framework_and_version_from_tag (image )
55
- if framework == "tensorflow" and Version (version ) == Version ("2.4.1" ):
56
- pytest .skip ("Skip ECR Scan on TF 2.4.1 DLC images" )
57
-
56
+ minimum_sev_threshold = "HIGH"
58
57
scan_status = None
59
58
start_time = time ()
60
59
ecr_utils .start_ecr_image_scan (ecr_client , image )
@@ -68,6 +67,10 @@ def test_ecr_scan(image, ecr_client):
68
67
if scan_status != "COMPLETE" :
69
68
raise TimeoutError (f"ECR Scan is still in { scan_status } state. Exiting." )
70
69
severity_counts = ecr_utils .get_ecr_image_scan_severity_count (ecr_client , image )
71
- assert not (
72
- severity_counts .get ("HIGH" , 0 ) or severity_counts .get ("CRITICAL" , 0 )
73
- ), f"Found vulnerabilities in image { image } : { str (severity_counts )} "
70
+ scan_results = ecr_utils .get_ecr_image_scan_results (ecr_client , image , minimum_vulnerability = minimum_sev_threshold )
71
+ assert all (
72
+ count == 0 for sev , count in severity_counts .items () if CVESeverity [sev ] >= CVESeverity [minimum_sev_threshold ]
73
+ ), (
74
+ f"Found vulnerabilities in image { image } : { str (severity_counts )} \n "
75
+ f"Vulnerabilities: { json .dumps (scan_results , indent = 4 )} "
76
+ )
0 commit comments