WebFuzzing / EvoMaster

The first open-source AI-driven tool for automatically generating system-level test cases (also known as fuzzing) for web/enterprise applications. Currently targeting whitebox and blackbox testing of Web APIs, like REST, GraphQL and RPC (e.g., gRPC and Thrift).
GNU Lesser General Public License v3.0
516 stars 85 forks source link

Getting Table error for simple project #279

Closed vaibhavpudke0007 closed 3 years ago

vaibhavpudke0007 commented 3 years ago

how to solve this out

arcuri82 commented 3 years ago

that error message will need to be improved...

anyway, do you actually have a database with tables in your application?

vaibhavpudke0007 commented 3 years ago

im working with YAML file based springboot swagger project there is no Database ........is there some solution to this?

arcuri82 commented 3 years ago

in the driver, simply do not return anything for the DB, eg

public Connection getConnection() {
        return null;
    }
arcuri82 commented 3 years ago

furthermore, that error message is from DbCleaner. are u calling DbCleaner even if you are not using DB?

vaibhavpudke0007 commented 3 years ago

// // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) //

package org.example;

import com.p6spy.engine.spy.P6SpyDriver; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import org.evomaster.client.java.controller.EmbeddedSutController; import org.evomaster.client.java.controller.InstrumentedSutStarter; import org.evomaster.client.java.controller.api.dto.AuthenticationDto; import org.evomaster.client.java.controller.api.dto.SutInfoDto.OutputFormat; import org.evomaster.client.java.controller.db.DbCleaner; import org.evomaster.client.java.controller.internal.SutController; import org.evomaster.client.java.controller.problem.ProblemInfo; import org.evomaster.client.java.controller.problem.RestProblem; import org.songrong.swaggerdemo.SwaggerdemoApplication; import org.springframework.boot.SpringApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.jdbc.core.JdbcTemplate;

public class EMDriver extends EmbeddedSutController { private ConfigurableApplicationContext ctx; private Connection connection;

public EMDriver() {
}

public static void main(String[] args) {
    SutController controller = new EMDriver();
    InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);
    starter.start();
}

public boolean isSutRunning() {
    return this.ctx != null && this.ctx.isRunning();
}

public String getPackagePrefixesToCover() {
    return "org.example";
}

public List<AuthenticationDto> getInfoForAuthentication() {
    return null;
}

public Connection getConnection() {
    return null;
}

public String getDatabaseDriverName() {
    return "org.h2.Driver";
}

public ProblemInfo getProblemInfo() {
    return new RestProblem("http://localhost:8080/v2/api-docs", (List)null);
}

public OutputFormat getPreferredOutputFormat() {
    return OutputFormat.JAVA_JUNIT_5;
}

public String startSut() {
    this.ctx = SpringApplication.run(SwaggerdemoApplication.class, new String[]{"--spring.datasource.url=jdbc:p6spy:h2:mem:testdb;DB_CLOSE_DELAY=-1;", "--spring.datasource.driver-class-name=" + P6SpyDriver.class.getName()});
    JdbcTemplate jdbc = (JdbcTemplate)this.ctx.getBean(JdbcTemplate.class);

    try {
        this.connection = jdbc.getDataSource().getConnection();
    } catch (SQLException var3) {
        var3.printStackTrace();
    }

    return "http://localhost:8080";
}

public void stopSut() {
    this.ctx.stop();
}

public void resetStateOfSUT() {
    DbCleaner.clearDatabase_H2(this.connection);
}

}

this is my code with no database

arcuri82 commented 3 years ago

you are literally telling spring to use a H2 database with spring.datasource.url, and EM how to clean it in resetStateOfSUT. which fails, because you have no tables in the DB

vaibhavpudke0007 commented 3 years ago

this is new code it is able to generate test cases but not able to run those test cases all test cases are getting ignored

package org.example;

import com.p6spy.engine.spy.P6SpyDriver; import org.evomaster.client.java.controller.EmbeddedSutController; import org.evomaster.client.java.controller.InstrumentedSutStarter; import org.evomaster.client.java.controller.api.dto.AuthenticationDto; import org.evomaster.client.java.controller.api.dto.SutInfoDto; import org.evomaster.client.java.controller.db.DbCleaner; import org.evomaster.client.java.controller.internal.SutController; import org.evomaster.client.java.controller.problem.ProblemInfo; import org.evomaster.client.java.controller.problem.RestProblem; import org.songrong.swaggerdemo.SwaggerdemoApplication; import org.springframework.boot.SpringApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection; import java.sql.SQLException; import java.util.List;

public class EMDriver extends EmbeddedSutController {

public static void main(String[] args){

    SutController controller = new EMDriver();
    InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);

    starter.start();
}

private ConfigurableApplicationContext ctx;
private Connection connection;

public boolean isSutRunning() {
    return ctx!=null && ctx.isRunning();
}

public String getPackagePrefixesToCover() {
    return "org.example";
}

public List<AuthenticationDto> getInfoForAuthentication() {
    return null;
}

public Connection getConnection() {
    return null;
}

public String getDatabaseDriverName() {
    return "org.h2.Driver";
}

public ProblemInfo getProblemInfo() {
    return new RestProblem("http://localhost:8080/v2/api-docs", null);
}

