From 2cc2b5f6dff97a8d7fefa2a53cd94321cbabf394 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 25 Sep 2017 21:00:03 +0100 Subject: [PATCH 1/6] Update CI to point to Swift 4 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e7e7d5e..94f26d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: generic sudo: required dist: trusty -osx_image: xcode8.3 +osx_image: xcode9 before_install: - if [ $TRAVIS_OS_NAME == "osx" ]; then brew tap vapor/tap; @@ -23,7 +23,7 @@ script: - swift test after_success: - - eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/master/codecov)" + - eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/swift-4-codecov/codecov-swift4)" notifications: email: From b52678ef0a6d7ff02673ee936cdea08917dc3a36 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 25 Sep 2017 21:00:47 +0100 Subject: [PATCH 2/6] Update README for Swift 4 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d814ca..2fcafea 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- Language + Language Build Status @@ -40,7 +40,7 @@ Vapor OAuth can be added to your Vapor add with a simple provider. To get starte ```swift dependencies: [ ..., - .Package(url: "https://github.com/brokenhandsio/vapor-oauth", majorVersion: 0) + .package(url: "https://github.com/brokenhandsio/vapor-oauth", from: "0.6.0")) ] ``` From 37c0dcaf86a9f47ba2dacd2efa822ddf900934d0 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 25 Sep 2017 21:03:16 +0100 Subject: [PATCH 3/6] Add Swift 4 manifest --- Package@swift-4.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Package@swift-4.swift diff --git a/Package@swift-4.swift b/Package@swift-4.swift new file mode 100644 index 0000000..6b55ca5 --- /dev/null +++ b/Package@swift-4.swift @@ -0,0 +1,18 @@ +// swift-tools-version:4.0 + +import PackageDescription + +let package = Package( + name: "VaporOAuth", + products: [ + .library(name: "VaporOAuth", targets: ["VaporOAuth"]), + ], + dependencies: [ + .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.2.0")), + .package(url: "https://github.com/vapor/auth-provider.git", .upToNextMajor(from: "1.2.0")), + ], + targets: [ + .target(name: "VaporOAuth", dependencies: ["Vapor", "AuthProvider"]), + .testTarget(name: "VaporOAuthTests", dependencies: ["VaporOAuth"]), + ] +) From 12ae5b77e24e457d7cba7f21b22a1e7a962bcffe Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 25 Sep 2017 21:12:21 +0100 Subject: [PATCH 4/6] Fix the tests for Swift 4 --- .../AuthorizationTests/AuthorizationRequestTests.swift | 2 +- .../AuthorizationTests/AuthorizationResponseTests.swift | 2 +- .../DefaultImplementationTests/DefaultImplementationTests.swift | 2 +- .../GrantTests/AuthorizationCodeTokenTests.swift | 2 +- .../GrantTests/ClientCredentialsTokenTests.swift | 2 +- Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift | 2 +- Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift | 2 +- Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift | 2 +- .../IntegrationTests/AuthCodeResourceServerTests.swift | 2 +- .../TokenIntrospectionTests/TokenIntrospectionTests.swift | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift index 271ff59..87c5916 100644 --- a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift +++ b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift @@ -57,7 +57,7 @@ class AuthorizationRequestTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift index 3b4ee40..ee39a4f 100644 --- a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift +++ b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift @@ -72,7 +72,7 @@ class AuthorizationResponseTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift b/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift index 941554d..e10d20a 100644 --- a/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift +++ b/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift @@ -34,7 +34,7 @@ class DefaultImplementationTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift b/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift index 48632f7..88624ed 100644 --- a/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift @@ -66,7 +66,7 @@ class AuthorizationCodeTokenTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift b/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift index 5a94fef..ef0bcff 100644 --- a/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift @@ -61,7 +61,7 @@ class ClientCredentialsTokenTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift b/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift index 3b14881..a9faad4 100644 --- a/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift @@ -88,7 +88,7 @@ class ImplicitGrantTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift b/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift index 6ca15fc..a4ea1dd 100644 --- a/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift @@ -73,7 +73,7 @@ class PasswordGrantTokenTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift b/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift index 300d6e4..8e46103 100644 --- a/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift @@ -64,7 +64,7 @@ class TokenRefreshTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift b/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift index e4d19f3..d0e5f53 100644 --- a/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift +++ b/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift @@ -68,7 +68,7 @@ class AuthCodeResourceServerTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift b/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift index d92c175..75e5e55 100644 --- a/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift +++ b/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift @@ -57,7 +57,7 @@ class TokenIntrospectionTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } From 861b9285ffe8f7629a6ea87c1eaf165495e6f544 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 25 Sep 2017 21:13:22 +0100 Subject: [PATCH 5/6] Remove warning from tests --- .../IntegrationTests/AuthCodeResourceServerTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift b/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift index d0e5f53..66fa448 100644 --- a/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift +++ b/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift @@ -117,7 +117,7 @@ class AuthCodeResourceServerTests: XCTestCase { for queryPart in queryParts { if queryPart.hasPrefix("code=") { let codeStartIndex = queryPart.index(queryPart.startIndex, offsetBy: 5) - codePart = queryPart.substring(from: codeStartIndex) + codePart = String(queryPart[codeStartIndex...]) } } From e8dcc40db89490e3b25305e475568d09dbd5d64e Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 25 Sep 2017 21:15:52 +0100 Subject: [PATCH 6/6] Remove warning from Swift 4 --- Sources/VaporOAuth/Helper/Helper.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/VaporOAuth/Helper/Helper.swift b/Sources/VaporOAuth/Helper/Helper.swift index d216659..7ac47e9 100644 --- a/Sources/VaporOAuth/Helper/Helper.swift +++ b/Sources/VaporOAuth/Helper/Helper.swift @@ -60,7 +60,11 @@ extension Request { throw Abort(.forbidden) } + #if swift(>=4) + let token = String(authHeader[authHeader.index(authHeader.startIndex, offsetBy: 7)...]) + #else let token = authHeader.substring(from: authHeader.index(authHeader.startIndex, offsetBy: 7)) + #endif guard !token.isEmpty else { throw Abort(.forbidden)