#Testing a path that is protected by session?
1 messages · Page 1 of 1 (latest)
You need to add a cookie to the request you're sending with the name vapor-session (unless you've changed it) and set the value to the session ID
hi, thanks, I just ended, calling to the login, and extracting the set-cookie I made a helper, and wala, there is my session with cookie, etc.
I should be able to change the test to request, right?
What do you mean change the test to request?
this ```
func loginWithUser(app: Application, user: String, password: String) async throws -> String {
let res = try app.sendRequest(.POST, "/login") { req in
try req.content.encode(["username": "[email protected]", "password": "admin"])
}
XCTAssertEqual(res.headers.contains(name: "set-cookie"), true)
let cookiesList: [String] = res.headers["set-cookie"]
let cookie : String = cookiesList[0]
XCTAssertContains(cookie, "vapor-session=")
return cookie
}