Skip to content

fix: Async key provider and errors should be resolved internally#335

Open
NikitaIT wants to merge 4 commits intofastify:mainfrom
NikitaIT:async-key-provider
Open

fix: Async key provider and errors should be resolved internally#335
NikitaIT wants to merge 4 commits intofastify:mainfrom
NikitaIT:async-key-provider

Conversation

@NikitaIT
Copy link
Copy Markdown
Contributor

@NikitaIT NikitaIT commented Apr 2, 2024

False positive tests: test: Async key provider errors should be resolved internally

Fix & test fix: feat: Async key provider

Related issue: #334

Checklist

Copy link
Copy Markdown
Contributor Author

@NikitaIT NikitaIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to work, I use it as a patch in my code. So far no problems have been noticed. All comments in the review are left for ease of review. They are not open issues on my part, or my todo. Close them as you become familiar. Thank you

Comment thread jwt.js
verifyResult.then(result => callback(null, result), error => wrapError(error, callback))
} else {
const verifyResult = verifier(token)
callback(null, verifyResult)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verifyResult moved in order to support promise based result.

Comment thread jwt.js
Comment thread jwt.js
Comment thread test/jwt-async.test.js
}
})
fastify.get('/', async function (request, reply) {
request.headers.jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.hQOxra1Zo9z61vCqe6_86kVfLqKI0WxDnkiJ_upW0sM'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded request.headers.jwt is for key=this secret reused from cache
Generated with https://jwt.io/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please generate this dynamically in code.

Comment thread test/jwt-async.test.js
@NikitaIT NikitaIT changed the title test: Async key provider and errors should be resolved internally fix: Async key provider and errors should be resolved internally Apr 3, 2024
Comment thread test/jwt-async.test.js
})
fastify.get('/', async function (request, reply) {
request.headers.jwt =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please generate this dynamically in code.

Comment thread test/jwt-async.test.js
}
})
fastify.get('/', async function (request, reply) {
request.headers.jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.hQOxra1Zo9z61vCqe6_86kVfLqKI0WxDnkiJ_upW0sM'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please generate this dynamically in code.

Comment thread test/jwt-async.test.js
Comment thread test/jwt-async.test.js
})
fastify.get('/', async function (request, reply) {
request.headers.jwt =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please generate this dynamically in code.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (2)

jwt.js:490

  • [nitpick] The variable 'verifyResult' is declared but not initialized. Consider initializing it.
let verifyResult

jwt.js:534

  • Ensure that all error cases handled by the 'wrapError' function are covered by tests.
function wrapError (error, callback) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"authenticate" example creates a new verifier instance and a new cache instance for each request

4 participants