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

Function benchmarkBasicAuth

benchmarks/auth.js:71–130  ·  view source on GitHub ↗

* Benchmarks basic authentication performance

()

Source from the content-addressed store, hash-verified

69 * Benchmarks basic authentication performance
70 */
71function benchmarkBasicAuth () {
72 console.log("\n📊 Basic Authentication Benchmarks");
73 console.log("-".repeat(40));
74
75 const server = createAuthServer({ // eslint-disable-line no-unused-vars
76 basic: {
77 enabled: true,
78 list: ["user1:password1", "user2:password2", "admin:secret123"]
79 }
80 });
81
82 const suite = new Benchmark.Suite();
83
84 // Create test requests with different auth scenarios
85 const validAuthReq = createMockRequest({
86 headers: {
87 authorization: "Basic " + Buffer.from("user1:password1").toString("base64")
88 }
89 });
90
91 const invalidAuthReq = createMockRequest({
92 headers: {
93 authorization: "Basic " + Buffer.from("user1:wrongpassword").toString("base64")
94 }
95 });
96
97 const noAuthReq = createMockRequest();
98
99 // Mock the passport authentication function behavior
100 const basicAuthCheck = req => {
101 const auth = req.headers.authorization;
102 if (!auth || !auth.startsWith("Basic ")) return false;
103
104 const encoded = auth.slice(6);
105 const decoded = Buffer.from(encoded, "base64").toString();
106 const [username, password] = decoded.split(":");
107
108 const validUsers = { "user1": "password1", "user2": "password2", "admin": "secret123" };
109
110 return validUsers[username] === password;
111 };
112
113 suite
114 .add("Basic Auth - Valid credentials", () => {
115 basicAuthCheck(validAuthReq);
116 })
117 .add("Basic Auth - Invalid credentials", () => {
118 basicAuthCheck(invalidAuthReq);
119 })
120 .add("Basic Auth - No credentials", () => {
121 basicAuthCheck(noAuthReq);
122 })
123 .on("cycle", event => {
124 console.log(` ${String(event.target)}`);
125 })
126 .on("complete", function () {
127 console.log(` Fastest: ${this.filter("fastest").map("name")}`);
128 })

Callers 1

mainFunction · 0.85

Calls 4

createAuthServerFunction · 0.85
basicAuthCheckFunction · 0.85
logMethod · 0.80
createMockRequestFunction · 0.70

Tested by

no test coverage detected