Skip to content

Commit

Permalink
fix session duration and test cookie expire time
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Dec 13, 2024
1 parent a49b476 commit e298998
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/server/routes/auth/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ describe("/auth/login", function(){
});

it("sets a cookie", async function(){
const maxAge = this.server.locals.sessionMaxAge;
this.agent = request.agent(this.server);
await this.agent.post("/auth/login")
let res = await this.agent.post("/auth/login")
.send({username: user.username, password: "12345678"})
.set("Content-Type", "application/json")
.set("Accept", "")
.expect(200)
.expect('set-cookie', /session=/);

let expiresText = /expires=([^;]+);/.exec(res.headers["set-cookie"]);
expect(expiresText, `expected regex to match ${res.headers["set-cookie"]}`).to.be.ok;
let expiresDate = new Date((expiresText as any)[1]);
expect(expiresDate.valueOf()).to.be.above(Date.now()-1);
expect(expiresDate.valueOf()).to.be.below(Date.now()+ maxAge + 1);
});

it("can get login status (not connected)", async function(){
Expand Down

0 comments on commit e298998

Please sign in to comment.