fastify / session

Session plugin for fastify
Other
101 stars 44 forks source link

Potential bug in unit test for idGenerator #266

Open U-4-E-A opened 1 week ago

U-4-E-A commented 1 week ago

Prerequisites

Issue

https://github.com/fastify/session/blob/master/test/idGenerator.test.js

Both tests appear to have the same error - they are not using Set.add() to add the newly generated ID to the set so ids.has(id) is checking for the id in an empty Set.

const ids = new Set()

for (let i = 0; i < (cacheSize); ++i) {
  const id = idGen()
  if (ids.has(id)) {
    t.fail('had a collision')
  }
  t.equal(id.length, 32)
}

I believe this should be: -

const ids = new Set()

for (let i = 0; i < (cacheSize); ++i) {
  const id = idGen()
  if (ids.has(id)) {
    t.fail('had a collision')
  }
  t.equal(id.length, 32)
  ids.add(id) <--------------------------------------------
}
climba03003 commented 1 week ago

Good catch