Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deletion in some ingest cases #14

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Support deletion in some ingest cases
  • Loading branch information
credbbl committed Nov 29, 2023
commit 2469b32789c1938d09f87d60686f3991434df9c2
3 changes: 2 additions & 1 deletion src/glvd/cli/ingest_debsec.py
Original file line number Diff line number Diff line change
@@ -52,10 +52,11 @@ async def import_cve_update(

new_entries = file_cve.get(entry.dist.deb_codename)
if not new_entries:
await session.delete(entry)
continue
new_entry = new_entries.pop((entry.cve_id, entry.deb_source), None)
if not new_entry:
# XXX: Delete entry
await session.delete(entry)
continue

# Update object in place. Only real changes will be commited
2 changes: 1 addition & 1 deletion src/glvd/cli/ingest_debsrc.py
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ async def import_update(

new_entry = file.pop(entry.deb_source, None)
if not new_entry:
# XXX: Delete entry
await session.delete(entry)
continue

# Update object in place. Only real changes will be commited
87 changes: 82 additions & 5 deletions tests/cli/test_ingest_debsec.py
Original file line number Diff line number Diff line change
@@ -18,21 +18,26 @@ async def test_import_cve_insert(self, db_session_class):
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='2',
)
),
('TEST-2', 'hello'): DebsecCve(
cve_id='TEST-2',
deb_source='hello',
deb_version_fixed='2',
),
}
f['bookworm'] = {
('TEST-1', 'hello'): DebsecCve(
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='1',
)
),
}

ingest = IngestDebsec('debian', None)
await ingest.import_cve_insert(db_session_class, f)

r = (await db_session_class.execute(select(DebsecCve).order_by(DebsecCve.cve_id, DebsecCve.deb_version_fixed))).all()
assert len(r) == 2
assert len(r) == 3
t = r.pop(0)[0]
assert t.cve_id == 'TEST-1'
assert t.dist.cpe_version == '12'
@@ -45,21 +50,72 @@ async def test_import_cve_insert(self, db_session_class):
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '2'

t = r.pop(0)[0]
assert t.cve_id == 'TEST-2'
assert t.dist.cpe_version == ''
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '2'

async def test_import_cve_update(self, db_session_class):
f = DebsecCveFile()
f[''] = {
('TEST-1', 'hello'): DebsecCve(
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='3',
)
),
('TEST-2', 'hello'): DebsecCve(
cve_id='TEST-2',
deb_source='hello',
deb_version_fixed='3',
),
}
f['bookworm'] = {
('TEST-1', 'hello'): DebsecCve(
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='1',
)
),
}

ingest = IngestDebsec('debian', None)
await ingest.import_cve_update(db_session_class, f)

r = (await db_session_class.execute(select(DebsecCve).order_by(DebsecCve.cve_id, DebsecCve.deb_version_fixed))).all()
assert len(r) == 3
t = r.pop(0)[0]
assert t.cve_id == 'TEST-1'
assert t.dist.cpe_version == '12'
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '1'

t = r.pop(0)[0]
assert t.cve_id == 'TEST-1'
assert t.dist.cpe_version == ''
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '3'

t = r.pop(0)[0]
assert t.cve_id == 'TEST-2'
assert t.dist.cpe_version == ''
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '3'

async def test_import_cve_delete_entry(self, db_session_class):
f = DebsecCveFile()
f[''] = {
('TEST-1', 'hello'): DebsecCve(
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='3',
),
}
f['bookworm'] = {
('TEST-1', 'hello'): DebsecCve(
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='1',
),
}

ingest = IngestDebsec('debian', None)
@@ -78,3 +134,24 @@ async def test_import_cve_update(self, db_session_class):
assert t.dist.cpe_version == ''
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '3'

async def test_import_cve_delete_dist(self, db_session_class):
f = DebsecCveFile()
f['bookworm'] = {
('TEST-1', 'hello'): DebsecCve(
cve_id='TEST-1',
deb_source='hello',
deb_version_fixed='1',
),
}

ingest = IngestDebsec('debian', None)
await ingest.import_cve_update(db_session_class, f)

r = (await db_session_class.execute(select(DebsecCve).order_by(DebsecCve.cve_id, DebsecCve.deb_version_fixed))).all()
assert len(r) == 1
t = r.pop(0)[0]
assert t.cve_id == 'TEST-1'
assert t.dist.cpe_version == '12'
assert t.deb_source == 'hello'
assert t.deb_version_fixed == '1'
17 changes: 17 additions & 0 deletions tests/cli/test_ingest_debsrc.py
Original file line number Diff line number Diff line change
@@ -62,3 +62,20 @@ async def test_import_update(self, db_session_class):
assert t.dist.cpe_version == '12'
assert t.deb_source == 'test2'
assert t.deb_version == '3'

async def test_import_delete(self, db_session_class):
f = DebsrcFile()
f['test1'] = Debsrc(
deb_source='test1',
deb_version='1',
)

ingest = IngestDebsrc('debian', 'bookworm', None)
await ingest.import_update(db_session_class, f)

r = (await db_session_class.execute(select(Debsrc).order_by(Debsrc.deb_source))).all()
assert len(r) == 1
t = r.pop(0)[0]
assert t.dist.cpe_version == '12'
assert t.deb_source == 'test1'
assert t.deb_version == '1'