rohanpadhye/JQF

Question: Is it possible to skip the iteration of an argument in a function?

freedom1b2830 opened this issue · 3 comments

I need to fuzz only the first argument without touching the second

the method has 2+ arguments.
1 input and 2 output

public @Override handle (HttpRequest arg1, (NEED: NO FUZZ)HttpResponce arg2){

path= arg1.getPath();
file=new File(path);

if(!file.exists()){
     throw ...
}

arg2.setCode(200);
arg2.body.bytes=Files.readAllBytes(file)
arg2.flush();

}

Umm, just make the second argument a constant? If you don't want it to be auto-generated then I assume you have a specific value that you want. Just make it a field of the fuzz test class. Make the field static if you want the same object for the whole fuzzing session (only do this if it is not stateful), or keep it non-static if you want to reset it for every new test execution.

@RunWith(JQF.class)
class HttpTest {

  private HttpResponce resp = /* value, e.g. new Response() */

  @Fuzz public void fuzzHandle(HttpRequest req) {
     // use req to set resp
  }
}

here is an example of the class i want to fuzz
https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServlet.html
doGet
doPost
doPut
doDelete

I need to fuzz only the first argument.

I have some access (I can create a query in the generator) to the first argument

but I don't need to touch the second argument, it is created by the servlet itself***

i cant use:

@RunWith(JQF.class)
class HttpTest {

  private HttpResponce resp = /* value, e.g. new Response() */

  HttpServlet servlet=new HttpServlet();//my custom impl
  
public @before initServer(){
    server =new server();
    server.addpath("/index",servlet) //pseudo
  
  }


  @Fuzz public void fuzzHandle(HttpRequest req) {
     servlet.doGet(req,resp)//i cant invoke it
  }
}

If it is created by the Servlet itself then servlet.doGet() is not the correct entry point---it is likely not even a public method. You need to figure out how to programmatically send the servlet an HttpRequest without manually calling doGet().

This is not a JQF specific problem, but rather a question about how to make HttpRequest testable. If you have a fixed HttpRequest object, how do you test the server programmatically? This is something you would do for regular manual system testing. If you figure that out, then you will have the right entry point for JQF fuzzing. Maybe look for test files in the source repository for servlets.