Skip to content

Commit eff149c

Browse files
authored
Merge pull request #1607 from cmilr/add-URLProtectionSpace.description
2 parents c74229f + b98ddbb commit eff149c

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

DarwinCompatibilityTests.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
B9C89FCE1F6DCAEB00087AF4 /* Test.plist in Resources */ = {isa = PBXBuildFile; fileRef = B9C89FB91F6DCAEB00087AF4 /* Test.plist */; };
112112
B9F137A120B998D0000B7577 /* xdgTestHelper in CopyFiles */ = {isa = PBXBuildFile; fileRef = B917D31C20B0DB8B00728EE0 /* xdgTestHelper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
113113
B9F326A01FC714DD003C3599 /* DarwinShims.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F3269E1FC714DD003C3599 /* DarwinShims.swift */; };
114+
DAE7D0F320D8224200DC6C54 /* TestURLProtectionSpace.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE7D0F220D8224200DC6C54 /* TestURLProtectionSpace.swift */; };
114115
/* End PBXBuildFile section */
115116

116117
/* Begin PBXContainerItemProxy section */
@@ -255,6 +256,7 @@
255256
B9C89FB81F6DCAEB00087AF4 /* PropertyList-1.0.dtd */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "PropertyList-1.0.dtd"; path = "TestFoundation/Resources/PropertyList-1.0.dtd"; sourceTree = "<group>"; };
256257
B9C89FB91F6DCAEB00087AF4 /* Test.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Test.plist; path = TestFoundation/Resources/Test.plist; sourceTree = "<group>"; };
257258
B9F3269E1FC714DD003C3599 /* DarwinShims.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DarwinShims.swift; sourceTree = "<group>"; };
259+
DAE7D0F220D8224200DC6C54 /* TestURLProtectionSpace.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestURLProtectionSpace.swift; path = TestFoundation/TestURLProtectionSpace.swift; sourceTree = "<group>"; };
258260
/* End PBXFileReference section */
259261

260262
/* Begin PBXFrameworksBuildPhase section */
@@ -379,6 +381,7 @@
379381
B9C89F171F6BF89600087AF4 /* TestUnitConverter.swift */,
380382
B9C89F191F6BF89700087AF4 /* TestURL.swift */,
381383
B9C89F2D1F6BF89A00087AF4 /* TestURLCredential.swift */,
384+
DAE7D0F220D8224200DC6C54 /* TestURLProtectionSpace.swift */,
382385
B9C89EEB1F6BF89000087AF4 /* TestURLProtocol.swift */,
383386
B9C89F141F6BF89600087AF4 /* TestURLRequest.swift */,
384387
B9C89EF51F6BF89100087AF4 /* TestURLResponse.swift */,
@@ -574,6 +577,7 @@
574577
B9C89F4C1F6BF89C00087AF4 /* TestDateFormatter.swift in Sources */,
575578
B9C89F4D1F6BF89C00087AF4 /* TestHTTPCookie.swift in Sources */,
576579
B9C89F4E1F6BF89C00087AF4 /* TestNSError.swift in Sources */,
580+
DAE7D0F320D8224200DC6C54 /* TestURLProtectionSpace.swift in Sources */,
577581
B9C89F4F1F6BF89C00087AF4 /* TestNSString.swift in Sources */,
578582
B9C89F501F6BF89C00087AF4 /* TestNSUUID.swift in Sources */,
579583
B9C89F511F6BF89C00087AF4 /* TestPropertyListSerialization.swift in Sources */,

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@
373373
D51239DF1CD9DA0800D433EE /* CFSocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 5B5D88E01BBC9B0300234F36 /* CFSocket.c */; };
374374
D512D17C1CD883F00032E6A5 /* TestFileHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D512D17B1CD883F00032E6A5 /* TestFileHandle.swift */; };
375375
D5C40F331CDA1D460005690C /* TestOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C40F321CDA1D460005690C /* TestOperationQueue.swift */; };
376+
DAA79BD920D42C07004AF044 /* TestURLProtectionSpace.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA79BD820D42C07004AF044 /* TestURLProtectionSpace.swift */; };
376377
DCA8120B1F046D13000D0C86 /* TestCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA8120A1F046D13000D0C86 /* TestCodable.swift */; };
377378
E1A03F361C4828650023AF4D /* PropertyList-1.0.dtd in Resources */ = {isa = PBXBuildFile; fileRef = E1A03F351C4828650023AF4D /* PropertyList-1.0.dtd */; };
378379
E1A03F381C482C730023AF4D /* NSXMLDTDTestData.xml in Resources */ = {isa = PBXBuildFile; fileRef = E1A03F371C482C730023AF4D /* NSXMLDTDTestData.xml */; };
@@ -874,6 +875,7 @@
874875
D512D17B1CD883F00032E6A5 /* TestFileHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestFileHandle.swift; sourceTree = "<group>"; };
875876
D5C40F321CDA1D460005690C /* TestOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestOperationQueue.swift; sourceTree = "<group>"; };
876877
D834F9931C31C4060023812A /* TestNSOrderedSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSOrderedSet.swift; sourceTree = "<group>"; };
878+
DAA79BD820D42C07004AF044 /* TestURLProtectionSpace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestURLProtectionSpace.swift; sourceTree = "<group>"; };
877879
DCA8120A1F046D13000D0C86 /* TestCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCodable.swift; sourceTree = "<group>"; };
878880
DCDBB8321C1768AC00313299 /* TestNSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSData.swift; sourceTree = "<group>"; };
879881
E1A03F351C4828650023AF4D /* PropertyList-1.0.dtd */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "PropertyList-1.0.dtd"; sourceTree = "<group>"; };
@@ -1545,6 +1547,7 @@
15451547
EA66F6431BF1619600136161 /* TestURL.swift */,
15461548
F9E0BB361CA70B8000F7FF3C /* TestURLCredential.swift */,
15471549
83712C8D1C1684900049AD49 /* TestNSURLRequest.swift */,
1550+
DAA79BD820D42C07004AF044 /* TestURLProtectionSpace.swift */,
15481551
7A7D6FBA1C16439400957E2E /* TestURLResponse.swift */,
15491552
5B1FD9E21D6D17B80080E83C /* TestURLSession.swift */,
15501553
555683BC1C1250E70041D4C6 /* TestUserDefaults.swift */,
@@ -2540,6 +2543,7 @@
25402543
D512D17C1CD883F00032E6A5 /* TestFileHandle.swift in Sources */,
25412544
D4FE895B1D703D1100DA7986 /* TestURLRequest.swift in Sources */,
25422545
684C79011F62B611005BD73E /* TestNSNumberBridging.swift in Sources */,
2546+
DAA79BD920D42C07004AF044 /* TestURLProtectionSpace.swift in Sources */,
25432547
B951B5EC1F4E2A2000D8B332 /* TestNSLock.swift in Sources */,
25442548
5B13B33A1C582D4C00651CE2 /* TestNSNumber.swift in Sources */,
25452549
5B13B3521C582D4C00651CE2 /* TestNSValue.swift in Sources */,

