Skip to content

Commit

Permalink
Merge pull request #8 from brokenhandsio/swift4
Browse files Browse the repository at this point in the history
Add Swift 4 support
  • Loading branch information
0xTim authored Sep 21, 2017
2 parents 0bc8db2 + 0e94a3a commit b720ac9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/*.xcodeproj
DerivedData/
Package.pins
Package.resolved
2 changes: 1 addition & 1 deletion .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 Down
17 changes: 17 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: "VaporSecurityHeaders",
products: [
.library(name: "VaporSecurityHeaders", targets: ["VaporSecurityHeaders"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.2.0")),
],
targets: [
.target(name: "VaporSecurityHeaders", dependencies: ["Vapor"]),
.testTarget(name: "VaporSecurityHeadersTests", dependencies: ["VaporSecurityHeaders"]),
]
)
6 changes: 3 additions & 3 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/VaporSecurityHeaders">
<img src="https://travis-ci.org/brokenhandsio/VaporSecurityHeaders.svg?branch=master" alt="Build Status">
Expand Down Expand Up @@ -72,7 +72,7 @@ You will need to add it as a dependency in your `Package.swift` file:
```swift
dependencies: [
...,
.Package(url: "https://github.com/brokenhandsio/VaporSecurityHeaders", majorVersion: 0)
.package(url: "https://github.com/brokenhandsio/VaporSecurityHeaders", from: "1.1.0")
]
```

Expand Down Expand Up @@ -111,7 +111,7 @@ If you are running Vapor on it's own (i.e. not as a CGI application or behind an

## Nginx, Apache and 3rd Party Services

Both web servers should pass on the response headers from Vapor without issue when running as a reverse proxy. Some servers and providers (such as Heroku) will inject their own headers or block certain headers (such as HSTS to stop you locking out their whole site). You will need to check with your provider to see what is enabled and allowed.
Both web servers should pass on the response headers from Vapor without issue when running as a reverse proxy. Some servers and providers (such as Heroku) will inject their own headers or block certain headers (such as HSTS to stop you locking out their whole site). You will need to check with your provider to see what is enabled and allowed.

# Security Header Information

Expand Down
27 changes: 25 additions & 2 deletions Tests/VaporSecurityHeadersTests/HeaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import HTTP
import VaporSecurityHeaders

class HeaderTests: XCTestCase {

// MARK: - All Tests

static var allTests = [
("testLinuxTestSuiteIncludesAllTests", testLinuxTestSuiteIncludesAllTests),
("testDefaultHeaders", testDefaultHeaders),
("testDefaultHeadersWithHSTS", testDefaultHeadersWithHSTS),
("testAllHeadersForApi", testAllHeadersForApi),
("testAPIHeadersWithHSTS", testAPIHeadersWithHSTS),
("testDefaultHeadersWithHSTS", testDefaultHeadersWithHSTS),
("testHeadersWithContentTypeOptionsTurnedOff", testHeadersWithContentTypeOptionsTurnedOff),
("testHeadersWithContentTypeOptionsNosniff", testHeadersWithContentTypeOptionsNosniff),
("testHeaderWithFrameOptionsDeny", testHeaderWithFrameOptionsDeny),
Expand Down Expand Up @@ -39,23 +42,41 @@ class HeaderTests: XCTestCase {
("testHeadersWithReferrerPolicyOriginWhenCrossOrigin", testHeadersWithReferrerPolicyOriginWhenCrossOrigin),
("testHeadersWithReferrerPolicyStrictOriginWhenCrossOrigin", testHeadersWithReferrerPolicyStrictOriginWhenCrossOrigin),
("testHeadersWithReferrerPolicyUnsafeUrl", testHeadersWithReferrerPolicyUnsafeUrl),
("testApiPolicyWithAddedReferrerPolicy", testApiPolicyWithAddedReferrerPolicy),
("testCustomCSPOnSingleRoute", testCustomCSPOnSingleRoute),
("testDifferentRequestReturnsDefaultCSPWhenSettingCustomCSPOnRoute", testDifferentRequestReturnsDefaultCSPWhenSettingCustomCSPOnRoute),
("testAbortMiddleware", testAbortMiddleware),
("testMockFileMiddleware", testMockFileMiddleware),
("testMockFileMiddlewareDifferentRequestReturnsDefaultCSPWhenSettingCustomCSPOnRoute", testMockFileMiddlewareDifferentRequestReturnsDefaultCSPWhenSettingCustomCSPOnRoute),
("testBuildWorks", testBuildWorks),
]

// MARK: - Properties

private var request: Request!
private var routeRequest: Request!
private var abortRequest: Request!

// MARK: - Overrides

override func setUp() {
request = Request(method: .get, uri: "/test/")
routeRequest = Request(method: .get, uri: "/route/")
abortRequest = Request(method: .get, uri: "/abort/")
}

// MARK: - Tests

func testLinuxTestSuiteIncludesAllTests() {
#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)
XCTAssertEqual(linuxCount, darwinCount,
"\(darwinCount - linuxCount) tests are missing from allTests")
#endif
}

func testDefaultHeaders() throws {
let expectedXCTOHeaderValue = "nosniff"
Expand Down Expand Up @@ -366,7 +387,7 @@ class HeaderTests: XCTestCase {
XCTAssertEqual(expected, response.headers[HeaderKey.referrerPolicy])
}

func testApiPolicyWithAddedReffererPolicy() throws {
func testApiPolicyWithAddedReferrerPolicy() throws {
let expected = "strict-origin"
let referrerConfig = ReferrerPolicyConfiguration(.strictOrigin)
let factory = SecurityHeadersFactory.api().with(referrerPolicy: referrerConfig)
Expand Down Expand Up @@ -489,6 +510,8 @@ class HeaderTests: XCTestCase {
XCTAssertEqual(expectedXFOHeaderValue, response.headers[HeaderKey.xFrameOptions])
XCTAssertEqual(expectedXSSProtectionHeaderValue, response.headers[HeaderKey.xXssProtection])
}

// MARK: - Private functions

private func makeTestDroplet(securityHeadersToAdd: SecurityHeadersFactory, routeHandler: ((Request) throws -> ResponseRepresentable)? = nil) throws -> Droplet {
var config = try Config()
Expand Down

0 comments on commit b720ac9

Please sign in to comment.