Skip to content

Commit

Permalink
feat: machine readable record feedback Datastore model (#2582)
Browse files Browse the repository at this point in the history
Datastore model for holding state on individual OSV record data quality
findings

Part of #2189

---------

Co-authored-by: Rex P <106129829+another-rex@users.noreply.github.com>
  • Loading branch information
andrewpollock and another-rex authored Sep 11, 2024
1 parent 93c8d00 commit fae251d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docker/importer/importer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,32 @@ def test_few_updates(self, unused_mock_time: mock.MagicMock,
])


@mock.patch('importer.utcnow', lambda: datetime.datetime(2024, 1, 1))
class ImportFindingsTest(unittest.TestCase):
"""Import Finding tests."""

def setUp(self):
tests.reset_emulator()

tests.mock_datetime(self)

def test_add_finding(self):
"""Test that creating an import finding works."""
expected = osv.ImportFinding(
bug_id='CVE-2024-1234',
findings=[
osv.ImportFindings.INVALID_VERSION,
],
first_seen=importer.utcnow(),
last_attempt=importer.utcnow(),
)
expected.put()

for actual in osv.ImportFinding.query(
osv.ImportFinding.bug_id == expected.bug_id):
self.assertEqual(expected, actual)


if __name__ == '__main__':
run_slow_tests = (
os.environ.get('CLOUD_BUILD', 0) != 1 and 'RUN_SLOW_TESTS' in os.environ)
Expand Down
21 changes: 21 additions & 0 deletions osv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,27 @@ class AliasDenyListEntry(ndb.Model):
bug_id: str = ndb.StringProperty()


class ImportFindings(enum.IntEnum):
"""The possible quality findings about an individual record."""
NONE = 0
DELETED = 1
INVALID_JSON = 2
INVALID_PACKAGE = 3
INVALID_PURL = 4
INVALID_VERSION = 5
INVALID_COMMIT = 6
INVALID_RANGE = 7
BAD_ALIASED_CVE = 8


class ImportFinding(ndb.Model):
"""Quality findings about an individual record."""
bug_id: str = ndb.StringProperty()
findings: list[ImportFindings] = ndb.IntegerProperty(repeated=True)
first_seen: datetime = ndb.DateTimeProperty()
last_attempt: datetime = ndb.DateTimeProperty()


def get_source_repository(source_name):
"""Get source repository."""
return SourceRepository.get_by_id(source_name)
Expand Down

0 comments on commit fae251d

Please sign in to comment.