From a9a75cd4cf8d24cf326e39ac1bbadafc164a5d3f Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 14 Dec 2016 00:07:48 -0500 Subject: [PATCH] Add a test for selecting images to be scanned --- test/test_secscan.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test_secscan.py b/test/test_secscan.py index c2d1bbb08..737b6ba9e 100644 --- a/test/test_secscan.py +++ b/test/test_secscan.py @@ -10,6 +10,7 @@ from util.secscan.api import SecurityScannerAPI, AnalyzeLayerException from util.secscan.analyzer import LayerAnalyzer from util.secscan.notifier import process_notification_data from data import model +from data.database import Image from workers.security_notification_worker import SecurityNotificationWorker from endpoints.v2 import v2_bp @@ -587,6 +588,20 @@ class TestSecurityScanner(unittest.TestCase): self.assertFalse(VulnerabilityFoundEvent().should_perform(event_data, notification)) + def test_select_images_to_scan(self): + # Set all images to have a security index of a version to that of the config. + expected_version = app.config['SECURITY_SCANNER_ENGINE_VERSION_TARGET'] + Image.update(security_indexed_engine=expected_version).execute() + + # Ensure no images are available for scanning. + self.assertIsNone(model.image.get_min_id_for_sec_scan(expected_version)) + self.assertTrue(len(model.image.get_images_eligible_for_scan(expected_version)) == 0) + + # Check for a higher version. + self.assertIsNotNone(model.image.get_min_id_for_sec_scan(expected_version + 1)) + self.assertTrue(len(model.image.get_images_eligible_for_scan(expected_version + 1)) > 0) + + def test_notification_worker(self): pages_called = []