@@ -131,3 +131,45 @@ Error
131131
132132 t . same ( cleaned , expected ) ;
133133} ) ;
134+
135+ t . test (
136+ "it does not remove the complete stack trace if the library root is wrong" ,
137+ async ( ) => {
138+ const stack = `
139+ Error
140+ at Collection.wrap (/Users/hansott/Code/node-RASP/build/agent/applyHooks.js:149:33)
141+ at Posts.all (/Users/hansott/Code/node-RASP/sample-apps/express-mongodb/posts.js:30:36)
142+ at /Users/hansott/Code/node-RASP/sample-apps/express-mongodb/app.js:49:41
143+ at asyncUtilWrap (/Users/hansott/Code/node-RASP/node_modules/express-async-handler/index.js:3:20)
144+ at /Users/hansott/Code/node-RASP/build/sources/express/wrapRequestHandler.js:22:20
145+ at runWithContext (/Users/hansott/Code/node-RASP/build/agent/Context.js:34:16)
146+ at /Users/hansott/Code/node-RASP/build/sources/express/wrapRequestHandler.js:12:45
147+ at Layer.handle [as handle_request] (/Users/hansott/Code/node-RASP/node_modules/express/lib/router/layer.js:95:5)
148+ at next (/Users/hansott/Code/node-RASP/node_modules/express/lib/router/route.js:149:13)
149+ at Route.dispatch (/Users/hansott/Code/node-RASP/node_modules/express/lib/router/route.js:119:3)
150+ ` . trim ( ) ;
151+
152+ const cleaned = cleanupStackTrace ( stack , "/Users/hansott/Code/node-RASP/" ) ;
153+
154+ const expected = `
155+ Error
156+ at Collection.wrap (/Users/hansott/Code/node-RASP/build/agent/applyHooks.js:149:33)
157+ at Posts.all (/Users/hansott/Code/node-RASP/sample-apps/express-mongodb/posts.js:30:36)
158+ at /Users/hansott/Code/node-RASP/sample-apps/express-mongodb/app.js:49:41
159+ at asyncUtilWrap (/Users/hansott/Code/node-RASP/node_modules/express-async-handler/index.js:3:20)
160+ at /Users/hansott/Code/node-RASP/build/sources/express/wrapRequestHandler.js:22:20
161+ at runWithContext (/Users/hansott/Code/node-RASP/build/agent/Context.js:34:16)
162+ at /Users/hansott/Code/node-RASP/build/sources/express/wrapRequestHandler.js:12:45
163+ at Layer.handle [as handle_request] (/Users/hansott/Code/node-RASP/node_modules/express/lib/router/layer.js:95:5)
164+ at next (/Users/hansott/Code/node-RASP/node_modules/express/lib/router/route.js:149:13)
165+ at Route.dispatch (/Users/hansott/Code/node-RASP/node_modules/express/lib/router/route.js:119:3)
166+ ` . trim ( ) ;
167+
168+ t . same ( cleaned , expected ) ;
169+ }
170+ ) ;
171+
172+ t . test ( "it catches exceptions" , async ( t ) => {
173+ // @ts -expect-error Test with invalid input
174+ t . same ( cleanupStackTrace ( "test" , undefined ) , "test" ) ;
175+ } ) ;
0 commit comments