Make sure urls have trailing slashes (#6)
* Make sure urls have trailing slashes * Cleaned up code Co-authored-by: Joel Saltzman <>
This commit is contained in:
parent
1867819c9f
commit
2e205327f8
|
@ -120,7 +120,12 @@ public struct AWSSigner {
|
|||
var date : String { return String(datetime.prefix(8))}
|
||||
|
||||
init(url: URL, method: HTTPMethod = .GET, headers: HTTPHeaders = HTTPHeaders(), body: BodyData? = nil, bodyHash: String? = nil, date: String, signer: AWSSigner) {
|
||||
self.url = url
|
||||
if url.path == "" {
|
||||
//URL has to have trailing slash
|
||||
self.url = url.appendingPathComponent("/")
|
||||
} else {
|
||||
self.url = url
|
||||
}
|
||||
self.method = method
|
||||
self.datetime = date
|
||||
self.unsignedURL = self.url
|
||||
|
|
|
@ -66,11 +66,21 @@ final class AWSSignerTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testTrailingSlash() {
|
||||
let signer = AWSSigner(credentials: credentials, name: "dynamodb", region:"us-west-1")
|
||||
let url = URL(string: "https://dynamodb.us-west-1.amazonaws.com")!
|
||||
let dateString = AWSSigner.timestamp(Date(timeIntervalSinceReferenceDate: 0))
|
||||
let signingData = AWSSigner.SigningData(url: url, method: .POST, date: dateString, signer: signer)
|
||||
XCTAssertTrue(signingData.url.absoluteString.hasSuffix("amazonaws.com/"))
|
||||
XCTAssertTrue(signingData.unsignedURL.absoluteString.hasSuffix("amazonaws.com/"))
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testSignGetHeaders", testSignGetHeaders),
|
||||
("testSignPutHeaders", testSignPutHeaders),
|
||||
("testSignS3GetURL", testSignS3GetURL),
|
||||
("testSignS3PutURL", testSignS3PutURL),
|
||||
("testBodyData", testBodyData),
|
||||
("testTrailingSlash", testTrailingSlash),
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue