test(napi): napi_fuzz PRG — edge probes (large payload, NUL, binary)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
36
capi/napi_fuzz.prg
Normal file
36
capi/napi_fuzz.prg
Normal file
@@ -0,0 +1,36 @@
|
||||
FUNCTION FN_HANDLE()
|
||||
LOCAL hReq := hb_jsonDecode( FN_NAPI_REQ() )
|
||||
LOCAL cPath := hb_HGetDef( hReq, "path", "" )
|
||||
LOCAL oF := FN_REQUIRE( "/Users/charleskwon/fivenode/fivenode/fivenode/napi/test/fuzzmod" )
|
||||
LOCAL xR := NIL
|
||||
LOCAL cErr := ""
|
||||
LOCAL oErr
|
||||
IF ! HB_ISOBJECT( oF )
|
||||
RETURN hb_jsonEncode( { "err" => FN_LASTERROR() } )
|
||||
ENDIF
|
||||
BEGIN SEQUENCE
|
||||
DO CASE
|
||||
CASE cPath == "/big1m"
|
||||
xR := oF:big( 1000000 )
|
||||
CASE cPath == "/big200k"
|
||||
xR := oF:big( 200000 )
|
||||
CASE cPath == "/echo1m"
|
||||
xR := oF:echo( Replicate( "y", 1000000 ) )
|
||||
CASE cPath == "/unicode"
|
||||
xR := oF:unicode()
|
||||
CASE cPath == "/binary"
|
||||
xR := oF:binary()
|
||||
OTHERWISE
|
||||
xR := "noop"
|
||||
ENDCASE
|
||||
RECOVER USING oErr
|
||||
cErr := IIF( HB_ISOBJECT( oErr ), oErr:Description, hb_CStr( oErr ) )
|
||||
END SEQUENCE
|
||||
RETURN hb_jsonEncode( { ;
|
||||
"status" => 200, ;
|
||||
"headers" => { "Content-Type" => "application/json" }, ;
|
||||
"body" => hb_jsonEncode( { ;
|
||||
"type" => ValType( xR ), ;
|
||||
"len" => IIF( xR == NIL, -1, Len( hb_CStr( xR ) ) ), ;
|
||||
"head" => Left( hb_CStr( xR ), 30 ), ;
|
||||
"err" => cErr } ) } )
|
||||
Reference in New Issue
Block a user