File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 11import crypto from "node:crypto" ;
22import { describe , expect , it , vi } from "vitest" ;
3- import { createLineWebhookMiddleware } from "./webhook.js" ;
3+ import { createLineWebhookMiddleware , startLineWebhook } from "./webhook.js" ;
44
55const sign = ( body : string , secret : string ) =>
66 crypto . createHmac ( "SHA256" , secret ) . update ( body ) . digest ( "base64" ) ;
@@ -18,6 +18,15 @@ const createRes = () => {
1818} ;
1919
2020describe ( "createLineWebhookMiddleware" , ( ) => {
21+ it ( "rejects startup when channel secret is missing" , ( ) => {
22+ expect ( ( ) =>
23+ startLineWebhook ( {
24+ channelSecret : " " ,
25+ onEvents : async ( ) => { } ,
26+ } ) ,
27+ ) . toThrow ( / r e q u i r e s a n o n - e m p t y c h a n n e l s e c r e t / i) ;
28+ } ) ;
29+
2130 it ( "parses JSON from raw string body" , async ( ) => {
2231 const onEvents = vi . fn ( async ( ) => { } ) ;
2332 const secret = "secret" ;
Original file line number Diff line number Diff line change @@ -101,9 +101,17 @@ export function startLineWebhook(options: StartLineWebhookOptions): {
101101 path : string ;
102102 handler : ( req : Request , res : Response , _next : NextFunction ) => Promise < void > ;
103103} {
104+ const channelSecret =
105+ typeof options . channelSecret === "string" ? options . channelSecret . trim ( ) : "" ;
106+ if ( ! channelSecret ) {
107+ throw new Error (
108+ "LINE webhook mode requires a non-empty channel secret. " +
109+ "Set channels.line.channelSecret in your config." ,
110+ ) ;
111+ }
104112 const path = options . path ?? "/line/webhook" ;
105113 const middleware = createLineWebhookMiddleware ( {
106- channelSecret : options . channelSecret ,
114+ channelSecret,
107115 onEvents : options . onEvents ,
108116 runtime : options . runtime ,
109117 } ) ;
You can’t perform that action at this time.
0 commit comments