Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Open
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
2 changes: 0 additions & 2 deletions src/main/scala/io/findify/s3mock/provider/FileProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class FileProvider(dir:String) extends Provider with LazyLogging {
file.createIfNotExists(createParents = true)
logger.debug(s"writing file for s3://$bucket/$key to $dir/$bucket/$key, bytes = ${data.length}")
file.writeByteArray(data)(OpenOptions.default)
objectMetadata.setLastModified(org.joda.time.DateTime.now().toDate)
metadataStore.put(bucket, key, objectMetadata)
}
override def getObject(bucket:String, key:String): GetObjectData = {
Expand Down Expand Up @@ -124,7 +123,6 @@ class FileProvider(dir:String) extends Provider with LazyLogging {
val hash = file.md5
metadataStore.get(bucket, key).foreach {m =>
m.setContentMD5(hash)
m.setLastModified(org.joda.time.DateTime.now().toDate)
}
logger.debug(s"completed multipart upload for s3://$bucket/$key")
CompleteMultipartUploadResult(bucket, key, hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class InMemoryProvider extends Provider with LazyLogging {
bucketDataStore.get(bucket) match {
case Some(bucketContent) =>
logger.debug(s"putting object for s3://$bucket/$key, bytes = ${data.length}")
bucketContent.keysInBucket.put(key, KeyContents(DateTime.now, data))
objectMetadata.setLastModified(org.joda.time.DateTime.now().toDate)
bucketContent.keysInBucket.put(key, KeyContents(DateTime(objectMetadata.getLastModified.getTime), data))
metadataStore.put(bucket, key, objectMetadata)
case None => throw NoSuchBucketException(bucket)
}
Expand Down Expand Up @@ -132,7 +131,6 @@ class InMemoryProvider extends Provider with LazyLogging {
val hash = DigestUtils.md5Hex(completeBytes)
metadataStore.get(bucket, key).foreach {m =>
m.setContentMD5(hash)
m.setLastModified(org.joda.time.DateTime.now().toDate)
}
CompleteMultipartUploadResult(bucket, key, hash)
case None => throw NoSuchBucketException(bucket)
Expand Down
11 changes: 9 additions & 2 deletions src/main/scala/io/findify/s3mock/route/MetadataUtil.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.findify.s3mock.route

import java.lang.Iterable
import java.text.SimpleDateFormat
import java.util
import java.util.Date

import akka.http.javadsl.model.HttpHeader
import akka.http.scaladsl.model.HttpRequest
Expand Down Expand Up @@ -36,9 +38,11 @@ object MetadataUtil extends LazyLogging {
// else if (ignoredHeaders.contains(key)) {
// ignore...
// }
else if (key.equalsIgnoreCase(Headers.LAST_MODIFIED)) try
metadata.setHeader(key, ServiceUtils.parseRfc822Date(header.value()))
else if (key.equalsIgnoreCase(Headers.LAST_MODIFIED)) try {
val sdf = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy")

metadata.setHeader(key, sdf.parse(header.value))
}
catch {
case pe: Exception => logger.warn("Unable to parse last modified date: " + header.value(), pe)
}
Expand Down Expand Up @@ -69,6 +73,9 @@ object MetadataUtil extends LazyLogging {

if(metadata.getContentType == null){
metadata.setContentType(request.entity.getContentType.toString)
}
if(metadata.getLastModified == null){
metadata.setLastModified(new Date())
}
metadata
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/io/findify/s3mock/GetPutObjectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class GetPutObjectTest extends S3MockTest {

it should "work with = in path" in {
s3.createBucket("urlencoded")
s3.listBuckets().exists(_.getName == "urlencoded") shouldBe true
s3.listBuckets().asScala.exists(_.getName == "urlencoded") shouldBe true
s3.putObject("urlencoded", "path/with=123/foo", "bar=")
s3.putObject("urlencoded", "path/withoutequals/foo", "bar")
val result = s3.listObjects("urlencoded").getObjectSummaries.toList.map(_.getKey)
val result = s3.listObjects("urlencoded").getObjectSummaries.asScala.toList.map(_.getKey)
result shouldBe List("path/with=123/foo", "path/withoutequals/foo")
getContent(s3.getObject("urlencoded", "path/with=123/foo")) shouldBe "bar="
getContent(s3.getObject("urlencoded", "path/withoutequals/foo")) shouldBe "bar"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.findify.s3mock

import java.io.ByteArrayInputStream
import java.util.Date

import com.amazonaws.services.s3.model.{ObjectMetadata, S3Object}

Expand All @@ -20,13 +21,15 @@ class GetPutObjectWithMetadataTest extends S3MockTest {
val metadata: ObjectMetadata = new ObjectMetadata()
metadata.setContentType("application/json")
metadata.setUserMetadata(Map("metamaic" -> "maic").asJava)
val lastmodified = new Date(150000000000L)
metadata.setLastModified(lastmodified)

s3.putObject("getput", "foo", is, metadata)

val s3Object: S3Object = s3.getObject("getput", "foo")
val actualMetadata: ObjectMetadata = s3Object.getObjectMetadata
actualMetadata.getContentType shouldBe "application/json"

actualMetadata.getLastModified shouldBe lastmodified
getContent(s3Object) shouldBe "bar"
}

Expand Down