Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from nodes-vapor/feature/remove-ssl-functionality
Browse files Browse the repository at this point in the history
Feature/remove ssl functionality
  • Loading branch information
steffendsommer committed Oct 24, 2017
2 parents d3f8221 + e43bde9 commit f05a055
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 103 deletions.
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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).
Expand Down
28 changes: 0 additions & 28 deletions Sources/SSLEnforcer.swift

This file was deleted.

47 changes: 1 addition & 46 deletions Tests/GatekeeperTests/GatekeeperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class GatekeeperTests: XCTestCase {
("testRateLimiter", testRateLimiter),
("testRateLimiterNoPeer", testRateLimiterNoPeer),
("testRateLimiterCountRefresh", testRateLimiterCountRefresh),
("testSSLEnforcerBasic", testSSLEnforcerBasic),
("testSSLEnforcerDenied", testSSLEnforcerDenied),
("testSSLEnforcerDoNotEnforce", testSSLEnforcerDoNotEnforce),
("testRefreshIntervalValues", testRefreshIntervalValues),
]

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit f05a055

Please sign in to comment.