|
|
@@ -339,337 +339,302 @@ class RequestResponseTestCase: BaseTestCase {
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
-extension Request {
|
|
|
- fileprivate func preValidate(operation: @escaping () -> Void) -> Self {
|
|
|
- internalQueue.addOperation {
|
|
|
- operation()
|
|
|
- }
|
|
|
+class RequestDescriptionTestCase: BaseTestCase {
|
|
|
+ func testRequestDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/get"
|
|
|
+ let delegate = SessionDelegate(startRequestsImmediately: false)
|
|
|
+ let manager = SessionManager(delegate: delegate)
|
|
|
+ let request = manager.request(urlString)
|
|
|
+ let initialRequestDescription = request.description
|
|
|
|
|
|
- return self
|
|
|
- }
|
|
|
+ let expectation = self.expectation(description: "Request description should update: \(urlString)")
|
|
|
|
|
|
- fileprivate func postValidate(operation: @escaping () -> Void) -> Self {
|
|
|
- internalQueue.addOperation {
|
|
|
- operation()
|
|
|
- }
|
|
|
+ var response: HTTPURLResponse?
|
|
|
+
|
|
|
+ // When
|
|
|
+ request.response { resp in
|
|
|
+ response = resp.response
|
|
|
+
|
|
|
+ expectation.fulfill()
|
|
|
+ }.resume()
|
|
|
|
|
|
- return self
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let finalRequestDescription = request.description
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertEqual(initialRequestDescription, "No request created yet.")
|
|
|
+ XCTAssertEqual(finalRequestDescription, "GET https://httpbin.org/get (\(response?.statusCode ?? -1))")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
-// TODO: Do we still want this API?
|
|
|
-class RequestExtensionTestCase: BaseTestCase {
|
|
|
- func testThatRequestExtensionHasAccessToTaskDelegateQueue() {
|
|
|
+class RequestDebugDescriptionTestCase: BaseTestCase {
|
|
|
+ // MARK: Properties
|
|
|
+
|
|
|
+ let manager: SessionManager = {
|
|
|
+ let manager = SessionManager()
|
|
|
+
|
|
|
+ return manager
|
|
|
+ }()
|
|
|
+
|
|
|
+ let managerWithAcceptLanguageHeader: SessionManager = {
|
|
|
+ var headers = HTTPHeaders.defaultHTTPHeaders
|
|
|
+ headers["Accept-Language"] = "en-US"
|
|
|
+
|
|
|
+ let configuration = URLSessionConfiguration.alamofireDefault
|
|
|
+ configuration.httpAdditionalHeaders = headers
|
|
|
+
|
|
|
+ let manager = SessionManager(configuration: configuration)
|
|
|
+
|
|
|
+ return manager
|
|
|
+ }()
|
|
|
+
|
|
|
+ let managerWithContentTypeHeader: SessionManager = {
|
|
|
+ var headers = HTTPHeaders.defaultHTTPHeaders
|
|
|
+ headers["Content-Type"] = "application/json"
|
|
|
+
|
|
|
+ let configuration = URLSessionConfiguration.alamofireDefault
|
|
|
+ configuration.httpAdditionalHeaders = headers
|
|
|
+
|
|
|
+ let manager = SessionManager(configuration: configuration)
|
|
|
+
|
|
|
+ return manager
|
|
|
+ }()
|
|
|
+
|
|
|
+ func managerWithCookie(_ cookie: HTTPCookie) -> SessionManager {
|
|
|
+ let configuration = URLSessionConfiguration.alamofireDefault
|
|
|
+ configuration.httpCookieStorage?.setCookie(cookie)
|
|
|
+
|
|
|
+ return SessionManager(configuration: configuration)
|
|
|
+ }
|
|
|
+
|
|
|
+ let managerDisallowingCookies: SessionManager = {
|
|
|
+ let configuration = URLSessionConfiguration.alamofireDefault
|
|
|
+ configuration.httpShouldSetCookies = false
|
|
|
+
|
|
|
+ let manager = SessionManager(configuration: configuration)
|
|
|
+
|
|
|
+ return manager
|
|
|
+ }()
|
|
|
+
|
|
|
+ // MARK: Tests
|
|
|
+
|
|
|
+ func testGETRequestDebugDescription() {
|
|
|
// Given
|
|
|
let urlString = "https://httpbin.org/get"
|
|
|
- let expectation = self.expectation(description: "GET request should succeed: \(urlString)")
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = manager.request(urlString).response { _ in expectation.fulfill() }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
+ XCTAssertTrue(components.contains("-X"))
|
|
|
+ XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
+ }
|
|
|
|
|
|
- var responses: [String] = []
|
|
|
+ func testGETRequestWithJSONHeaderDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/get"
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
|
|
|
// When
|
|
|
- Alamofire.request(urlString)
|
|
|
- .preValidate {
|
|
|
- responses.append("preValidate")
|
|
|
- }
|
|
|
- .validate()
|
|
|
- .postValidate {
|
|
|
- responses.append("postValidate")
|
|
|
- }
|
|
|
+ let headers: [String: String] = [ "X-Custom-Header": "{\"key\": \"value\"}" ]
|
|
|
+ let request = manager.request(urlString, headers: headers).response { _ in expectation.fulfill() }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "-H \"X-Custom-Header: {\\\"key\\\": \\\"value\\\"}\""))
|
|
|
+ }
|
|
|
+
|
|
|
+ func testGETRequestWithDuplicateHeadersDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/get"
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
+
|
|
|
+ // When
|
|
|
+ let headers = [ "Accept-Language": "en-GB" ]
|
|
|
+ let request = managerWithAcceptLanguageHeader.request(urlString, headers: headers).response { _ in expectation.fulfill() }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
+ XCTAssertTrue(components.contains("-X"))
|
|
|
+ XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
+
|
|
|
+ let tokens = request.debugDescription.components(separatedBy: "Accept-Language:")
|
|
|
+ XCTAssertTrue(tokens.count == 2, "command should contain a single Accept-Language header")
|
|
|
+
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "-H \"Accept-Language: en-GB\""))
|
|
|
+ }
|
|
|
+
|
|
|
+ func testPOSTRequestDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/post"
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
+
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = manager.request(urlString, method: .post).response { _ in expectation.fulfill() }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
+ XCTAssertEqual(components[3..<5], ["-X", "POST"])
|
|
|
+ XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
+ }
|
|
|
+
|
|
|
+ func testPOSTRequestWithJSONParametersDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/post"
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
+
|
|
|
+ let parameters = [
|
|
|
+ "foo": "bar",
|
|
|
+ "fo\"o": "b\"ar",
|
|
|
+ "f'oo": "ba'r"
|
|
|
+ ]
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = manager.request(urlString, method: .post, parameters: parameters, encoding: JSONEncoding.default).response {
|
|
|
+ _ in expectation.fulfill()
|
|
|
+ }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
+ XCTAssertEqual(components[3..<5], ["-X", "POST"])
|
|
|
+
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "-H \"Content-Type: application/json\""))
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "-d \"{"))
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "\\\"f'oo\\\":\\\"ba'r\\\""))
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "\\\"fo\\\\\\\"o\\\":\\\"b\\\\\\\"ar\\\""))
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "\\\"foo\\\":\\\"bar\\"))
|
|
|
+
|
|
|
+ XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
+ }
|
|
|
+
|
|
|
+ func testPOSTRequestWithCookieDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/post"
|
|
|
+
|
|
|
+ let properties = [
|
|
|
+ HTTPCookiePropertyKey.domain: "httpbin.org",
|
|
|
+ HTTPCookiePropertyKey.path: "/post",
|
|
|
+ HTTPCookiePropertyKey.name: "foo",
|
|
|
+ HTTPCookiePropertyKey.value: "bar",
|
|
|
+ ]
|
|
|
+
|
|
|
+ let cookie = HTTPCookie(properties: properties)!
|
|
|
+ let cookieManager = managerWithCookie(cookie)
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
+
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = cookieManager.request(urlString, method: .post).response { _ in expectation.fulfill() }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
+ XCTAssertEqual(components[3..<5], ["-X", "POST"])
|
|
|
+ XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
+ XCTAssertEqual(components[5..<6], ["-b"])
|
|
|
+ }
|
|
|
+
|
|
|
+ func testPOSTRequestWithCookiesDisabledDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/post"
|
|
|
+
|
|
|
+ let properties = [
|
|
|
+ HTTPCookiePropertyKey.domain: "httpbin.org",
|
|
|
+ HTTPCookiePropertyKey.path: "/post",
|
|
|
+ HTTPCookiePropertyKey.name: "foo",
|
|
|
+ HTTPCookiePropertyKey.value: "bar",
|
|
|
+ ]
|
|
|
+
|
|
|
+ let cookie = HTTPCookie(properties: properties)!
|
|
|
+ managerDisallowingCookies.session.configuration.httpCookieStorage?.setCookie(cookie)
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = managerDisallowingCookies.request(urlString, method: .post)
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ let cookieComponents = components.filter { $0 == "-b" }
|
|
|
+ XCTAssertTrue(cookieComponents.isEmpty)
|
|
|
+ }
|
|
|
+
|
|
|
+ func testMultipartFormDataRequestWithDuplicateHeadersDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "https://httpbin.org/post"
|
|
|
+ let japaneseData = Data("日本語".utf8)
|
|
|
+ let expectation = self.expectation(description: "multipart form data encoding should succeed")
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = managerWithContentTypeHeader.upload(multipartFormData: { (data) in
|
|
|
+ data.append(japaneseData, withName: "japanese")
|
|
|
+ }, to: urlString)
|
|
|
.response { _ in
|
|
|
- responses.append("response")
|
|
|
expectation.fulfill()
|
|
|
}
|
|
|
|
|
|
waitForExpectations(timeout: timeout, handler: nil)
|
|
|
|
|
|
+ let components = cURLCommandComponents(for: request)
|
|
|
+
|
|
|
// Then
|
|
|
- if responses.count == 3 {
|
|
|
- XCTAssertEqual(responses[0], "preValidate")
|
|
|
- XCTAssertEqual(responses[1], "postValidate")
|
|
|
- XCTAssertEqual(responses[2], "response")
|
|
|
- } else {
|
|
|
- XCTFail("responses count should be equal to 3")
|
|
|
- }
|
|
|
+ XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
+ XCTAssertTrue(components.contains("-X"))
|
|
|
+ XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
+
|
|
|
+ let tokens = request.debugDescription.components(separatedBy: "Content-Type:")
|
|
|
+ XCTAssertTrue(tokens.count == 2, "command should contain a single Content-Type header")
|
|
|
+
|
|
|
+ XCTAssertNotNil(request.debugDescription.range(of: "-H \"Content-Type: multipart/form-data;"))
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-// MARK: -
|
|
|
+ func testThatRequestWithInvalidURLDebugDescription() {
|
|
|
+ // Given
|
|
|
+ let urlString = "invalid_url"
|
|
|
+ let expectation = self.expectation(description: "request should complete")
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = manager.request(urlString).response { _ in expectation.fulfill() }
|
|
|
+
|
|
|
+ waitForExpectations(timeout: timeout, handler: nil)
|
|
|
+
|
|
|
+ let debugDescription = request.debugDescription
|
|
|
|
|
|
-//class RequestDescriptionTestCase: BaseTestCase {
|
|
|
-// func testRequestDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/get"
|
|
|
-// let request = Alamofire.request(urlString)
|
|
|
-// let initialRequestDescription = request.description
|
|
|
-//
|
|
|
-// let expectation = self.expectation(description: "Request description should update: \(urlString)")
|
|
|
-//
|
|
|
-// var finalRequestDescription: String?
|
|
|
-// var response: HTTPURLResponse?
|
|
|
-//
|
|
|
-// // When
|
|
|
-// request.response { resp in
|
|
|
-// finalRequestDescription = request.description
|
|
|
-// response = resp.response
|
|
|
-//
|
|
|
-// expectation.fulfill()
|
|
|
-// }
|
|
|
-//
|
|
|
-// waitForExpectations(timeout: timeout, handler: nil)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(initialRequestDescription, "GET https://httpbin.org/get")
|
|
|
-// XCTAssertEqual(finalRequestDescription, "GET https://httpbin.org/get (\(response?.statusCode ?? -1))")
|
|
|
-// }
|
|
|
-//}
|
|
|
+ // Then
|
|
|
+ XCTAssertNotNil(debugDescription, "debugDescription should not crash")
|
|
|
+ }
|
|
|
|
|
|
-// MARK: -
|
|
|
+ // MARK: Test Helper Methods
|
|
|
|
|
|
-//class RequestDebugDescriptionTestCase: BaseTestCase {
|
|
|
-// // MARK: Properties
|
|
|
-//
|
|
|
-// let manager: SessionManager = {
|
|
|
-// let manager = SessionManager(configuration: .default)
|
|
|
-// manager.startRequestsImmediately = false
|
|
|
-// return manager
|
|
|
-// }()
|
|
|
-//
|
|
|
-// let managerWithAcceptLanguageHeader: SessionManager = {
|
|
|
-// var headers = SessionManager.default.session.configuration.httpAdditionalHeaders ?? [:]
|
|
|
-// headers["Accept-Language"] = "en-US"
|
|
|
-//
|
|
|
-// let configuration = URLSessionConfiguration.default
|
|
|
-// configuration.httpAdditionalHeaders = headers
|
|
|
-//
|
|
|
-// let manager = SessionManager(configuration: configuration)
|
|
|
-// manager.startRequestsImmediately = false
|
|
|
-//
|
|
|
-// return manager
|
|
|
-// }()
|
|
|
-//
|
|
|
-// let managerWithContentTypeHeader: SessionManager = {
|
|
|
-// var headers = SessionManager.default.session.configuration.httpAdditionalHeaders ?? [:]
|
|
|
-// headers["Content-Type"] = "application/json"
|
|
|
-//
|
|
|
-// let configuration = URLSessionConfiguration.default
|
|
|
-// configuration.httpAdditionalHeaders = headers
|
|
|
-//
|
|
|
-// let manager = SessionManager(configuration: configuration)
|
|
|
-// manager.startRequestsImmediately = false
|
|
|
-//
|
|
|
-// return manager
|
|
|
-// }()
|
|
|
-//
|
|
|
-// let managerDisallowingCookies: SessionManager = {
|
|
|
-// let configuration = URLSessionConfiguration.default
|
|
|
-// configuration.httpShouldSetCookies = false
|
|
|
-//
|
|
|
-// let manager = SessionManager(configuration: configuration)
|
|
|
-// manager.startRequestsImmediately = false
|
|
|
-//
|
|
|
-// return manager
|
|
|
-// }()
|
|
|
-//
|
|
|
-// // MARK: Tests
|
|
|
-//
|
|
|
-// func testGETRequestDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/get"
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let request = manager.request(urlString)
|
|
|
-// let components = cURLCommandComponents(for: request)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
-// XCTAssertFalse(components.contains("-X"))
|
|
|
-// XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testGETRequestWithJSONHeaderDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/get"
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let headers: [String: String] = [ "X-Custom-Header": "{\"key\": \"value\"}" ]
|
|
|
-// let request = manager.request(urlString, headers: headers)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "-H \"X-Custom-Header: {\\\"key\\\": \\\"value\\\"}\""))
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testGETRequestWithDuplicateHeadersDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/get"
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let headers = [ "Accept-Language": "en-GB" ]
|
|
|
-// let request = managerWithAcceptLanguageHeader.request(urlString, headers: headers)
|
|
|
-// let components = cURLCommandComponents(for: request)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
-// XCTAssertFalse(components.contains("-X"))
|
|
|
-// XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
-//
|
|
|
-// let tokens = request.debugDescription.components(separatedBy: "Accept-Language:")
|
|
|
-// XCTAssertTrue(tokens.count == 2, "command should contain a single Accept-Language header")
|
|
|
-//
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "-H \"Accept-Language: en-GB\""))
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testPOSTRequestDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/post"
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let request = manager.request(urlString, method: .post)
|
|
|
-// let components = cURLCommandComponents(for: request)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
-// XCTAssertEqual(components[3..<5], ["-X", "POST"])
|
|
|
-// XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testPOSTRequestWithJSONParametersDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/post"
|
|
|
-//
|
|
|
-// let parameters = [
|
|
|
-// "foo": "bar",
|
|
|
-// "fo\"o": "b\"ar",
|
|
|
-// "f'oo": "ba'r"
|
|
|
-// ]
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let request = manager.request(urlString, method: .post, parameters: parameters, encoding: JSONEncoding.default)
|
|
|
-// let components = cURLCommandComponents(for: request)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
-// XCTAssertEqual(components[3..<5], ["-X", "POST"])
|
|
|
-//
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "-H \"Content-Type: application/json\""))
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "-d \"{"))
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "\\\"f'oo\\\":\\\"ba'r\\\""))
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "\\\"fo\\\\\\\"o\\\":\\\"b\\\\\\\"ar\\\""))
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "\\\"foo\\\":\\\"bar\\"))
|
|
|
-//
|
|
|
-// XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testPOSTRequestWithCookieDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/post"
|
|
|
-//
|
|
|
-// let properties = [
|
|
|
-// HTTPCookiePropertyKey.domain: "httpbin.org",
|
|
|
-// HTTPCookiePropertyKey.path: "/post",
|
|
|
-// HTTPCookiePropertyKey.name: "foo",
|
|
|
-// HTTPCookiePropertyKey.value: "bar",
|
|
|
-// ]
|
|
|
-//
|
|
|
-// let cookie = HTTPCookie(properties: properties)!
|
|
|
-// manager.session.configuration.httpCookieStorage?.setCookie(cookie)
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let request = manager.request(urlString, method: .post)
|
|
|
-// let components = cURLCommandComponents(for: request)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
-// XCTAssertEqual(components[3..<5], ["-X", "POST"])
|
|
|
-// XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
-// XCTAssertEqual(components[5..<6], ["-b"])
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testPOSTRequestWithCookiesDisabledDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/post"
|
|
|
-//
|
|
|
-// let properties = [
|
|
|
-// HTTPCookiePropertyKey.domain: "httpbin.org",
|
|
|
-// HTTPCookiePropertyKey.path: "/post",
|
|
|
-// HTTPCookiePropertyKey.name: "foo",
|
|
|
-// HTTPCookiePropertyKey.value: "bar",
|
|
|
-// ]
|
|
|
-//
|
|
|
-// let cookie = HTTPCookie(properties: properties)!
|
|
|
-// managerDisallowingCookies.session.configuration.httpCookieStorage?.setCookie(cookie)
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let request = managerDisallowingCookies.request(urlString, method: .post)
|
|
|
-// let components = cURLCommandComponents(for: request)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// let cookieComponents = components.filter { $0 == "-b" }
|
|
|
-// XCTAssertTrue(cookieComponents.isEmpty)
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testMultipartFormDataRequestWithDuplicateHeadersDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "https://httpbin.org/post"
|
|
|
-// let japaneseData = Data("日本語".utf8)
|
|
|
-// let expectation = self.expectation(description: "multipart form data encoding should succeed")
|
|
|
-//
|
|
|
-// var request: Request?
|
|
|
-// var components: [String] = []
|
|
|
-//
|
|
|
-// // When
|
|
|
-// managerWithContentTypeHeader.upload(
|
|
|
-// multipartFormData: { multipartFormData in
|
|
|
-// multipartFormData.append(japaneseData, withName: "japanese")
|
|
|
-// },
|
|
|
-// to: urlString,
|
|
|
-// encodingCompletion: { result in
|
|
|
-// switch result {
|
|
|
-// case .success(let upload, _, _):
|
|
|
-// request = upload
|
|
|
-// components = self.cURLCommandComponents(for: upload)
|
|
|
-//
|
|
|
-// expectation.fulfill()
|
|
|
-// case .failure:
|
|
|
-// expectation.fulfill()
|
|
|
-// }
|
|
|
-// }
|
|
|
-// )
|
|
|
-//
|
|
|
-// waitForExpectations(timeout: timeout, handler: nil)
|
|
|
-//
|
|
|
-// debugPrint(request!)
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
|
|
|
-// XCTAssertTrue(components.contains("-X"))
|
|
|
-// XCTAssertEqual(components.last, "\"\(urlString)\"")
|
|
|
-//
|
|
|
-// let tokens = request.debugDescription.components(separatedBy: "Content-Type:")
|
|
|
-// XCTAssertTrue(tokens.count == 2, "command should contain a single Content-Type header")
|
|
|
-//
|
|
|
-// XCTAssertNotNil(request.debugDescription.range(of: "-H \"Content-Type: multipart/form-data;"))
|
|
|
-// }
|
|
|
-//
|
|
|
-// func testThatRequestWithInvalidURLDebugDescription() {
|
|
|
-// // Given
|
|
|
-// let urlString = "invalid_url"
|
|
|
-//
|
|
|
-// // When
|
|
|
-// let request = manager.request(urlString)
|
|
|
-// let debugDescription = request.debugDescription
|
|
|
-//
|
|
|
-// // Then
|
|
|
-// XCTAssertNotNil(debugDescription, "debugDescription should not crash")
|
|
|
-// }
|
|
|
-//
|
|
|
-// // MARK: Test Helper Methods
|
|
|
-//
|
|
|
-// private func cURLCommandComponents(for request: Request) -> [String] {
|
|
|
-// let whitespaceCharacterSet = CharacterSet.whitespacesAndNewlines
|
|
|
-// return request.debugDescription
|
|
|
-// .components(separatedBy: whitespaceCharacterSet)
|
|
|
-// .filter { $0 != "" && $0 != "\\" }
|
|
|
-// }
|
|
|
-//}
|
|
|
+ private func cURLCommandComponents(for request: Request) -> [String] {
|
|
|
+ let whitespaceCharacterSet = CharacterSet.whitespacesAndNewlines
|
|
|
+ return request.debugDescription
|
|
|
+ .components(separatedBy: whitespaceCharacterSet)
|
|
|
+ .filter { $0 != "" && $0 != "\\" }
|
|
|
+ }
|
|
|
+}
|