From 3b1a49f6ab8ebfe4c3a57dff0a6d82b27e7d0991 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Thu, 25 Aug 2016 18:45:16 -0700 Subject: [PATCH] updated TurnstileWeb to 8-24 --- Package.swift | 4 - Sources/TurnstileWeb/OAuth2.swift | 6 +- Sources/TurnstileWeb/TLSClientStream.swift | 70 ----------------- Tests/LinuxMain.swift | 3 +- Tests/TurnstileWebTests/FacebookTests.swift | 16 +--- .../TLSClientStreamTests.swift | 78 ------------------- 6 files changed, 6 insertions(+), 171 deletions(-) delete mode 100644 Sources/TurnstileWeb/TLSClientStream.swift delete mode 100644 Tests/TurnstileWebTests/TLSClientStreamTests.swift diff --git a/Package.swift b/Package.swift index 060fa57..47d7b6c 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,3 @@ var package = Package( .Package(url: "https://github.com/vapor/json.git", majorVersion: 0, minor: 5) ] ) - -#if os(Linux) -package.dependencies.append(Package.Dependency.Package(url: "https://github.com/czechboy0/SecretSocks.git", majorVersion: 0, minor: 6)) -#endif diff --git a/Sources/TurnstileWeb/OAuth2.swift b/Sources/TurnstileWeb/OAuth2.swift index 436269c..3703d63 100644 --- a/Sources/TurnstileWeb/OAuth2.swift +++ b/Sources/TurnstileWeb/OAuth2.swift @@ -33,11 +33,7 @@ public class OAuth2 { /// The Token Endpoint of the OAuth 2 Server public let tokenURL: String - #if os(Linux) - let HTTPClient = Client.self - #else - let HTTPClient = Client.self - #endif + let HTTPClient = BasicClient.self /// Creates the OAuth 2 client diff --git a/Sources/TurnstileWeb/TLSClientStream.swift b/Sources/TurnstileWeb/TLSClientStream.swift deleted file mode 100644 index 0b3098d..0000000 --- a/Sources/TurnstileWeb/TLSClientStream.swift +++ /dev/null @@ -1,70 +0,0 @@ -/** - Brought in from https://github.com/vapor/tls-provider 0.4 - Attribution and Copyright below: - - The MIT License (MIT) - - Copyright (c) 2016 Tanner Nelson - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -#if os(Linux) -import TLS -import SecretSocks -import Transport - -/** - Establish a secure SSL/TLS connection to a remote server -*/ -class TLSClientStream: TCPProgramStream, ClientStream { - public func connect() throws -> Stream { - try stream.connect() - switch securityLayer { - case .none: - return stream - case .tls: - let secure = try stream.makeSecret(mode: .client) - try secure.connect() - return secure - } - } -} - -/* - Incomplete conformance of SSL.Socket. Will be updating with more thorough support - */ -extension TLS.Socket: Stream { - // Timeout not supported - public func setTimeout(_ timeout: Double) throws {} - - public var closed: Bool { - return false - } - - public func close() throws { - // - } - - - public func flush() throws { - // no flush, send immediately flushes - } -} -#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index afa4adf..a0b7fc2 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -10,6 +10,5 @@ XCTMain([ testCase(URandomTests.allTests), testCase(BCryptTests.allTests), testCase(FacebookTests.allTests), - testCase(OAuth2Tests.allTests), - testCase(TLSClientStreamTests.allTests) + testCase(OAuth2Tests.allTests) ]) diff --git a/Tests/TurnstileWebTests/FacebookTests.swift b/Tests/TurnstileWebTests/FacebookTests.swift index 6b16d1e..092280b 100644 --- a/Tests/TurnstileWebTests/FacebookTests.swift +++ b/Tests/TurnstileWebTests/FacebookTests.swift @@ -14,23 +14,15 @@ import JSON import Turnstile import Foundation import Transport +import URI class FacebookTests: XCTestCase { var facebook: Facebook! - #if os(Linux) - let HTTPClient = Client.self - #else - let HTTPClient = Client.self - #endif + let HTTPClient = BasicClient.self override func setUp() { - #if os(OSX) || os(iOS) - let clientID = ProcessInfo.processInfo.environment["FACEBOOK_CLIENT_ID"] ?? "" - let clientSecret = ProcessInfo.processInfo.environment["FACEBOOK_CLIENT_SECRET"] ?? "" - #elseif os(Linux) - let clientID = ProcessInfo.processInfo().environment["FACEBOOK_CLIENT_ID"] ?? "" - let clientSecret = ProcessInfo.processInfo().environment["FACEBOOK_CLIENT_SECRET"] ?? "" - #endif + let clientID = ProcessInfo.processInfo.environment["FACEBOOK_CLIENT_ID"] ?? "" + let clientSecret = ProcessInfo.processInfo.environment["FACEBOOK_CLIENT_SECRET"] ?? "" facebook = Facebook(clientID: clientID, clientSecret: clientSecret) } diff --git a/Tests/TurnstileWebTests/TLSClientStreamTests.swift b/Tests/TurnstileWebTests/TLSClientStreamTests.swift deleted file mode 100644 index f7104b0..0000000 --- a/Tests/TurnstileWebTests/TLSClientStreamTests.swift +++ /dev/null @@ -1,78 +0,0 @@ -#if os(Linux) -/** - Brought in from https://github.com/vapor/tls-provider. - Attribution and Copyright below: - - The MIT License (MIT) - - Copyright (c) 2016 Tanner Nelson - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -import XCTest -@testable import TurnstileWeb - -class TLSClientStreamTests: XCTestCase { - static var allTests = [ - ("testSend", testSend) - ] - - func testSend() { - do { - let clientStream = try TLSClientStream.init(host: "api.spotify.com", port: 443, securityLayer: .tls).connect() - let uri = "/v1/search?type=artist&q=hannah%20diamond" - try clientStream.send("GET \(uri) HTTP/1.1\r\nHost: api.spotify.com\r\n\r\n".bytes) - let response = try clientStream.receive(max: 2048).string - - XCTAssert(response.contains("spotify:artist:3sXErEOw7EmO6Sj7EgjHdU")) - } catch { - XCTFail("Could not send: \(error)") - } - } -} - -extension Sequence where Iterator.Element == UInt8 { - /** - Converts a slice of bytes to - string. Courtesy of Socks by @Czechboy0 - */ - public var string: String { - var utf = UTF8() - var gen = makeIterator() - var str = String() - while true { - switch utf.decode(&gen) { - case .emptyInput: - return str - case .error: - break - case .scalarValue(let unicodeScalar): - str.append(unicodeScalar) - } - } - } -} - -extension String { - var bytes: [UInt8] { - return Array(utf8) - } -} -#endif