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

feat: machine readable record feedback Datastore model #2582

Merged
Show file tree
Hide file tree
Changes from all commits
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
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not very clear to me what this test is testing? I don't think there's any _pre_put code on ImportFindings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mostly just me wanting to exercise the thing to make sure it was all anatomically correct

"""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
Loading