public SutInfoDto.OutputFormat getPreferredOutputFormat() {
    return SutInfoDto.OutputFormat.JAVA_JUNIT_5;
}

public String startSut() {

    ctx = SpringApplication.run(SwaggerdemoApplication.class, new String[]{
            "--spring.datasource.driver-class-name=" + P6SpyDriver.class.getName()
    });

    return "http://localhost:8080";
}

public void stopSut() {
    ctx.stop();
}

public void resetStateOfSUT() {
}
vaibhavpudke0007 commented 3 years ago

Thank you soo much for your all help sir it means a lot

vaibhavpudke0007 commented 3 years ago

sir can you please check and tell me what is problem for error

vaibhavpudke0007 commented 3 years ago

still facing this error

2021-04-12 09:51:02.342 INFO 11656 --- [ Thread-11] o.s.j.d.e.EmbeddedDatabaseFactory : Shutting down embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false' 2021-04-12 09:51:02.361 INFO 11656 --- [ Thread-11] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' 2021-04-12 09:51:02.406 INFO 11656 --- [ Thread-11] o.e.jetty.server.AbstractConnector : Stopped ServerConnector@bfc14b9{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2021-04-12 09:51:02.407 INFO 11656 --- [ Thread-11] org.eclipse.jetty.server.session : node0 Stopped scavenging 2021-04-12 09:51:02.414 INFO 11656 --- [ Thread-11] o.e.j.s.h.ContextHandler.application : Destroying Spring FrameworkServlet 'dispatcherServlet' 2021-04-12 09:51:02.417 INFO 11656 --- [ Thread-11] o.e.jetty.server.handler.ContextHandler : Stopped o.s.b.w.e.j.JettyEmbeddedWebAppContext@2f1d0bbc{application,/,[file:///C:/Users/Hp/AppData/Local/Temp/jetty-docbase.1964457206371464344.8080/, jar:file:/C:/Users/Hp/.m2/repository/io/springfox/springfox-swagger-ui/2.9.2/springfox-swagger-ui-2.9.2.jar!/META-INF/resources],UNAVAILABLE}

arcuri82 commented 3 years ago

what error? those logs only show INFO messages.

regarding running JUnit tests, that all depends on your project settings

vaibhavpudke0007 commented 3 years ago

how to get run test cases working this is message I'm getting when I'm trying to run it java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/GsonObjectMapperFactory

at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at io.restassured.RestAssured.<clinit>(RestAssured.java:421)
at EvoMasterTest.initClass(EvoMasterTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:532)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeBeforeAllMethods$8(ClassTestDescriptor.java:373)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeBeforeAllMethods(ClassTestDescriptor.java:372)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:201)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:74)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:105)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

Caused by: java.lang.ClassNotFoundException: io.restassured.path.json.mapper.factory.GsonObjectMapperFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 36 more

arcuri82 commented 3 years ago

have you read the documentation? that problem with Spring is discussed there, with link to SO to solve it...

dkarthi1973 commented 3 years ago

you are literally telling spring to use a H2 database with spring.datasource.url, and EM how to clean it in resetStateOfSUT. which fails, because you have no tables in the DB

We don't know the table structure to create table on DB. could you please share the table structure. will create and try to connect accordingly

arcuri82 commented 3 years ago

what??? sorry, but I do not understand what you are saying... if you do not have a DB, simply do not configure EM to use a DB, nor start the application with a DB that you are not going to use

vaibhavpudke0007 commented 3 years ago

sir can you send the right EMDriver code for this one without DB and its connection

package org.example;

import com.p6spy.engine.spy.P6SpyDriver; import org.evomaster.client.java.controller.EmbeddedSutController; import org.evomaster.client.java.controller.InstrumentedSutStarter; import org.evomaster.client.java.controller.api.dto.AuthenticationDto; import org.evomaster.client.java.controller.api.dto.SutInfoDto; import org.evomaster.client.java.controller.db.DbCleaner; import org.evomaster.client.java.controller.internal.SutController; import org.evomaster.client.java.controller.problem.ProblemInfo; import org.evomaster.client.java.controller.problem.RestProblem; import org.songrong.swaggerdemo.SwaggerdemoApplication; import org.springframework.boot.SpringApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection; import java.sql.SQLException; import java.util.List;

public class EMDriver extends EmbeddedSutController {

public static void main(String[] args){

SutController controller = new EMDriver();
InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);

starter.start();

}

private ConfigurableApplicationContext ctx; private Connection connection;

public boolean isSutRunning() { return ctx!=null && ctx.isRunning(); }

public String getPackagePrefixesToCover() { return "org.example"; }

public List getInfoForAuthentication() { return null; }

public Connection getConnection() { return null; }

public String getDatabaseDriverName() { return "org.h2.Driver"; }

public ProblemInfo getProblemInfo() { return new RestProblem("http://localhost:8080/v2/api-docs", null); }

public SutInfoDto.OutputFormat getPreferredOutputFormat() { return SutInfoDto.OutputFormat.JAVA_JUNIT_5; }

public String startSut() {

ctx = SpringApplication.run(SwaggerdemoApplication.class, new String[]{
        "--spring.datasource.driver-class-name=" + P6SpyDriver.class.getName()
});

return "http://localhost:8080";

}

public void stopSut() { ctx.stop(); }

public void resetStateOfSUT() { }