Skip to content

Commit

Permalink
this commit fixes #147 (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobi9 authored Nov 6, 2023
1 parent 9ea1ffa commit 3eadd2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ declare namespace fastifyCsrfProtection {

interface FastifyCsrfProtectionOptionsFastifyCookie {
sessionPlugin?: '@fastify/cookie';
csrfOpts: Omit<CSRFOptions, 'hmacKey'> & Required<Pick<CSRFOptions, 'hmacKey'>>;
csrfOpts?: | ({
[k in keyof CSRFOptions]: k extends "userInfo"
? true
: CSRFOptions[k];
} & Required<Pick<CSRFOptions, "hmacKey">>)
| ({
[k in keyof CSRFOptions]: k extends "userInfo"
? false
: CSRFOptions[k];
});
}

interface FastifyCsrfProtectionOptionsFastifySession {
Expand Down
8 changes: 5 additions & 3 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ expectError(fastify.register(FastifyCsrfProtection, { getUserInfo: 'invalid' }))

fastify.register(FastifyCsrfProtection, { csrfOpts: { hmacKey: 'hmac' }, sessionPlugin: '@fastify/cookie' })
fastify.register(FastifyCsrfProtection, { csrfOpts: { hmacKey: 'hmac' } })
expectError(fastify.register(FastifyCsrfProtection, { }))
expectError(fastify.register(FastifyCsrfProtection, { csrfOpts: { }}))
expectError(fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { }}))
fastify.register(FastifyCsrfProtection, { })
fastify.register(FastifyCsrfProtection, { csrfOpts: { }})
expectError(fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true}}))
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true, hmacKey: 'key'}})
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie'})
fastify.register(FastifyCsrfProtection, { csrfOpts: { }, sessionPlugin: '@fastify/session' })
fastify.register(FastifyCsrfProtection, { csrfOpts: { }, sessionPlugin: '@fastify/secure-session' })
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/session' })
Expand Down

0 comments on commit 3eadd2e

Please sign in to comment.