This repository has been archived by the owner on Jan 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import XCTest | ||
@testable import VaporXFPMiddlewareTests | ||
|
||
XCTMain([ | ||
testCase(VaporXFPMiddlewareTests.allTests) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
} | ||
} |