* blueprints: add ability to load blueprints via OCI Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add docs Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * fix inheritance check for meta models Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * add oci tests Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
"""Test blueprints OCI"""
|
|
from django.test import TransactionTestCase
|
|
from requests_mock import Mocker
|
|
|
|
from authentik.blueprints.models import OCI_MEDIA_TYPE, BlueprintInstance, BlueprintRetrievalFailed
|
|
|
|
|
|
class TestBlueprintOCI(TransactionTestCase):
|
|
"""Test Blueprints OCI Tasks"""
|
|
|
|
def test_successful(self):
|
|
"""Successful retrieval"""
|
|
with Mocker() as mocker:
|
|
mocker.get(
|
|
"https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest",
|
|
json={
|
|
"layers": [
|
|
{
|
|
"mediaType": OCI_MEDIA_TYPE,
|
|
"digest": "foo",
|
|
}
|
|
]
|
|
},
|
|
)
|
|
mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", text="foo")
|
|
|
|
self.assertEqual(
|
|
BlueprintInstance(
|
|
path="https://ghcr.io/goauthentik/blueprints/test:latest"
|
|
).retrieve_oci(),
|
|
"foo",
|
|
)
|
|
|
|
def test_manifests_error(self):
|
|
"""Test manifests request erroring"""
|
|
with Mocker() as mocker:
|
|
mocker.get(
|
|
"https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", status_code=401
|
|
)
|
|
|
|
with self.assertRaises(BlueprintRetrievalFailed):
|
|
BlueprintInstance(
|
|
path="https://ghcr.io/goauthentik/blueprints/test:latest"
|
|
).retrieve_oci()
|
|
|
|
def test_manifests_error_response(self):
|
|
"""Test manifests request erroring"""
|
|
with Mocker() as mocker:
|
|
mocker.get(
|
|
"https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest",
|
|
json={"errors": ["foo"]},
|
|
)
|
|
|
|
with self.assertRaises(BlueprintRetrievalFailed):
|
|
BlueprintInstance(
|
|
path="https://ghcr.io/goauthentik/blueprints/test:latest"
|
|
).retrieve_oci()
|
|
|
|
def test_no_matching_blob(self):
|
|
"""Successful retrieval"""
|
|
with Mocker() as mocker:
|
|
mocker.get(
|
|
"https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest",
|
|
json={
|
|
"layers": [
|
|
{
|
|
"mediaType": OCI_MEDIA_TYPE + "foo",
|
|
"digest": "foo",
|
|
}
|
|
]
|
|
},
|
|
)
|
|
with self.assertRaises(BlueprintRetrievalFailed):
|
|
BlueprintInstance(
|
|
path="https://ghcr.io/goauthentik/blueprints/test:latest"
|
|
).retrieve_oci()
|
|
|
|
def test_blob_error(self):
|
|
"""Successful retrieval"""
|
|
with Mocker() as mocker:
|
|
mocker.get(
|
|
"https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest",
|
|
json={
|
|
"layers": [
|
|
{
|
|
"mediaType": OCI_MEDIA_TYPE,
|
|
"digest": "foo",
|
|
}
|
|
]
|
|
},
|
|
)
|
|
mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", status_code=401)
|
|
|
|
with self.assertRaises(BlueprintRetrievalFailed):
|
|
BlueprintInstance(
|
|
path="https://ghcr.io/goauthentik/blueprints/test:latest"
|
|
).retrieve_oci()
|