Skip to content

Commit

Permalink
Fixed a problem in the S3Signer regarding escaped url's. fixes kalibe…
Browse files Browse the repository at this point in the history
  • Loading branch information
EECOLOR committed Feb 19, 2014
1 parent 52dcc7b commit 73bb622
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/fly/play/s3/S3Signer.scala
Expand Up @@ -3,7 +3,6 @@ package fly.play.s3
import java.net.URI
import java.security.MessageDigest
import java.util.Date

import fly.play.aws.Aws.dates.rfc822DateFormat
import fly.play.aws.auth.AwsCredentials
import fly.play.aws.auth.Signer
Expand All @@ -13,6 +12,7 @@ import javax.crypto.spec.SecretKeySpec
import play.api.http.ContentTypeOf
import play.api.http.Writeable
import play.api.libs.ws.WS
import java.net.URL

case class S3Signer(credentials: AwsCredentials, s3Host: String) extends Signer with SignerUtils {
private val AwsCredentials(accessKeyId, secretKey, sessionToken, expirationSeconds) = credentials
Expand Down Expand Up @@ -47,8 +47,8 @@ case class S3Signer(credentials: AwsCredentials, s3Host: String) extends Signer

var newHeaders = addHeaders(request.headers, dateTime, contentType, contentMd5)

val uri = URI.create(request.url)
var path = uri.getPath match {
val uri = new URL(request.url)
val path = uri.getPath match {
case "" | null => None
case path => Some(path)
}
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Expand Up @@ -5,7 +5,7 @@ import play.Project._
object ApplicationBuild extends Build {

val appName = "play-s3"
val appVersion = "3.3.3"
val appVersion = "3.3.4"

val appDependencies = Seq(
"nl.rhinofly" %% "play-aws-utils" % "2.4.2")
Expand Down
26 changes: 23 additions & 3 deletions test/fly/play/s3/S3Spec.scala
Expand Up @@ -3,18 +3,15 @@ package fly.play.s3
import java.io.File
import java.lang.IllegalArgumentException
import java.util.Date

import scala.concurrent.Await
import scala.concurrent.Awaitable
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.util.Failure
import scala.util.Success

import org.specs2.execute.AsResult
import org.specs2.mutable.Specification
import org.specs2.specification.Example

import fly.play.aws.auth.SimpleAwsCredentials
import fly.play.s3.acl.CanonicalUser
import fly.play.s3.acl.FULL_CONTROL
Expand All @@ -32,6 +29,7 @@ import play.api.libs.ws.WS
import play.api.test.FakeApplication
import play.api.test.Helpers.running
import utils.MultipartFormData
import java.net.URLEncoder

class S3Spec extends Specification {

Expand Down Expand Up @@ -403,6 +401,28 @@ class S3Spec extends Specification {

noException(testBucket remove expectedFileName)
}

}

"be able to add and delete files with 'weird' names" inApp {

def uploadListAndRemoveFileWithName(prefix:String, name: String) = {
await(testBucket + BucketFile(URLEncoder.encode(prefix + name, "UTF-8"), "text/plain", "test".getBytes))

await(testBucket.list(prefix)) must beLike {
case Seq(BucketItem(itemName, false)) => itemName === (prefix + name)
}

await(testBucket - URLEncoder.encode(prefix + name, "UTF-8"))

success
}

uploadListAndRemoveFileWithName("sample/", "test file.txt")
uploadListAndRemoveFileWithName("sample/", "test&;-file.txt")
uploadListAndRemoveFileWithName("sample/", "test & file.txt")
uploadListAndRemoveFileWithName("sample/", "test+&+file.txt")
}
}

}

0 comments on commit 73bb622

Please sign in to comment.