Skip to content

Commit

Permalink
Merge pull request #5 from brokenhandsio/swift4
Browse files Browse the repository at this point in the history
Swift 4 support
  • Loading branch information
0xTim authored Sep 25, 2017
2 parents 3220b78 + e8dcc40 commit 4a6cf6d
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions Package@swift-4.swift
Original file line number Diff line number Diff line change
@@ -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"]),
]
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br>
<br>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/Swift-3.1-brightgreen.svg" alt="Language">
<img src="http://img.shields.io/badge/Swift-4-brightgreen.svg" alt="Language">
</a>
<a href="https://travis-ci.org/brokenhandsio/vapor-oauth">
<img src="https://travis-ci.org/brokenhandsio/vapor-oauth.svg?branch=master" alt="Build Status">
Expand Down Expand Up @@ -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"))
]
```

Expand Down
4 changes: 4 additions & 0 deletions Sources/VaporOAuth/Helper/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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...])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4a6cf6d

Please sign in to comment.