Skip to content

[SR-7938] Add URLProtectionSpace.description #1607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DarwinCompatibilityTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
B9C89FCE1F6DCAEB00087AF4 /* Test.plist in Resources */ = {isa = PBXBuildFile; fileRef = B9C89FB91F6DCAEB00087AF4 /* Test.plist */; };
B9F137A120B998D0000B7577 /* xdgTestHelper in CopyFiles */ = {isa = PBXBuildFile; fileRef = B917D31C20B0DB8B00728EE0 /* xdgTestHelper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
B9F326A01FC714DD003C3599 /* DarwinShims.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F3269E1FC714DD003C3599 /* DarwinShims.swift */; };
DAE7D0F320D8224200DC6C54 /* TestURLProtectionSpace.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE7D0F220D8224200DC6C54 /* TestURLProtectionSpace.swift */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -379,6 +381,7 @@
B9C89F171F6BF89600087AF4 /* TestUnitConverter.swift */,
B9C89F191F6BF89700087AF4 /* TestURL.swift */,
B9C89F2D1F6BF89A00087AF4 /* TestURLCredential.swift */,
DAE7D0F220D8224200DC6C54 /* TestURLProtectionSpace.swift */,
B9C89EEB1F6BF89000087AF4 /* TestURLProtocol.swift */,
B9C89F141F6BF89600087AF4 /* TestURLRequest.swift */,
B9C89EF51F6BF89100087AF4 /* TestURLResponse.swift */,
Expand Down Expand Up @@ -574,6 +577,7 @@
B9C89F4C1F6BF89C00087AF4 /* TestDateFormatter.swift in Sources */,
B9C89F4D1F6BF89C00087AF4 /* TestHTTPCookie.swift in Sources */,
B9C89F4E1F6BF89C00087AF4 /* TestNSError.swift in Sources */,
DAE7D0F320D8224200DC6C54 /* TestURLProtectionSpace.swift in Sources */,
B9C89F4F1F6BF89C00087AF4 /* TestNSString.swift in Sources */,
B9C89F501F6BF89C00087AF4 /* TestNSUUID.swift in Sources */,
B9C89F511F6BF89C00087AF4 /* TestPropertyListSerialization.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
D51239DF1CD9DA0800D433EE /* CFSocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 5B5D88E01BBC9B0300234F36 /* CFSocket.c */; };
D512D17C1CD883F00032E6A5 /* TestFileHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D512D17B1CD883F00032E6A5 /* TestFileHandle.swift */; };
D5C40F331CDA1D460005690C /* TestOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C40F321CDA1D460005690C /* TestOperationQueue.swift */; };
DAA79BD920D42C07004AF044 /* TestURLProtectionSpace.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA79BD820D42C07004AF044 /* TestURLProtectionSpace.swift */; };
DCA8120B1F046D13000D0C86 /* TestCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA8120A1F046D13000D0C86 /* TestCodable.swift */; };
E1A03F361C4828650023AF4D /* PropertyList-1.0.dtd in Resources */ = {isa = PBXBuildFile; fileRef = E1A03F351C4828650023AF4D /* PropertyList-1.0.dtd */; };
E1A03F381C482C730023AF4D /* NSXMLDTDTestData.xml in Resources */ = {isa = PBXBuildFile; fileRef = E1A03F371C482C730023AF4D /* NSXMLDTDTestData.xml */; };
Expand Down Expand Up @@ -874,6 +875,7 @@
D512D17B1CD883F00032E6A5 /* TestFileHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestFileHandle.swift; sourceTree = "<group>"; };
D5C40F321CDA1D460005690C /* TestOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestOperationQueue.swift; sourceTree = "<group>"; };
D834F9931C31C4060023812A /* TestNSOrderedSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSOrderedSet.swift; sourceTree = "<group>"; };
DAA79BD820D42C07004AF044 /* TestURLProtectionSpace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestURLProtectionSpace.swift; sourceTree = "<group>"; };
DCA8120A1F046D13000D0C86 /* TestCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCodable.swift; sourceTree = "<group>"; };
DCDBB8321C1768AC00313299 /* TestNSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSData.swift; sourceTree = "<group>"; };
E1A03F351C4828650023AF4D /* PropertyList-1.0.dtd */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "PropertyList-1.0.dtd"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1545,6 +1547,7 @@
EA66F6431BF1619600136161 /* TestURL.swift */,
F9E0BB361CA70B8000F7FF3C /* TestURLCredential.swift */,
83712C8D1C1684900049AD49 /* TestNSURLRequest.swift */,
DAA79BD820D42C07004AF044 /* TestURLProtectionSpace.swift */,
7A7D6FBA1C16439400957E2E /* TestURLResponse.swift */,
5B1FD9E21D6D17B80080E83C /* TestURLSession.swift */,
555683BC1C1250E70041D4C6 /* TestUserDefaults.swift */,
Expand Down Expand Up @@ -2540,6 +2543,7 @@
D512D17C1CD883F00032E6A5 /* TestFileHandle.swift in Sources */,
D4FE895B1D703D1100DA7986 /* TestURLRequest.swift in Sources */,
684C79011F62B611005BD73E /* TestNSNumberBridging.swift in Sources */,
DAA79BD920D42C07004AF044 /* TestURLProtectionSpace.swift in Sources */,
B951B5EC1F4E2A2000D8B332 /* TestNSLock.swift in Sources */,
5B13B33A1C582D4C00651CE2 /* TestNSNumber.swift in Sources */,
5B13B3521C582D4C00651CE2 /* TestNSValue.swift in Sources */,
Expand Down
52 changes: 52 additions & 0 deletions Foundation/URLProtectionSpace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,58 @@ open class URLProtectionSpace : NSObject, NSSecureCoding, NSCopying {
open override func isProxy() -> Bool {
return _isProxy
}

/*!
A string that represents the contents of the URLProtectionSpace Object.
This property is intended to produce readable output.
*/
open override var description: String {
let authMethods: Set<String> = [
NSURLAuthenticationMethodDefault,
NSURLAuthenticationMethodHTTPBasic,
NSURLAuthenticationMethodHTTPDigest,
NSURLAuthenticationMethodHTMLForm,
NSURLAuthenticationMethodNTLM,
NSURLAuthenticationMethodNegotiate,
NSURLAuthenticationMethodClientCertificate,
NSURLAuthenticationMethodServerTrust
]
var result = "<\(type(of: self)) \(Unmanaged.passUnretained(self).toOpaque())>: "
result += "Host:\(host), "

if let prot = self.protocol {
result += "Server:\(prot), "
} else {
result += "Server:(null), "
}

if authMethods.contains(self.authenticationMethod) {
result += "Auth-Scheme:\(self.authenticationMethod), "
} else {
result += "Auth-Scheme:NSURLAuthenticationMethodDefault, "
}

if let realm = self.realm {
result += "Realm:\(realm), "
} else {
result += "Realm:(null), "
}

result += "Port:\(self.port), "

if _isProxy {
result += "Proxy:YES, "
} else {
result += "Proxy:NO, "
}

if let proxyType = self.proxyType {
result += "Proxy-Type:\(proxyType), "
} else {
result += "Proxy-Type:(null)"
}
return result
}
}

