authentik.blueprints.tests.test_oci
Test blueprints OCI
1"""Test blueprints OCI""" 2 3from django.test import TransactionTestCase 4from requests_mock import Mocker 5 6from authentik.blueprints.models import BlueprintInstance, BlueprintRetrievalFailed 7from authentik.blueprints.v1.oci import OCI_MEDIA_TYPE 8 9 10class TestBlueprintOCI(TransactionTestCase): 11 """Test Blueprints OCI Tasks""" 12 13 def test_successful(self): 14 """Successful retrieval""" 15 with Mocker() as mocker: 16 mocker.get( 17 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 18 json={ 19 "layers": [ 20 { 21 "mediaType": OCI_MEDIA_TYPE, 22 "digest": "foo", 23 } 24 ] 25 }, 26 ) 27 mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", text="foo") 28 29 self.assertEqual( 30 BlueprintInstance( 31 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 32 ).retrieve(), 33 "foo", 34 ) 35 36 def test_successful_port(self): 37 """Successful retrieval with custom port""" 38 with Mocker() as mocker: 39 mocker.get( 40 "https://ghcr.io:1234/v2/goauthentik/blueprints/test/manifests/latest", 41 json={ 42 "layers": [ 43 { 44 "mediaType": OCI_MEDIA_TYPE, 45 "digest": "foo", 46 } 47 ] 48 }, 49 ) 50 mocker.get("https://ghcr.io:1234/v2/goauthentik/blueprints/test/blobs/foo", text="foo") 51 52 self.assertEqual( 53 BlueprintInstance( 54 path="oci://ghcr.io:1234/goauthentik/blueprints/test:latest" 55 ).retrieve(), 56 "foo", 57 ) 58 59 def test_manifests_error(self): 60 """Test manifests request erroring""" 61 with Mocker() as mocker: 62 mocker.get( 63 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", status_code=401 64 ) 65 66 with self.assertRaises(BlueprintRetrievalFailed): 67 BlueprintInstance( 68 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 69 ).retrieve_oci() 70 71 def test_manifests_error_response(self): 72 """Test manifests request erroring""" 73 with Mocker() as mocker: 74 mocker.get( 75 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 76 json={"errors": ["foo"]}, 77 ) 78 79 with self.assertRaises(BlueprintRetrievalFailed): 80 BlueprintInstance( 81 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 82 ).retrieve_oci() 83 84 def test_no_matching_blob(self): 85 """Successful retrieval""" 86 with Mocker() as mocker: 87 mocker.get( 88 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 89 json={ 90 "layers": [ 91 { 92 "mediaType": OCI_MEDIA_TYPE + "foo", 93 "digest": "foo", 94 } 95 ] 96 }, 97 ) 98 with self.assertRaises(BlueprintRetrievalFailed): 99 BlueprintInstance( 100 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 101 ).retrieve_oci() 102 103 def test_blob_error(self): 104 """Successful retrieval""" 105 with Mocker() as mocker: 106 mocker.get( 107 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 108 json={ 109 "layers": [ 110 { 111 "mediaType": OCI_MEDIA_TYPE, 112 "digest": "foo", 113 } 114 ] 115 }, 116 ) 117 mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", status_code=401) 118 119 with self.assertRaises(BlueprintRetrievalFailed): 120 BlueprintInstance( 121 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 122 ).retrieve_oci()
class
TestBlueprintOCI(django.test.testcases.TransactionTestCase):
11class TestBlueprintOCI(TransactionTestCase): 12 """Test Blueprints OCI Tasks""" 13 14 def test_successful(self): 15 """Successful retrieval""" 16 with Mocker() as mocker: 17 mocker.get( 18 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 19 json={ 20 "layers": [ 21 { 22 "mediaType": OCI_MEDIA_TYPE, 23 "digest": "foo", 24 } 25 ] 26 }, 27 ) 28 mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", text="foo") 29 30 self.assertEqual( 31 BlueprintInstance( 32 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 33 ).retrieve(), 34 "foo", 35 ) 36 37 def test_successful_port(self): 38 """Successful retrieval with custom port""" 39 with Mocker() as mocker: 40 mocker.get( 41 "https://ghcr.io:1234/v2/goauthentik/blueprints/test/manifests/latest", 42 json={ 43 "layers": [ 44 { 45 "mediaType": OCI_MEDIA_TYPE, 46 "digest": "foo", 47 } 48 ] 49 }, 50 ) 51 mocker.get("https://ghcr.io:1234/v2/goauthentik/blueprints/test/blobs/foo", text="foo") 52 53 self.assertEqual( 54 BlueprintInstance( 55 path="oci://ghcr.io:1234/goauthentik/blueprints/test:latest" 56 ).retrieve(), 57 "foo", 58 ) 59 60 def test_manifests_error(self): 61 """Test manifests request erroring""" 62 with Mocker() as mocker: 63 mocker.get( 64 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", status_code=401 65 ) 66 67 with self.assertRaises(BlueprintRetrievalFailed): 68 BlueprintInstance( 69 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 70 ).retrieve_oci() 71 72 def test_manifests_error_response(self): 73 """Test manifests request erroring""" 74 with Mocker() as mocker: 75 mocker.get( 76 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 77 json={"errors": ["foo"]}, 78 ) 79 80 with self.assertRaises(BlueprintRetrievalFailed): 81 BlueprintInstance( 82 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 83 ).retrieve_oci() 84 85 def test_no_matching_blob(self): 86 """Successful retrieval""" 87 with Mocker() as mocker: 88 mocker.get( 89 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 90 json={ 91 "layers": [ 92 { 93 "mediaType": OCI_MEDIA_TYPE + "foo", 94 "digest": "foo", 95 } 96 ] 97 }, 98 ) 99 with self.assertRaises(BlueprintRetrievalFailed): 100 BlueprintInstance( 101 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 102 ).retrieve_oci() 103 104 def test_blob_error(self): 105 """Successful retrieval""" 106 with Mocker() as mocker: 107 mocker.get( 108 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 109 json={ 110 "layers": [ 111 { 112 "mediaType": OCI_MEDIA_TYPE, 113 "digest": "foo", 114 } 115 ] 116 }, 117 ) 118 mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", status_code=401) 119 120 with self.assertRaises(BlueprintRetrievalFailed): 121 BlueprintInstance( 122 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 123 ).retrieve_oci()
Test Blueprints OCI Tasks
def
test_successful(self):
14 def test_successful(self): 15 """Successful retrieval""" 16 with Mocker() as mocker: 17 mocker.get( 18 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 19 json={ 20 "layers": [ 21 { 22 "mediaType": OCI_MEDIA_TYPE, 23 "digest": "foo", 24 } 25 ] 26 }, 27 ) 28 mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", text="foo") 29 30 self.assertEqual( 31 BlueprintInstance( 32 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 33 ).retrieve(), 34 "foo", 35 )
Successful retrieval
def
test_successful_port(self):
37 def test_successful_port(self): 38 """Successful retrieval with custom port""" 39 with Mocker() as mocker: 40 mocker.get( 41 "https://ghcr.io:1234/v2/goauthentik/blueprints/test/manifests/latest", 42 json={ 43 "layers": [ 44 { 45 "mediaType": OCI_MEDIA_TYPE, 46 "digest": "foo", 47 } 48 ] 49 }, 50 ) 51 mocker.get("https://ghcr.io:1234/v2/goauthentik/blueprints/test/blobs/foo", text="foo") 52 53 self.assertEqual( 54 BlueprintInstance( 55 path="oci://ghcr.io:1234/goauthentik/blueprints/test:latest" 56 ).retrieve(), 57 "foo", 58 )
Successful retrieval with custom port
def
test_manifests_error(self):
60 def test_manifests_error(self): 61 """Test manifests request erroring""" 62 with Mocker() as mocker: 63 mocker.get( 64 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", status_code=401 65 ) 66 67 with self.assertRaises(BlueprintRetrievalFailed): 68 BlueprintInstance( 69 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 70 ).retrieve_oci()
Test manifests request erroring
def
test_manifests_error_response(self):
72 def test_manifests_error_response(self): 73 """Test manifests request erroring""" 74 with Mocker() as mocker: 75 mocker.get( 76 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 77 json={"errors": ["foo"]}, 78 ) 79 80 with self.assertRaises(BlueprintRetrievalFailed): 81 BlueprintInstance( 82 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 83 ).retrieve_oci()
Test manifests request erroring
def
test_no_matching_blob(self):
85 def test_no_matching_blob(self): 86 """Successful retrieval""" 87 with Mocker() as mocker: 88 mocker.get( 89 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 90 json={ 91 "layers": [ 92 { 93 "mediaType": OCI_MEDIA_TYPE + "foo", 94 "digest": "foo", 95 } 96 ] 97 }, 98 ) 99 with self.assertRaises(BlueprintRetrievalFailed): 100 BlueprintInstance( 101 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 102 ).retrieve_oci()
Successful retrieval
def
test_blob_error(self):
104 def test_blob_error(self): 105 """Successful retrieval""" 106 with Mocker() as mocker: 107 mocker.get( 108 "https://ghcr.io/v2/goauthentik/blueprints/test/manifests/latest", 109 json={ 110 "layers": [ 111 { 112 "mediaType": OCI_MEDIA_TYPE, 113 "digest": "foo", 114 } 115 ] 116 }, 117 ) 118 mocker.get("https://ghcr.io/v2/goauthentik/blueprints/test/blobs/foo", status_code=401) 119 120 with self.assertRaises(BlueprintRetrievalFailed): 121 BlueprintInstance( 122 path="oci://ghcr.io/goauthentik/blueprints/test:latest" 123 ).retrieve_oci()
Successful retrieval