MCPcopy Create free account
hub / github.com/avoidwork/tenso / benchmarkSessionAuth

Function benchmarkSessionAuth

benchmarks/auth.js:375–422  ·  view source on GitHub ↗

* Benchmarks session-based authentication

()

Source from the content-addressed store, hash-verified

373 * Benchmarks session-based authentication
374 */
375function benchmarkSessionAuth () {
376 console.log("\n📊 Session-based Authentication");
377 console.log("-".repeat(40));
378
379 const suite = new Benchmark.Suite();
380
381 // Mock session store
382 const sessionStore = new Map();
383 sessionStore.set("valid-session", { userId: 123, role: "user", authenticated: true });
384 sessionStore.set("admin-session", { userId: 1, role: "admin", authenticated: true });
385
386 const sessionAuthCheck = sessionId => {
387 const session = sessionStore.get(sessionId);
388
389 return session && session.authenticated === true;
390 };
391
392 const sessionRoleCheck = (sessionId, requiredRole) => {
393 const session = sessionStore.get(sessionId);
394
395 return session && session.authenticated && session.role === requiredRole;
396 };
397
398 suite
399 .add("Session Auth - Valid session check", () => {
400 sessionAuthCheck("valid-session");
401 })
402 .add("Session Auth - Invalid session check", () => {
403 sessionAuthCheck("invalid-session");
404 })
405 .add("Session Auth - Role validation", () => {
406 sessionRoleCheck("admin-session", "admin");
407 })
408 .add("Session Auth - Failed role validation", () => {
409 sessionRoleCheck("valid-session", "admin");
410 })
411 .add("Session Auth - Multiple session checks", () => {
412 const sessions = ["valid-session", "admin-session", "invalid-session"];
413 sessions.forEach(id => sessionAuthCheck(id));
414 })
415 .on("cycle", event => {
416 console.log(` ${String(event.target)}`);
417 })
418 .on("complete", function () {
419 console.log(` Fastest: ${this.filter("fastest").map("name")}`);
420 })
421 .run();
422}
423
424/**
425 * Memory usage test for authentication

Callers 1

mainFunction · 0.85

Calls 3

sessionAuthCheckFunction · 0.85
sessionRoleCheckFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected