Merge pull request #2234 from coreos-inc/select-image-test

Add a test for selecting images to be scanned
This commit is contained in:
josephschorr 2016-12-14 00:34:27 -05:00 committed by GitHub
commit 2a6632cff4

View file

@ -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 = []