question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test `@tinyhttp/session`

See original GitHub issue

tests are almost identical to Express session module, so there are references to source of their tests.

  • SessionManager(opts)
    • more coming soon…
  • getSession(req, res)
    • session.save(cb)
      • Should save session to store (src)
      • Should prevent end-of-request save (src)
      • Should prevent end-of-request save on reloaded session
    • session.touch(cb) (src)
    • session.cookie (src)
    • session.originalMaxAge (src)
    • and the rest of session properties 😄
  • Cookie
    • new Cookie(opts)
      • expires is falsy be default
      • httpOnly is true by default

this list is in progress, so pls ping once finished writing those tests

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
talentlessguycommented, Oct 24, 2020

@alcar alright, will check for ur tests then but won’t close this issue

1reaction
alcarcommented, Oct 17, 2020

Hmm, I see! Okay, I’ll give that a try.

Just for reference, here is what I currently have:

it('should prevent end-of-request save', async () => {
  const store = new MemoryStore()

  const getSession = SessionManager({
    store,
    secret: 'test',
  })

  const { fetch } = InitAppAndTest(async (req, res) => {
    const session = await getSession(req, res)

    session.save((err) => {
      if (err) {
        return res.end(err.message)
      }

      res.end('saved')
    })
  })

  await fetch('/').expectStatus(200).expectBody('saved')

  shouldSetSessionInStore(store)
})

function shouldSetSessionInStore(store: MemoryStore) {
  const _set = store.set

  let count = 0

  store.set = function set() {
    count++

    return _set.apply(this, arguments)
  }

  assert.ok(count === 1, 'should set session in store')
}

I was also wondering why they do two consecutive requests and set a cookie in their tests 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

tiny-http/tiny-http: Low level HTTP server library in Rust - GitHub
Tiny -http handles everything that is related to client connections and data transfers and encoding. Everything else (parsing the values of the headers, ......
Read more >
7.9 Testing Session Tracking Using HttpSession - eTutorials.org
Every unique client of a web application is assigned a javax.servlet.http.HttpSession object on the server. The session object provides a little space on...
Read more >
HTTP Session Management - Manning
HTTP sessions are a necessity for all but the most trivial web ... A browser stores and manages small amounts of text known...
Read more >
How to calculate the size of the Http Session? - Mastertheboss
A simple way to count the active HTTP Sessions is to check the ... For large HTTP Session objects, however, you can neglect...
Read more >
Testing for Session Management Schema - OWASP Foundation
One of the core components of any web-based application is the mechanism by which it controls and maintains the state for a user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found