Conversation
5938ff8 to
a8d16a4
Compare
a8d16a4 to
a6d8d36
Compare
|
So, this PR breaks my // I expect [[f1 AND f2 AND Fn] OR [F3 AND F4 AND Fn]], { relation: 'or' }
fastify.auth(
[
[fastify.checkAuth('admins'), ...someOtherAdminChecks],
[fastify.checkAuth('clients'), ...someOtherClientChecks],
],
{ relation: 'or' }
)It runs both paths even first path is passing. I'll try to find the issue in the changes. |
| method: 'POST', | ||
| url: '/check-two-sub-arrays-or', | ||
| payload: { | ||
| n: 11 |
There was a problem hiding this comment.
I updated 11 to 110 and now verifyBigAsync is passing BUT verifyOddAsync still called and doesn't wait until verifyBigAsync finished
There was a problem hiding this comment.
@mcollina my thoughts on this — due to broken default behavior it should be 5.0.0, not 4.5.0
There was a problem hiding this comment.
@isnifer Could you provide a test case for this?
I've just tried the following case locally:
- a route:
fastify.route({
method: 'POST',
url: '/check-two-sub-arrays-or-2',
preHandler: fastify.auth([[fastify.verifyBigAsync], [fastify.verifyOddAsync]], { relation: 'or' }),
handler: (req, reply) => {
reply.send({
big: req.big,
odd: req.odd ?? 'hello',
})
}
})- a test:
test('Two sub-arrays Or Relation success', t => {
t.plan(2)
fastify.inject({
method: 'POST',
url: '/check-two-sub-arrays-or-2',
payload: {
n: 110
}
}, (err, res) => {
t.error(err)
const payload = JSON.parse(res.payload)
t.same(payload, {
big: true,
odd: 'hello',
})
})
})And the test is passing meaning the fastify.verifyOddAsync was not called.
There was a problem hiding this comment.
@yakovenkodenis yes, sure, I forked this repo https://github.com/isnifer/fastify-auth.
- I hide all routes except this one — https://github.com/isnifer/fastify-auth/blob/master/test/example-composited.js#L148-L159
- Added important
console.log()s here — https://github.com/isnifer/fastify-auth/blob/master/test/example-composited.js#L52-L73 - And hide all tests except this one — https://github.com/isnifer/fastify-auth/blob/master/test/example-composited.test.js#L473-L490
And my test logs are:
npm t
> @fastify/auth@4.5.0 test
> npm run test:unit && npm run test:typescript
> @fastify/auth@4.5.0 test:unit
> tap
PASS ./test/auth.test.js 29 OK 38.833ms
PASS ./test/example-async.test.js 18 OK 48.952ms
./test/example-composited.test.js 1> If you see it — IT IS OK
./test/example-composited.test.js 1> THIS IS A SECOND AUTH PATH SHOULD NOT BE CALLED
PASS ./test/example-composited.test.js 2 OK 17.618ms
PASS ./test/example.test.js 20 OK 50.974msThere was a problem hiding this comment.
@yakovenkodenis also important note — I've changed line https://github.com/isnifer/fastify-auth/blob/master/test/example-composited.test.js#L481 to make verifyBigAsync pass since it's a first auth path
There was a problem hiding this comment.
Could @isnifer open a dedicated issue with your findings?
It is hard to discuss a bug in a merged PR
This PR addresses Issue #216: Extending composite authentication to allow nesting auth arrays with both
andandorrelations.If the
relation(defaultRelation) parameter isand, then the relation inside sub-arrays will beor.If the
relation(defaultRelation) parameter isor, then the relation inside sub-arrays will beand.fastify.auth([f1, f2, [f3, f4]], { relation: 'or' })f1 OR f2 OR (f3 AND f4)fastify.auth([f1, f2, [f3, f4]], { relation: 'and' })f1 AND f2 AND (f3 OR f4)Checklist
npm run testandnpm run benchmarkand the Code of conduct