def test_create_manifest_config_blob(self, test_name, proxy_manifest_response): test_params = storage_test_cases[test_name] repo = f"{self.orgname}/{test_params['image_name']}" params = { "repository": repo, "manifest_ref": test_params["manifest_ref"], } proxy_mock = proxy_manifest_response( test_params["manifest_ref"], test_params["manifest_json"], test_params["manifest_type"], ) with patch("data.registry_model.registry_proxy_model.Proxy", MagicMock(return_value=proxy_mock)): headers = _get_auth_headers(self.sub, self.ctx, repo) headers["Accept"] = ", ".join( DOCKER_SCHEMA2_CONTENT_TYPES.union(OCI_CONTENT_TYPES).union( DOCKER_SCHEMA1_CONTENT_TYPES)) resp = conduct_call( self.client, test_params["view_name"], url_for, "GET", params, expected_code=200, headers=headers, ) manifest = parse_manifest_from_bytes( Bytes.for_string_or_unicode(test_params["manifest_json"]), test_params["manifest_type"], sparse_manifest_support=True, ) if manifest.schema_version == 2 and not manifest.is_manifest_list: q = ImageStorage.filter( ImageStorage.content_checksum == manifest.config.digest) assert q.count() == 1
def setup(self, client, app, proxy_manifest_response): self.client = client self.user = model.user.get_user("devtable") context, subject = build_context_and_subject( ValidatedAuthContext(user=self.user)) access = [{ "type": "repository", "name": self.repository, "actions": ["pull"], }] token = generate_bearer_token(realapp.config["SERVER_HOSTNAME"], subject, context, access, 600, instance_keys) self.headers = { "Authorization": f"Bearer {token.decode('ascii')}", } if self.org is None: self.org = model.organization.create_organization( self.orgname, "{self.orgname}@devtable.com", self.user) self.org.save() self.config = model.proxy_cache.create_proxy_cache_config( org_name=self.orgname, upstream_registry=self.registry, expiration_s=3600, ) if self.repo_ref is None: r = model.repository.create_repository(self.orgname, self.image_name, self.user) assert r is not None self.repo_ref = registry_model.lookup_repository( self.orgname, self.image_name) assert self.repo_ref is not None def get_blob(layer): content = Bytes.for_string_or_unicode(layer).as_encoded_str() digest = str(sha256_digest(content)) blob = model.blob.store_blob_record_and_temp_link( self.orgname, self.image_name, digest, ImageStorageLocation.get(name="local_us"), len(content), 120, ) storage.put_content(["local_us"], get_layer_path(blob), content) return blob, digest if self.manifest is None: layer1 = json.dumps({ "config": {}, "rootfs": { "type": "layers", "diff_ids": [] }, "history": [{}], }) _, config_digest = get_blob(layer1) layer2 = "test" _, blob_digest = get_blob(layer2) builder = DockerSchema2ManifestBuilder() builder.set_config_digest(config_digest, len(layer1.encode("utf-8"))) builder.add_layer(blob_digest, len(layer2.encode("utf-8"))) manifest = builder.build() created_manifest = model.oci.manifest.get_or_create_manifest( self.repo_ref.id, manifest, storage) self.manifest = created_manifest.manifest assert self.digest == blob_digest assert self.manifest is not None if self.blob is None: self.blob = ImageStorage.filter( ImageStorage.content_checksum == self.digest).get()