Skip to content

Commit

Permalink
Fix / test metadata and mediaType (#5024)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantb authored Jun 10, 2024
1 parent f6e41a9 commit 8f10166
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ final class Files(
test(CreateFile(iri, projectRef, testStorageRef, testStorageType, testAttributes, caller.subject, tag = None))
(_, storage) <- fetchAndValidateActiveStorage(storageId, projectRef, pc)
metadata <- fileOperations.delegate(storage, description.filename)
} yield DelegationResponse(metadata.bucket, iri, metadata.path, description.metadata)
} yield DelegationResponse(metadata.bucket, iri, metadata.path, description.metadata, description.mediaType)
}.span("delegate")

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.bluebrain.nexus.delta.plugins.storage.files.routes

import akka.http.scaladsl.model.StatusCodes.{Created, OK}
import akka.http.scaladsl.model.Uri
import akka.http.scaladsl.model.{ContentType, Uri}
import akka.http.scaladsl.server._
import cats.effect.IO
import cats.syntax.all._
Expand Down Expand Up @@ -104,7 +104,7 @@ final class DelegateFilesRoutes(
delegationResponse.metadata,
delegationResponse.path.path,
None,
None
delegationResponse.mediaType
)
_ <- index(project, fileResource, mode)
} yield fileResource
Expand All @@ -113,7 +113,13 @@ final class DelegateFilesRoutes(

object DelegateFilesRoutes {

final case class DelegationResponse(bucket: String, id: Iri, path: Uri, metadata: Option[FileCustomMetadata])
final case class DelegationResponse(
bucket: String,
id: Iri,
path: Uri,
metadata: Option[FileCustomMetadata],
mediaType: Option[ContentType]
)

object DelegationResponse {
implicit val enc: Encoder[DelegationResponse] = deriveEncoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TokenIssuerSuite extends CatsEffectSuite with Generators {

test("JWS verification fails if token is expired") {
val tokenIssuer = new TokenIssuer(rsaJWK, tokenValidity = 0.seconds)
val returnedPayload = DelegationResponse(genString(), iri"potato", Uri(genString()), None)
val returnedPayload = DelegationResponse(genString(), iri"potato", Uri(genString()), None, None)

val program = for {
jwsPayload <- tokenIssuer.issueJWSPayload(returnedPayload.asJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"_filename": "{{filename}}",
"_location": "{{location}}",
"_mediaType": "image/png",
"_mediaType": "{{mediaType}}",
"_origin" : "External",
"_incoming": "{{self}}/incoming",
"_outgoing": "{{self}}/outgoing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ class S3StorageSpec extends StorageSpec {
.accepted
}

private def registrationResponse(id: String, digestValue: String, location: String, filename: String): Json =
private def registrationResponse(
id: String,
digestValue: String,
location: String,
filename: String,
mediaType: String
): Json =
jsonContentOf(
"kg/files/registration-metadata.json",
replacements(
Expand All @@ -248,7 +254,8 @@ class S3StorageSpec extends StorageSpec {
"projId" -> s"$projectRef",
"digestValue" -> digestValue,
"location" -> location,
"filename" -> filename
"filename" -> filename,
"mediaType" -> mediaType
): _*
)

Expand Down Expand Up @@ -282,7 +289,8 @@ class S3StorageSpec extends StorageSpec {
fullId,
logoSha256HexDigest,
location = path,
filename = logoFilename
filename = logoFilename,
mediaType = "image/png"
)
}
} yield assertion
Expand Down Expand Up @@ -372,8 +380,18 @@ class S3StorageSpec extends StorageSpec {

s"Delegate S3 file upload" should {
"succeed using JWS protocol with flattened serialization" in {
val filename = genString()
val payload = Json.obj("filename" -> Json.fromString(filename))
val filename = genString()
val (name, desc, keywords) = (genString(), genString(), Json.obj(genString() := genString()))
val metadata =
json"""
{
"name": "$name",
"description": "$desc",
"keywords": $keywords
}
"""
val payload =
Json.obj("filename" -> Json.fromString(filename), "metadata" -> metadata, "mediaType" := "image/dan")

for {
jwsPayload <-
Expand All @@ -390,14 +408,16 @@ class S3StorageSpec extends StorageSpec {
}
encodedId = UrlUtils.encode(id)
filename = path.split("/").last
expectedMetadata = Json.obj("name" := name, "description" := desc, "_keywords" := keywords)
assertion <- deltaClient.get[Json](s"/files/$projectRef/$encodedId", Coyote) { (json, response) =>
response.status shouldEqual StatusCodes.OK
val expected = registrationResponse(
id,
logoSha256HexDigest,
location = path,
filename = filename
)
filename = filename,
mediaType = "image/dan"
).deepMerge(expectedMetadata)
val actual = filterMetadataKeys(json)
actual shouldEqual expected
}
Expand Down

0 comments on commit 8f10166

Please sign in to comment.