Skip to content

Instantly share code, notes, and snippets.

@WaleedAshraf
Last active March 18, 2018 19:07
Show Gist options
  • Save WaleedAshraf/ebd0bfa752b7496faed134b01a338382 to your computer and use it in GitHub Desktop.
Save WaleedAshraf/ebd0bfa752b7496faed134b01a338382 to your computer and use it in GitHub Desktop.
Mock Express Session
// name = "my-session" -> base64 value of required object (cookie)
// name.sig = "my-session.sig" -> signed value of cookie using Keygrip
let cookie = Buffer.from(JSON.stringify({"count":2})).toString('base64'); // base64 converted value of cookie
let kg = Keygrip(['testKey']) // same key as I'm using in my app
let hash = kg.sign('my-session=' + cookie);
await request(app).get('api/image/submit').set("Accept", "text/html")
.set('cookie', ['my-session=' + cookie + '; ' + 'my-session.sig=' + hash + ';'])
.expect(200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment