-
Notifications
You must be signed in to change notification settings - Fork 963
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
Reapply "Store attestations for PEP740 (#16302)" (#16545) #16546
Reapply "Store attestations for PEP740 (#16302)" (#16545) #16546
Conversation
This reverts commit da7e1ed.
Signed-off-by: William Woodruff <[email protected]>
warehouse/migrations/versions/4037669366ca_recreate_attestations_table.py
Outdated
Show resolved
Hide resolved
Signed-off-by: William Woodruff <[email protected]>
IFileStorage requires a name to disambiguate it. Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
This removes two mocked `db_request`s from the simple index tests. These mocks were masking larger architectural issues with both attestations and our test scaffolding for attestations. This isn't quite complete yet, since it does a nasty thing (uses a file storage with a tmpdir) to get IntegrityService initialization working. Signed-off-by: William Woodruff <[email protected]>
Listing some action items that need to be accomplished before undrafting:
|
Signed-off-by: William Woodruff <[email protected]>
This reduces the overall API surface for IIntegrityService implementers, and adds an initial NullIntegrityService to make unit-level testing simpler. Signed-off-by: William Woodruff <[email protected]>
This reverts commit e19be6c.
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Remove more ad-hoc stubs as well. Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a functional test for this in 17e9d45 but it's currently failing trying to refresh the TUF metadata. @woodruffw @DarkaMaul thoughts on what we should do about TUF here?
6a55e5c
to
b58fa0b
Compare
b58fa0b
to
866b0a7
Compare
Oh interesting, the TUF failure seems to have been an intermittent thing, this now works. Will have to look into why the attestation hash digest is different. |
Here's what I was getting, for context:
|
I've also started writing some tests for this at trail-of-forks#3063, and my solution there was to mock the verification. However, I did not assert that the hashes were correct (and they are probably not). |
tests/functional/api/test_simple.py
Outdated
response = webtest.get("/simple/sampleproject/", status=HTTPStatus.OK) | ||
link = response.html.find("a", text="sampleproject-3.0.0.tar.gz") | ||
assert "data-provenance" in link.attrs | ||
assert link.get("data-provenance") == expected_hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails here because the hash we get here is
hashlib.sha256(
b"sampleproject-3.0.0.tar.gz:2" # notice the 2 here
).hexdigest()
However, the len(attestations)
should be 1.
The problem lies in generate_provenance of NullService
that creates the DatabaseAttestation
and adds it to the file.attestations
(like in _persist_attestations )
Because the relationship is noted as back_populates
, sqlalchemy automatically adds the newly created DatabaseAttestation
to the file
instance.
The statement below is thus redundant and creates add a second time the attestation to the file instance.
file.attestations.append(database_attestation)
However, if we look at test_persist_attestations_succeeds
, the test passes with the following statements :
assert len(attestations_db) == 1
assert len(file.attestations) == 1
I've observed the state in a debugger using sqlalchemy tools and they looked appropriate.
from sqlachemy import inspect
state = inspect(database_attestation)
Any idea here of the reason for this behavior ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the Attestation
objects weren't actually being added to the session, the test was emitting a warning like:
tests/unit/attestations/test_services.py::TestIntegrityService::test_generate_provenance_succeeds[GitHubPublisherFactory]
/opt/warehouse/src/warehouse/attestations/models.py:53: SAWarning: Object of type <Attestation> not in session, add operation along 'File.attestations' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation.)
f"{Path(self.file.path).name}.attestation",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sorting this out - I missed the warning in the logs.
Rename key Co-authored-by: Dustin Ingram <[email protected]>
This reverts commit 52931a1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, will wait to merge until next week though.
WIP, needs full backstop tests.This reverts commit da7e1ed.