| 209 | |
| 210 | // Mock JWT validation (simplified - in real scenario would use jsonwebtoken library) |
| 211 | const jwtAuthCheck = req => { |
| 212 | const auth = req.headers.authorization; |
| 213 | if (!auth || !auth.startsWith("Bearer ")) return false; |
| 214 | |
| 215 | const token = auth.slice(7); |
| 216 | // Simplified JWT structure check |
| 217 | const parts = token.split("."); |
| 218 | if (parts.length !== 3) return false; |
| 219 | |
| 220 | // Mock validation - in real scenario would verify signature |
| 221 | try { |
| 222 | const payload = JSON.parse(Buffer.from(parts[1], "base64").toString()); |
| 223 | |
| 224 | return payload.sub && payload.iat; |
| 225 | } catch { |
| 226 | return false; |
| 227 | } |
| 228 | }; |
| 229 | |
| 230 | suite |
| 231 | .add("JWT Auth - Valid token", () => { |