Although it is not recommended S3 supports a an object key with a leading slash. (putting and retrieving).
Running the InMemory version- after putting an object with a leading slash in key name,
The answer for listObjects will be incorrect.
For example the following test will fail:
it should "return non empty list if prefix is correct" in {
s3.createBucket("test")
s3.putObject("test", "/one/foo1", "xxx")
s3.putObject("test", "/one/foo2", "xxx")
s3.putObject("test", "/one/foo3", "xxx")
s3.listObjects("test", "/one").getObjectSummaries.asScala.isEmpty shouldBe false
}
Investigation this issue a bit, it seems that an HTTP layer translate the leading slash to "%2F"
in bucketDataStore in listBucket,
The following test fails because the list object command retrieve all the keys in the bucket.
it should "return empty list if prefix is incorrect2" in {
s3.createBucket("test")
s3.putObject("test", "/one/foo1", "xxx")
s3.putObject("test", "/one/foo2", "xxx")
s3.putObject("test", "/one/foo3", "xxx")
s3.listObjects("test", "%2Fone").getObjectSummaries.asScala.isEmpty shouldBe true
}
@carmelevi @shuttie Is this a bug only for InMemory version? if you run those tests with file based version they also fail. I'm building a Pr that addresses both cases.
Although it is not recommended S3 supports a an object key with a leading slash. (putting and retrieving).
Running the InMemory version- after putting an object with a leading slash in key name, The answer for listObjects will be incorrect.
For example the following test will fail: it should "return non empty list if prefix is correct" in { s3.createBucket("test") s3.putObject("test", "/one/foo1", "xxx") s3.putObject("test", "/one/foo2", "xxx") s3.putObject("test", "/one/foo3", "xxx") s3.listObjects("test", "/one").getObjectSummaries.asScala.isEmpty shouldBe false }
Investigation this issue a bit, it seems that an HTTP layer translate the leading slash to "%2F" in bucketDataStore in listBucket, The following test fails because the list object command retrieve all the keys in the bucket.