Skip to content

Commit 80144c2

Browse files
woodruffwdi
andauthored
PEP 740: add IntegrityService and interface (#16684)
* add IntegrityService and interface Signed-off-by: William Woodruff <[email protected]> * cleanup, formatting, fix imports Signed-off-by: William Woodruff <[email protected]> * tests: add IntegrityService coverage Signed-off-by: William Woodruff <[email protected]> * attestations.backend -> integrity.backend Signed-off-by: William Woodruff <[email protected]> * add OIDCPublisher.supports_attestations This is False by default, but individual publisher subclasses can override it. Signed-off-by: William Woodruff <[email protected]> --------- Signed-off-by: William Woodruff <[email protected]> Co-authored-by: Dustin Ingram <[email protected]>
1 parent 55ccaf7 commit 80144c2

File tree

16 files changed

+752
-3
lines changed

16 files changed

+752
-3
lines changed

dev/environment

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ BREACHED_EMAILS=warehouse.accounts.NullEmailBreachedService
4646
BREACHED_PASSWORDS=warehouse.accounts.NullPasswordBreachedService
4747

4848
OIDC_BACKEND=warehouse.oidc.services.NullOIDCPublisherService
49+
INTEGRITY_BACKEND=warehouse.attestations.services.NullIntegrityService
4950

5051
METRICS_BACKEND=warehouse.metrics.DataDogMetrics host=notdatadog
5152

requirements/main.in

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ requests
6161
requests-aws4auth
6262
redis>=2.8.0,<6.0.0
6363
rfc3986
64+
rfc8785
6465
sentry-sdk
6566
setuptools
6667
sigstore~=3.2.0

requirements/main.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,9 @@ rfc3986==2.0.0 \
19861986
rfc8785==0.1.3 \
19871987
--hash=sha256:167efe3b5cdd09dded9d0cfc8fec1f48f5cd9f8f13b580ada4efcac138925048 \
19881988
--hash=sha256:6116062831c62e7ac5d027973a1fe07b601ccd854bca4a2b401938a00a20b0c0
1989-
# via sigstore
1989+
# via
1990+
# -r requirements/main.in
1991+
# sigstore
19901992
rich==13.8.1 \
19911993
--hash=sha256:1760a3c0848469b97b558fc61c85233e3dafb69c7a071b4d60c38099d3cd4c06 \
19921994
--hash=sha256:8260cda28e3db6bf04d2d1ef4dbc03ba80a824c88b0e7668a0f23126a424844a

tests/conftest.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from jinja2 import Environment, FileSystemLoader
3232
from psycopg.errors import InvalidCatalogName
33+
from pypi_attestations import Attestation, Envelope, VerificationMaterial
3334
from pyramid.i18n import TranslationString
3435
from pyramid.static import ManifestCacheBuster
3536
from pyramid_jinja2 import IJinja2Environment
@@ -387,13 +388,11 @@ def get_db_session_for_app_config(app_config):
387388

388389
@pytest.fixture(scope="session")
389390
def app_config(database):
390-
391391
return get_app_config(database)
392392

393393

394394
@pytest.fixture(scope="session")
395395
def app_config_dbsession_from_env(database):
396-
397396
nondefaults = {
398397
"warehouse.db_create_session": lambda r: r.environ.get("warehouse.db_session")
399398
}
@@ -539,6 +538,20 @@ def activestate_oidc_service(db_session):
539538
)
540539

541540

541+
@pytest.fixture
542+
def dummy_attestation():
543+
return Attestation(
544+
version=1,
545+
verification_material=VerificationMaterial(
546+
certificate="somebase64string", transparency_entries=[dict()]
547+
),
548+
envelope=Envelope(
549+
statement="somebase64string",
550+
signature="somebase64string",
551+
),
552+
)
553+
554+
542555
@pytest.fixture
543556
def macaroon_service(db_session):
544557
return macaroon_services.DatabaseMacaroonService(db_session)

tests/unit/attestations/test_init.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
import pretend
14+
15+
from warehouse import attestations
16+
from warehouse.attestations.interfaces import IIntegrityService
17+
18+
19+
def test_includeme():
20+
fake_service_klass = pretend.stub(create_service=pretend.stub())
21+
config = pretend.stub(
22+
registry=pretend.stub(settings={"integrity.backend": "fake.path.to.backend"}),
23+
maybe_dotted=pretend.call_recorder(
24+
lambda attr: fake_service_klass,
25+
),
26+
register_service_factory=pretend.call_recorder(
27+
lambda factory, iface, name=None: None
28+
),
29+
)
30+
31+
attestations.includeme(config)
32+
33+
assert config.maybe_dotted.calls == [pretend.call("fake.path.to.backend")]
34+
assert config.register_service_factory.calls == [
35+
pretend.call(fake_service_klass.create_service, IIntegrityService),
36+
]

0 commit comments

Comments
 (0)