Skip to content

Commit 77f1ba2

Browse files
committed
synced changes from swift-tools-support-core #88
1 parent 4b6d7e3 commit 77f1ba2

File tree

1 file changed

+0
-132
lines changed

1 file changed

+0
-132
lines changed

swift-tools-support-core/Tests/TSCUtilityTests/DownloaderTests.swift

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -208,138 +208,6 @@ class DownloaderTests: XCTestCase {
208208
}
209209
#endif
210210

211-
@available(OSX 10.13, *)
212-
func testAuthenticatedSuccess() {
213-
214-
let netrcContent = "machine protected.downloader-tests.com login anonymous password qwerty"
215-
guard case .success(let netrc) = Netrc.from(netrcContent) else {
216-
return XCTFail("Cannot load netrc content")
217-
}
218-
let authData = "anonymous:qwerty".data(using: .utf8)!
219-
let testAuthHeader = "Basic \(authData.base64EncodedString())"
220-
221-
#if os(macOS)
222-
let configuration = URLSessionConfiguration.default
223-
configuration.protocolClasses = [MockAuthenticatingURLProtocol.self]
224-
let downloader = FoundationDownloader(configuration: configuration)
225-
226-
mktmpdir { tmpdir in
227-
let url = URL(string: "https://protected.downloader-tests.com/testBasics.zip")!
228-
let destination = tmpdir.appending(component: "download")
229-
230-
let didStartLoadingExpectation = XCTestExpectation(description: "didStartLoading")
231-
let progress50Expectation = XCTestExpectation(description: "progress50")
232-
let progress100Expectation = XCTestExpectation(description: "progress100")
233-
let successExpectation = XCTestExpectation(description: "success")
234-
MockAuthenticatingURLProtocol.notifyDidStartLoading(for: url, completion: { didStartLoadingExpectation.fulfill() })
235-
236-
downloader.downloadFile(at: url, to: destination, withAuthorizationProvider: netrc, progress: { bytesDownloaded, totalBytesToDownload in
237-
238-
XCTAssertEqual(MockAuthenticatingURLProtocol.authenticationHeader(for: url), testAuthHeader)
239-
240-
switch (bytesDownloaded, totalBytesToDownload) {
241-
case (512, 1024):
242-
progress50Expectation.fulfill()
243-
case (1024, 1024):
244-
progress100Expectation.fulfill()
245-
default:
246-
XCTFail("unexpected progress")
247-
}
248-
}, completion: { result in
249-
switch result {
250-
case .success:
251-
XCTAssert(localFileSystem.exists(destination))
252-
let bytes = ByteString(Array(repeating: 0xbe, count: 512) + Array(repeating: 0xef, count: 512))
253-
XCTAssertEqual(try! localFileSystem.readFileContents(destination), bytes)
254-
successExpectation.fulfill()
255-
case .failure(let error):
256-
XCTFail("\(error)")
257-
}
258-
})
259-
260-
wait(for: [didStartLoadingExpectation], timeout: 1.0)
261-
262-
let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: "1.1", headerFields: [
263-
"Content-Length": "1024"
264-
])!
265-
266-
MockAuthenticatingURLProtocol.sendResponse(response, for: url)
267-
MockAuthenticatingURLProtocol.sendData(Data(repeating: 0xbe, count: 512), for: url)
268-
wait(for: [progress50Expectation], timeout: 1.0)
269-
MockAuthenticatingURLProtocol.sendData(Data(repeating: 0xef, count: 512), for: url)
270-
wait(for: [progress100Expectation], timeout: 1.0)
271-
MockAuthenticatingURLProtocol.sendCompletion(for: url)
272-
wait(for: [successExpectation], timeout: 1.0)
273-
}
274-
#endif
275-
}
276-
277-
@available(OSX 10.13, *)
278-
func testDefaultAuthenticationSuccess() {
279-
280-
let netrcContent = "default login default password default"
281-
guard case .success(let netrc) = Netrc.from(netrcContent) else {
282-
return XCTFail("Cannot load netrc content")
283-
}
284-
let authData = "default:default".data(using: .utf8)!
285-
let testAuthHeader = "Basic \(authData.base64EncodedString())"
286-
287-
#if os(macOS)
288-
let configuration = URLSessionConfiguration.default
289-
configuration.protocolClasses = [MockAuthenticatingURLProtocol.self]
290-
let downloader = FoundationDownloader(configuration: configuration)
291-
292-
mktmpdir { tmpdir in
293-
let url = URL(string: "https://restricted.downloader-tests.com/testBasics.zip")!
294-
let destination = tmpdir.appending(component: "download")
295-
296-
let didStartLoadingExpectation = XCTestExpectation(description: "didStartLoading")
297-
let progress50Expectation = XCTestExpectation(description: "progress50")
298-
let progress100Expectation = XCTestExpectation(description: "progress100")
299-
let successExpectation = XCTestExpectation(description: "success")
300-
MockAuthenticatingURLProtocol.notifyDidStartLoading(for: url, completion: { didStartLoadingExpectation.fulfill() })
301-
302-
downloader.downloadFile(at: url, to: destination, withAuthorizationProvider: netrc, progress: { bytesDownloaded, totalBytesToDownload in
303-
304-
XCTAssertEqual(MockAuthenticatingURLProtocol.authenticationHeader(for: url), testAuthHeader)
305-
306-
switch (bytesDownloaded, totalBytesToDownload) {
307-
case (512, 1024):
308-
progress50Expectation.fulfill()
309-
case (1024, 1024):
310-
progress100Expectation.fulfill()
311-
default:
312-
XCTFail("unexpected progress")
313-
}
314-
}, completion: { result in
315-
switch result {
316-
case .success:
317-
XCTAssert(localFileSystem.exists(destination))
318-
let bytes = ByteString(Array(repeating: 0xbe, count: 512) + Array(repeating: 0xef, count: 512))
319-
XCTAssertEqual(try! localFileSystem.readFileContents(destination), bytes)
320-
successExpectation.fulfill()
321-
case .failure(let error):
322-
XCTFail("\(error)")
323-
}
324-
})
325-
326-
wait(for: [didStartLoadingExpectation], timeout: 1.0)
327-
328-
let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: "1.1", headerFields: [
329-
"Content-Length": "1024"
330-
])!
331-
332-
MockAuthenticatingURLProtocol.sendResponse(response, for: url)
333-
MockAuthenticatingURLProtocol.sendData(Data(repeating: 0xbe, count: 512), for: url)
334-
wait(for: [progress50Expectation], timeout: 1.0)
335-
MockAuthenticatingURLProtocol.sendData(Data(repeating: 0xef, count: 512), for: url)
336-
wait(for: [progress100Expectation], timeout: 1.0)
337-
MockAuthenticatingURLProtocol.sendCompletion(for: url)
338-
wait(for: [successExpectation], timeout: 1.0)
339-
}
340-
#endif
341-
}
342-
343211
func testClientError() {
344212
// FIXME: Remove once https://github.com/apple/swift-corelibs-foundation/pull/2593 gets inside a toolchain.
345213
#if os(macOS)

0 commit comments

Comments
 (0)