(req, config, store)
| 162 | const rateStores = configs.map(() => new Map()); |
| 163 | |
| 164 | const checkRateLimitWithConfig = (req, config, store) => { |
| 165 | const reqId = req.sessionID || req.ip; |
| 166 | const currentTime = Math.floor(Date.now() / 1000); |
| 167 | |
| 168 | if (!store.has(reqId)) { |
| 169 | store.set(reqId, { |
| 170 | remaining: config.limit - 1, |
| 171 | reset: currentTime + config.reset |
| 172 | }); |
| 173 | |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | const state = store.get(reqId); |
| 178 | |
| 179 | if (currentTime >= state.reset) { |
| 180 | state.remaining = config.limit - 1; |
| 181 | state.reset = currentTime + config.reset; |
| 182 | |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | return state.remaining > 0 ? (state.remaining--, true) : false; |
| 187 | }; |
| 188 | |
| 189 | configs.forEach((config, index) => { |
| 190 | suite.add(`Rate Limit - ${config.name}`, () => { |
no outgoing calls
no test coverage detected