diff --git a/README.md b/README.md index e55535c..43040f1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/nodes-vapor/gatekeeper)](http://clayallsopp.github.io/readme-score?url=https://github.com/nodes-vapor/gatekeeper) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nodes-vapor/gatekeeper/master/LICENSE) -Rate Limiter and SSL enforcing middleware. +Rate Limiter middleware. ## 📦 Installation @@ -21,33 +21,6 @@ Update your `Package.swift` file. ## Getting started 🚀 -Both the rate limiter and SSL-enforcing middleware are easy to configure and get running. - - -## SSLEnforcer 🔒 - -`SSLEnforcer` has three configurable fields: the error to be thrown, your `Droplet` and the environments you wish to enforce on. The environments defaults to `[.production]`. -```swift -let drop = Droplet() -// this will only enforce if running in `production` mode. -let enforcer = SSLEnforcer(error: Abort.notFound, drop: drop) -``` - -If you wish to secure your endpoints during development you can do the following: -```swift -let enforcer = SSLEnforcer( - error: Abort.notFound, - drop: drop, - environments: [ - .production, - .development - ] -) -``` - - -## RateLimiter ⏱ - `RateLimiter` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache. ```swift @@ -64,7 +37,6 @@ case .hour case .day ``` - ## Credits 🏆 This package is developed and maintained by the Vapor team at [Nodes](https://www.nodes.dk). diff --git a/Sources/SSLEnforcer.swift b/Sources/SSLEnforcer.swift deleted file mode 100644 index fa6a1ae..0000000 --- a/Sources/SSLEnforcer.swift +++ /dev/null @@ -1,28 +0,0 @@ -import HTTP -import Vapor - -public struct SSLEnforcer: Middleware { - private var shouldEnforce: Bool - private let error: AbortError - - public init(error: AbortError, drop: Droplet, environments: [Environment] = [.production]) { - shouldEnforce = environments.contains(drop.config.environment) - self.error = error - } - - public func respond(to request: Request, chainingTo next: Responder) throws -> Response { - if shouldEnforce { - // ** WARNING ** - // it's possible for a user to make a request using the scheme `https` - // but over plaintext. If this is a concern, serve application - // behind a proxy server, such as nginx, and have the proxy enforce - // an SSL conntection. - guard request.uri.scheme == "https" else { - throw error - } - } - - let response = try next.respond(to: request) - return response - } -} diff --git a/Tests/GatekeeperTests/GatekeeperTests.swift b/Tests/GatekeeperTests/GatekeeperTests.swift index 72462b8..0ee63b8 100644 --- a/Tests/GatekeeperTests/GatekeeperTests.swift +++ b/Tests/GatekeeperTests/GatekeeperTests.swift @@ -12,9 +12,6 @@ class GatekeeperTests: XCTestCase { ("testRateLimiter", testRateLimiter), ("testRateLimiterNoPeer", testRateLimiterNoPeer), ("testRateLimiterCountRefresh", testRateLimiterCountRefresh), - ("testSSLEnforcerBasic", testSSLEnforcerBasic), - ("testSSLEnforcerDenied", testSSLEnforcerDenied), - ("testSSLEnforcerDoNotEnforce", testSSLEnforcerDoNotEnforce), ("testRefreshIntervalValues", testRefreshIntervalValues), ] @@ -86,49 +83,7 @@ class GatekeeperTests: XCTestCase { requestsLeft = try! middleware.cache.get("192.168.1.2")?["requestsLeft"]?.int XCTAssertEqual(requestsLeft, 99, "Requests left should've reset") } - - func testSSLEnforcerBasic() { - let middleware = SSLEnforcer(error: Abort.badRequest, drop: productionDrop) - let request = getHTTPSRequest() - - do { - _ = try middleware.respond(to: request, chainingTo: MockResponder()) - } catch { - XCTFail("Request failed: \(error)") - } - } - - func testSSLEnforcerDenied() { - let middleware = SSLEnforcer(error: Abort.badRequest, drop: productionDrop) - let request = getHTTPRequest() - - do { - _ = try middleware.respond(to: request, chainingTo: MockResponder()) - XCTFail("Should've been rejected") - } catch let error as Abort { - switch error.status { - case .badRequest: - // success - break - default: - XCTFail("Expected bad request") - } - } catch { - XCTFail("Request failed: \(error)") - } - } - - func testSSLEnforcerDoNotEnforce() { - let middleware = SSLEnforcer(error: Abort.badRequest, drop: developmentDrop) - let request = getHTTPSRequest() - - do { - _ = try middleware.respond(to: request, chainingTo: MockResponder()) - } catch { - XCTFail("SSL should not have been enforced for development.") - } - } - + func testRefreshIntervalValues() { let expected: [(Rate.Interval, Double)] = [ (.second, 1),