extension URLProtectionSpace {
Expand Down
39 changes: 39 additions & 0 deletions TestFoundation/TestURLProtectionSpace.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new file so that date should just be 2018

//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

class TestURLProtectionSpace : XCTestCase {

static var allTests: [(String, (TestURLProtectionSpace) -> () throws -> Void)] {
return [
("test_description", test_description),
]
}

func test_description() {
var space = URLProtectionSpace(
host: "apple.com",
port: 80,
protocol: "http",
realm: nil,
authenticationMethod: "basic"
)
XCTAssert(space.description.hasPrefix("<\(type(of: space))"))
XCTAssert(space.description.hasSuffix(": Host:apple.com, Server:http, Auth-Scheme:NSURLAuthenticationMethodDefault, Realm:(null), Port:80, Proxy:NO, Proxy-Type:(null)"))

space = URLProtectionSpace(
host: "apple.com",
port: 80,
protocol: "http",
realm: nil,
authenticationMethod: "NSURLAuthenticationMethodHTMLForm"
)
XCTAssert(space.description.hasPrefix("<\(type(of: space))"))
XCTAssert(space.description.hasSuffix(": Host:apple.com, Server:http, Auth-Scheme:NSURLAuthenticationMethodHTMLForm, Realm:(null), Port:80, Proxy:NO, Proxy-Type:(null)"))
}
}
1 change: 1 addition & 0 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ XCTMain([
testCase(TestURL.allTests),
testCase(TestURLComponents.allTests),
testCase(TestURLCredential.allTests),
testCase(TestURLProtectionSpace.allTests),
testCase(TestURLProtocol.allTests),
testCase(TestNSURLRequest.allTests),
testCase(TestURLRequest.allTests),
Expand Down