Skip to content

fix(validation): do not enforce entry mediatypes #37

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

Merged
merged 2 commits into from
May 15, 2025
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
4 changes: 0 additions & 4 deletions image/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ def validate_static(entry: Dict[str, Any]) -> Tuple[bool, str]:
)
if not platform_valid:
return platform_valid, err

# If the mediaType is unsupported, then error
if entry["mediaType"] in UNSUPPORTED_OCI_MANIFEST_MEDIA_TYPES:
return False, f"Unsupported mediaType: {entry['mediaType']}"

# Valid if all of the above are valid
return True, ""
Expand Down
16 changes: 11 additions & 5 deletions image/v2s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@
MANIFEST_LIST_V2_SCHEMA, \
MANIFEST_LIST_V2_ENTRY_SCHEMA

# A list of mediaTypes which are not supported by the v2s2 manifest spec
# See doc comments below
UNSUPPORTED_V2S2_MANIFEST_MEDIA_TYPES = [
OCI_MANIFEST_MEDIA_TYPE
]
"""
A list of mediaTypes which are not supported by the v2s2 manifest spec.
This mainly just includes the OCI manifest mediaType.
"""

# See doc comments below
UNSUPPORTED_V2S2_MANIFEST_LIST_MEDIA_TYPES = [
OCI_INDEX_MEDIA_TYPE
]
"""
A list of mediaTypes which are not supported by the v2s2 manifest list
spec. This mainly just includes the OCI index mediaType.
"""

"""
ContainerImageManifestV2S2 class
Expand Down Expand Up @@ -145,10 +155,6 @@ def validate_static(entry: Dict[str, Any]) -> Tuple[bool, str]:
)
if not platform_valid:
return platform_valid, err

# If the mediaType is unsupported, then error
if entry["mediaType"] in UNSUPPORTED_V2S2_MANIFEST_MEDIA_TYPES:
return False, f"Unsupported mediaType: {entry['mediaType']}"

# Valid if all of the above are valid
return True, ""
Expand Down
22 changes: 0 additions & 22 deletions tests/oci_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,6 @@
}
}

# An example manifest list entry from the CNCF manifest v2s2 spec
CNCF_MANIFEST_LIST_ENTRY_EXAMPLE = {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270",
"size": 7682,
"platform": {
"architecture": "amd64",
"os": "linux",
"features": [
"sse4"
]
}
}

# An example image index entry following the OCI spec
DOCKER_BUILDX_ATTESTATION_INDEX_ENTRY = {
"mediaType": "application/vnd.oci.image.manifest.v1+json",
Expand Down Expand Up @@ -229,14 +215,6 @@ def test_container_image_oci_image_index_entry_static_validation():
assert isinstance(err, str)
assert len(err) > 0

# CNCF (non-OCI) example should be invalid
cncf_example_valid, err = ContainerImageIndexEntryOCI.validate_static(
copy.deepcopy(CNCF_MANIFEST_LIST_ENTRY_EXAMPLE)
)
assert cncf_example_valid == False
assert isinstance(err, str)
assert len(err) > 0

def test_container_image_oci_image_index_entry_instantiation():
# Invalid entry should raise ValidationError
exc = None
Expand Down
Loading