Foundation/URLProtectionSpace.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,58 @@ open class URLProtectionSpace : NSObject, NSSecureCoding, NSCopying {
249249
open override func isProxy() -> Bool {
250250
return _isProxy
251251
}
252+
253+
/*!
254+
A string that represents the contents of the URLProtectionSpace Object.
255+
This property is intended to produce readable output.
256+
*/
257+
open override var description: String {
258+
let authMethods: Set<String> = [
259+
NSURLAuthenticationMethodDefault,
260+
NSURLAuthenticationMethodHTTPBasic,
261+
NSURLAuthenticationMethodHTTPDigest,
262+
NSURLAuthenticationMethodHTMLForm,
263+
NSURLAuthenticationMethodNTLM,
264+
NSURLAuthenticationMethodNegotiate,
265+
NSURLAuthenticationMethodClientCertificate,
266+
NSURLAuthenticationMethodServerTrust
267+
]
268+
var result = "<\(type(of: self)) \(Unmanaged.passUnretained(self).toOpaque())>: "
269+
result += "Host:\(host), "
270+
271+
if let prot = self.protocol {
272+
result += "Server:\(prot), "
273+
} else {
274+
result += "Server:(null), "
275+
}
276+
277+
if authMethods.contains(self.authenticationMethod) {
278+
result += "Auth-Scheme:\(self.authenticationMethod), "
279+
} else {
280+
result += "Auth-Scheme:NSURLAuthenticationMethodDefault, "
281+
}
282+
283+
if let realm = self.realm {
284+
result += "Realm:\(realm), "
285+
} else {
286+
result += "Realm:(null), "
287+
}
288+
289+
result += "Port:\(self.port), "
290+
291+
if _isProxy {
292+
result += "Proxy:YES, "
293+
} else {
294+
result += "Proxy:NO, "
295+
}
296+
297+
if let proxyType = self.proxyType {
298+
result += "Proxy-Type:\(proxyType), "
299+
} else {
300+
result += "Proxy-Type:(null)"
301+
}
302+
return result
303+
}
252304
}
253305

254306
extension URLProtectionSpace {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
class TestURLProtectionSpace : XCTestCase {
11+
12+
static var allTests: [(String, (TestURLProtectionSpace) -> () throws -> Void)] {
13+
return [
14+
("test_description", test_description),
15+
]
16+
}
17+
18+
func test_description() {
19+
var space = URLProtectionSpace(
20+
host: "apple.com",
21+
port: 80,
22+
protocol: "http",
23+
realm: nil,
24+
authenticationMethod: "basic"
25+
)
26+
XCTAssert(space.description.hasPrefix("<\(type(of: space))"))
27+
XCTAssert(space.description.hasSuffix(": Host:apple.com, Server:http, Auth-Scheme:NSURLAuthenticationMethodDefault, Realm:(null), Port:80, Proxy:NO, Proxy-Type:(null)"))
28+
29+
space = URLProtectionSpace(
30+
host: "apple.com",
31+
port: 80,
32+
protocol: "http",
33+
realm: nil,
34+
authenticationMethod: "NSURLAuthenticationMethodHTMLForm"
35+
)
36+
XCTAssert(space.description.hasPrefix("<\(type(of: space))"))
37+
XCTAssert(space.description.hasSuffix(": Host:apple.com, Server:http, Auth-Scheme:NSURLAuthenticationMethodHTMLForm, Realm:(null), Port:80, Proxy:NO, Proxy-Type:(null)"))
38+
}
39+
}

TestFoundation/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ XCTMain([
7777
testCase(TestURL.allTests),
7878
testCase(TestURLComponents.allTests),
7979
testCase(TestURLCredential.allTests),
80+
testCase(TestURLProtectionSpace.allTests),
8081
testCase(TestURLProtocol.allTests),
8182
testCase(TestNSURLRequest.allTests),
8283
testCase(TestURLRequest.allTests),

0 commit comments

Comments
 (0)