refactor: Refactor middleware, tests (#2005)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* refactor: test, basic auth, cache * refactor: deno dist files * refactor: formating * refactor: format deno basic-auth * refactor: revert package.json test changes
authored by Aris Kemper · committed by GitHub · parent a00fc56 · Browse files · 4 files·+34 added−46 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+34 added−46 removed
- other:+34 added−46 removed
Provenance
- Commit
ed0efa7- Tree
14017c2- Author
Aris Kemper <aris.github@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
a00fc56
4 files changed+34 added−46 removed
modified:deno_dist/middleware/basic-auth/index.ts+4 added-10 removed
41 unmodified lines4243444546474849505152535455464748495051525311 unmodified lines41 unmodified lines return async function basicAuth(ctx, next) { const requestUser = auth(ctx.req) if (requestUser) { for (const user of users) { const usernameEqual = await timingSafeEqual( user.username, requestUser.username, options.hashFunction ) const passwordEqual = await timingSafeEqual( user.password, requestUser.password, options.hashFunction ) const [usernameEqual, passwordEqual] = await Promise.all([ timingSafeEqual(user.username, requestUser.username, options.hashFunction), timingSafeEqual(user.password, requestUser.password, options.hashFunction), ]) if (usernameEqual && passwordEqual) { await next() return }11 unmodified linesmodified:deno_dist/middleware/cache/index.ts+13 added-13 removed
31 unmodified lines3233343536373839404142434445464748363738394041424344454647484950515231 unmodified lines return async function cache(c, next) { const key = c.req.url const cache = await caches.open(options.cacheName) const response = await cache.match(key) if (!response) { await next() if (!c.res.ok) { return } addHeader(c) const response = c.res.clone() if (options.wait) { await cache.put(key, response) } else { c.executionCtx.waitUntil(cache.put(key, response)) } } else { if (response) { return new Response(response.body, response) }
await next() if (!c.res.ok) { return } addHeader(c) const res = c.res.clone() if (options.wait) { await cache.put(key, res) } else { c.executionCtx.waitUntil(cache.put(key, res)) } }}modified:src/middleware/basic-auth/index.ts+4 added-10 removed
41 unmodified lines4243444546474849505152535455464748495051525311 unmodified lines41 unmodified lines return async function basicAuth(ctx, next) { const requestUser = auth(ctx.req) if (requestUser) { for (const user of users) { const usernameEqual = await timingSafeEqual( user.username, requestUser.username, options.hashFunction ) const passwordEqual = await timingSafeEqual( user.password, requestUser.password, options.hashFunction ) const [usernameEqual, passwordEqual] = await Promise.all([ timingSafeEqual(user.username, requestUser.username, options.hashFunction), timingSafeEqual(user.password, requestUser.password, options.hashFunction), ]) if (usernameEqual && passwordEqual) { await next() return }11 unmodified linesmodified:src/middleware/cache/index.ts+13 added-13 removed
31 unmodified lines32 return async function cache(c, next) {33 const key = c.req.url34 const cache = await caches.open(options.cacheName)35 const response = await cache.match(key)36- if (!response) {37- await next()38- if (!c.res.ok) {39- return40- }41- addHeader(c)42- const response = c.res.clone()43- if (options.wait) {44- await cache.put(key, response)45- } else {46- c.executionCtx.waitUntil(cache.put(key, response))47- }48- } else {36+ if (response) {37 return new Response(response.body, response)38 }39+40+ await next()41+ if (!c.res.ok) {42+ return43+ }44+ addHeader(c)45+ const res = c.res.clone()46+ if (options.wait) {47+ await cache.put(key, res)48+ } else {49+ c.executionCtx.waitUntil(cache.put(key, res))50+ }51 }52 }