-
Notifications
You must be signed in to change notification settings - Fork 981
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mike Fiedler <[email protected]> Co-authored-by: Dustin Ingram <[email protected]>
- Loading branch information
1 parent
2706bfb
commit 50a58f3
Showing
20 changed files
with
523 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/functional/_fixtures/sampleproject-3.0.0.tar.gz.publish.attestation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"version": 1, | ||
"verification_material": { | ||
"certificate": "MIIC6zCCAnGgAwIBAgIUFgmhIYx8gvBGePCTacG/4kbBdRwwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjQwODI5MTcwOTM5WhcNMjQwODI5MTcxOTM5WjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtGrMPml4OtsRJ3Z6qRahs0kHCZxP4n9fvrJE957WVxgAGg4k6a1PbRJY9nT9wKpRrZmKV++AgA9ndhdruXXaAKOCAZAwggGMMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUosNvhYEuTPfgyU/dZfu93lFGRNswHwYDVR0jBBgwFoAU39Ppz1YkEZb5qNjpKFWixi4YZD8wQAYDVR0RAQH/BDYwNIEyOTE5NDM2MTU4MjM2LWNvbXB1dGVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20wKQYKKwYBBAGDvzABAQQbaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tMCsGCisGAQQBg78wAQgEHQwbaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tMIGKBgorBgEEAdZ5AgQCBHwEegB4AHYA3T0wasbHETJjGR4cmWc3AqJKXrjePK3/h4pygC8p7o4AAAGRnx0/aQAABAMARzBFAiBogvcKHIIR9FcX1vQgDhGtAl0XQoMRiEB3OdUWO94P1gIhANdJlyISdtvVrHes25dWKTLepy+IzQmzfQU/S7cxWHmOMAoGCCqGSM49BAMDA2gAMGUCMGe2xTiuenbjdt1d2e4IaCiwRh2G4KAtyujRESSSUbpuGme/o9ouiApeONBv2CvvGAIxAOEkAGFO3aALE3IPNosxqaz9MbqJOdmYhB1Cz1D7xbFc/m243VxJWxaC/uOFEpyiYQ==", | ||
"transparency_entries": [ | ||
{ | ||
"logIndex": "125970014", | ||
"logId": { | ||
"keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0=" | ||
}, | ||
"kindVersion": { | ||
"kind": "dsse", | ||
"version": "0.0.1" | ||
}, | ||
"integratedTime": "1724951379", | ||
"inclusionPromise": { | ||
"signedEntryTimestamp": "MEUCIQCHrKFTeXNY432S0bUSBS69S8d5JnNcDXa41q6OEvxEwgIgaZstc5Jpm0IgwFC7RDTXYEAKk+3aG/MkRkaPdJdyn8U=" | ||
}, | ||
"inclusionProof": { | ||
"logIndex": "4065752", | ||
"rootHash": "7jVDF3UNUZVEU85ffETQ3WKfXhOoMi4cgytJM250HTk=", | ||
"treeSize": "4065754", | ||
"hashes": [ | ||
"NwJgWJoxjearbnEIT9bnWXpzo0LGNrR1cpWId0g66rE=", | ||
"kLjpW3Eh7pQJNOvyntghzF57tcfqk2IzX7cqiBDgGf8=", | ||
"FW8y9LQ1i3q+MnbeGJipKGl4VfX1zRBOD7TmhbEw7uI=", | ||
"mKcbGJDJ/+buNbXy9Eyv94nVoAyUauuIlN3cJg3qSBY=", | ||
"5VytqqAHhfRkRWMrY43UXWCnRBb7JwElMlKpY5JueBc=", | ||
"mZJnD39LTKdis2wUTz1OOMx3r7HwgJh9rnb2VwiPzts=", | ||
"MXZOQFJFiOjREF0xwMOCXu29HwTchjTtl/BeFoI51wY=", | ||
"g8zCkHnLwO3LojK7g5AnqE8ezSNRnCSz9nCL5GD3a8A=", | ||
"RrZsD/RSxNoujlvq/MsCEvLSkKZfv0jmQM9Kp7qbJec=", | ||
"QxmVWsbTp4cClxuAkuT51UH2EY7peHMVGKq7+b+cGwQ=", | ||
"Q2LAtNzOUh+3PfwfMyNxYb06fTQmF3VeTT6Fr6Upvfc=", | ||
"ftwAu6v62WFDoDmcZ1JKfrRPrvuiIw5v3BvRsgQj7N8=" | ||
], | ||
"checkpoint": { | ||
"envelope": "rekor.sigstore.dev - 1193050959916656506\n4065754\n7jVDF3UNUZVEU85ffETQ3WKfXhOoMi4cgytJM250HTk=\n\n— rekor.sigstore.dev wNI9ajBGAiEAhMomhZHOTNB5CVPO98CMXCv01ZlIF+C+CgzraAB01r8CIQCEuXbv6aqguUpB/ig5eXRIbarvxLXkg3nX48DzambktQ==\n" | ||
} | ||
}, | ||
"canonicalizedBody": "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiZHNzZSIsInNwZWMiOnsiZW52ZWxvcGVIYXNoIjp7ImFsZ29yaXRobSI6InNoYTI1NiIsInZhbHVlIjoiOWRiNGJjMzE3MTgyZWI3NzljNDIyY2Q0NGI2ZDdlYTk5ZWM1M2Q3M2JiY2ZjZWVmZTIyNWVlYjQ3NTQyMjc4OCJ9LCJwYXlsb2FkSGFzaCI6eyJhbGdvcml0aG0iOiJzaGEyNTYiLCJ2YWx1ZSI6IjlkYjY0MjlhOTkzZGFiY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kRMM1ZQUmtWd2VXbFpVVDA5Q2kwdExTMHRSVTVFSUVORlVsUkpSa2xEUVZSRkxTMHRMUzBLIn1dfX0=" | ||
} | ||
] | ||
}, | ||
"envelope": { | ||
"statement": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJzdWJqZWN0IjpbeyJuYW1lIjoic2FtcGxlcHJvamVjdC0zLjAuMC50YXIuZ3oiLCJkaWdlc3QiOnsic2hhMjU2IjoiMTE3ZWQ4OGU1ZGIwNzNiYjkyOTY5YTc1NDU3NDVmZDk3N2VlODViNzAxOTcwNmRkMjU2YTY0MDU4ZjcwOTYzZCJ9fV0sInByZWRpY2F0ZVR5cGUiOiJodHRwczovL2RvY3MucHlwaS5vcmcvYXR0ZXN0YXRpb25zL3B1Ymxpc2gvdjEiLCJwcmVkaWNhdGUiOm51bGx9", | ||
"signature": "MEUCIBhiN/nMGL7hzYBOPB9TLknhGSdKnCD4zB7L5yew4BbwAiEArs8yz0+BOcgHKsKBsMuNyYaDGZE0UWBn0Gp5ZF35/Sc=" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import json | ||
|
||
from http import HTTPStatus | ||
from pathlib import Path | ||
|
||
from ...common.db.packaging import ( | ||
FileFactory, | ||
ProjectFactory, | ||
ProvenanceFactory, | ||
ReleaseFactory, | ||
) | ||
|
||
_HERE = Path(__file__).parent | ||
_ASSETS = _HERE.parent / "_fixtures" | ||
assert _ASSETS.is_dir() | ||
|
||
|
||
def test_provenance_available(webtest): | ||
with open( | ||
_ASSETS / "sampleproject-3.0.0.tar.gz.publish.attestation", | ||
) as f: | ||
attestation_contents = f.read() | ||
attestation_json = json.loads(attestation_contents) | ||
|
||
project = ProjectFactory.create() | ||
release = ReleaseFactory.create(project=project) | ||
file_ = FileFactory.create(release=release, packagetype="sdist") | ||
ProvenanceFactory.create( | ||
file=file_, | ||
provenance={"attestation_bundles": [{"attestations": [attestation_json]}]}, | ||
) | ||
|
||
response = webtest.get( | ||
f"/integrity/{project.name}/{release.version}/{file_.filename}/provenance", | ||
status=HTTPStatus.OK, | ||
) | ||
assert response.json | ||
assert "attestation_bundles" in response.json | ||
attestation_bundles = response.json["attestation_bundles"] | ||
assert len(attestation_bundles) == 1 | ||
attestation_bundle = attestation_bundles[0] | ||
assert "attestations" in attestation_bundle | ||
attestations = attestation_bundle["attestations"] | ||
assert len(attestations) == 1 | ||
attestation = attestations[0] | ||
assert attestation == attestation_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pretend | ||
import pytest | ||
|
||
from warehouse.api import integrity | ||
|
||
|
||
def test_select_content_type(db_request): | ||
db_request.accept = "application/json" | ||
|
||
assert ( | ||
integrity._select_content_type(db_request) | ||
== integrity.MIME_PYPI_INTEGRITY_V1_JSON | ||
) | ||
|
||
|
||
# Backstop; can be removed/changed once this view supports HTML. | ||
@pytest.mark.parametrize( | ||
"content_type", | ||
[integrity.MIME_TEXT_HTML, integrity.MIME_PYPI_INTEGRITY_V1_HTML], | ||
) | ||
def test_provenance_for_file_bad_accept(db_request, content_type): | ||
db_request.accept = content_type | ||
response = integrity.provenance_for_file(pretend.stub(), db_request) | ||
assert response.status_code == 406 | ||
assert response.json == {"message": "Request not acceptable"} | ||
|
||
|
||
def test_provenance_for_file_not_enabled(db_request, monkeypatch): | ||
monkeypatch.setattr(db_request, "flags", pretend.stub(enabled=lambda *a: True)) | ||
|
||
response = integrity.provenance_for_file(pretend.stub(), db_request) | ||
assert response.status_code == 403 | ||
assert response.json == {"message": "Attestations temporarily disabled"} | ||
|
||
|
||
def test_provenance_for_file_not_present(db_request, monkeypatch): | ||
monkeypatch.setattr(db_request, "flags", pretend.stub(enabled=lambda *a: False)) | ||
file = pretend.stub(provenance=None, filename="fake-1.2.3.tar.gz") | ||
|
||
response = integrity.provenance_for_file(file, db_request) | ||
assert response.status_code == 404 | ||
assert response.json == {"message": "No provenance available for fake-1.2.3.tar.gz"} |
Oops, something went wrong.