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

Commit

Permalink
Configure and write basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamcma committed Aug 25, 2017
1 parent 7ad6b82 commit 91eb982
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import XCTest
@testable import VaporXFPMiddlewareTests

XCTMain([
testCase(VaporXFPMiddlewareTests.allTests)
])
41 changes: 41 additions & 0 deletions Tests/XFPMiddlewareTests/XFPMiddlewareTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import XCTest
import Vapor
import HTTP
import XFPMiddleware
import Testing

class XFPMiddlewareTests: XCTestCase {
static var allTests = [
("testXFPMiddleware", testXFPMiddleware)
]

override func setUp() {
Testing.onFail = XCTFail
}

func testXFPMiddleware() throws {
let drop = try Droplet()

let protected = drop.grouped(XFPMiddleware.init())

protected.get { req in
return Response(status: .ok)
}

let httpReq = Request(method: .get, uri: "/")
httpReq.uri.scheme = "http"
httpReq.headers["X-Forwarded-Proto"] = "http"

let httpsReq = Request(method: .get, uri: "/")
httpsReq.uri.scheme = "http"
httpsReq.headers["X-Forwarded-Proto"] = "https"

try drop.testResponse(to: httpReq)
.assertStatus(is: .seeOther)

try drop.testResponse(to: httpsReq)
.assertStatus(is: .ok)


}
}

0 comments on commit 91eb982

Please sign in to comment.