adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
187 stars 65 forks source link

The error root cause is not revealed on basic auth when db error is thrown #212

Closed Yopadd closed 1 year ago

Yopadd commented 1 year ago

I started to implement basic auth in my app. I followed all steps:

the error returned is Invalid basic auth credentials with code http 401. But the root cause is Error: connect ECONNREFUSED 127.0.0.1:5432

To reproduce :

test('protected route', async ({ client, expect }) => {
  const response = await client
    .post(`/protected`)
    .basicAuth("fake@mail.com", 'pass')
    .json({})

  expect(response.status()).toBe(200)
})

Route.post('/protected', async ({ auth }) => {
  await auth.use('basic').authenticate()

  return `You are logged in as ${auth.user!.name}`
})

The cause seems the try/catch here :

https://github.com/adonisjs/auth/blob/49228c5b619ba76362ad8ccb2afc9e2f65e83104/src/Guards/BasicAuth/index.ts#L117

I didn't push a PR because I don't know how you want handle this error type.

Yopadd commented 1 year ago

But maybe it's voluntary to not revealed the root cause for security reason :thinking:

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.