diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index 1013831..5f39639 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -44,9 +44,7 @@ To use a specific distribution version number, use this endpoint: include::{snippets}/getCveForDistroByVersion/curl-request.adoc[] -The expected response looks like this: - -include::{snippets}/getCveForDistroByVersion/http-response.adoc[] +The expected response is the same as for the previous request. === Get a list of CVEs for packages by distro @@ -62,4 +60,12 @@ include::{snippets}/getCveForPackagesByDistroVersion/curl-request.adoc[] The expected response looks like this: -include::{snippets}/getCveForPackagesByDistroVersion/http-response.adoc[] \ No newline at end of file +include::{snippets}/getCveForPackagesByDistroVersion/http-response.adoc[] + +== Get List of Packages + +include::{snippets}/getPackages/curl-request.adoc[] + +The expected response looks like this: + +include::{snippets}/getPackages/http-response.adoc[] diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2066b40..f022922 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,4 +3,4 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/glvd spring.datasource.username=glvd spring.datasource.password=glvd spring.sql.init.mode=never -jakarta.persistence.query.timeout=5000 +jakarta.persistence.query.timeout=7000 diff --git a/src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java b/src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java index 532f851..061f2ec 100644 --- a/src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java +++ b/src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java @@ -42,7 +42,8 @@ class GlvdControllerTest { @Container @ServiceConnection - static PostgreSQLContainer postgres = new PostgreSQLContainer<>(glvdPostgresImage).withDatabaseName("glvd") + static PostgreSQLContainer postgres = new PostgreSQLContainer<>(glvdPostgresImage) + .withDatabaseName("glvd") .withUsername("glvd").withPassword("glvd"); @Autowired @@ -100,7 +101,7 @@ public void shouldReturnCvesForBookworm() { .filter(document("getCveForDistro", preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()), preprocessResponse(prettyPrint()))) - .when().port(this.port).get("/v1/cves/debian_linux/bookworm") + .when().port(this.port).get("/v1/cves/gardenlinux/1592") .then().statusCode(HttpStatus.SC_OK); } @@ -110,7 +111,7 @@ public void shouldReturnCvesForBookwormByVersion() { .filter(document("getCveForDistroByVersion", preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()), preprocessResponse(prettyPrint()))) - .when().port(this.port).get("/v1/cves/debian_linux/version/12") + .when().port(this.port).get("/v1/cves/gardenlinux/version/1592.0") .then().statusCode(HttpStatus.SC_OK); } @@ -120,7 +121,7 @@ public void shouldReturnCvesForListOfPackages() { .filter(document("getCveForPackages", preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()), preprocessResponse(prettyPrint()))) - .when().port(this.port).get("/v1/cves/debian_linux/bookworm/packages/dav1d,firefox-esr") + .when().port(this.port).get("/v1/cves/gardenlinux/1592/packages/crun,vim") .then().statusCode(HttpStatus.SC_OK); } @@ -130,7 +131,7 @@ public void shouldReturnCvesForListOfPackagesByDistroVersion() { .filter(document("getCveForPackagesByDistroVersion", preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()), preprocessResponse(prettyPrint()))) - .when().port(this.port).get("/v1/cves/debian_linux/version/12/packages/dav1d,firefox-esr") + .when().port(this.port).get("/v1/cves/gardenlinux/version/1592.0/packages/crun,vim") .then().statusCode(HttpStatus.SC_OK); } @@ -144,4 +145,14 @@ public void shouldBeReady() { .then().statusCode(HttpStatus.SC_OK).body("dbCheck", containsString("true")); } + @Test + public void shouldGetPackagesForDistro() { + given(this.spec).accept("application/json") + .filter(document("getPackages", + preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()), + preprocessResponse(prettyPrint()))) + .when().port(this.port).get("/v1/packages/1592.0") + .then().statusCode(200); + } + } \ No newline at end of file diff --git a/src/test/java/io/gardenlinux/glvd/PackageControllerTest.java b/src/test/java/io/gardenlinux/glvd/PackageControllerTest.java deleted file mode 100644 index adf1b9b..0000000 --- a/src/test/java/io/gardenlinux/glvd/PackageControllerTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.gardenlinux.glvd; - -import io.gardenlinux.glvd.db.CveRepository; -import io.restassured.RestAssured; -import io.restassured.builder.RequestSpecBuilder; -import io.restassured.http.ContentType; -import io.restassured.specification.RequestSpecification; -import org.apache.http.HttpStatus; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.boot.testcontainers.service.connection.ServiceConnection; -import org.springframework.restdocs.RestDocumentationContextProvider; -import org.springframework.restdocs.RestDocumentationExtension; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.DockerImageName; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.containsString; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.document; -import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@Testcontainers -@ExtendWith({RestDocumentationExtension.class, SpringExtension.class}) -class PackageControllerTest { - - static DockerImageName glvdPostgresImage = DockerImageName - .parse(TestConfig.DbContainerImage) - .asCompatibleSubstituteFor("postgres"); - - @Container - @ServiceConnection - static PostgreSQLContainer postgres = new PostgreSQLContainer<>(glvdPostgresImage).withDatabaseName("glvd") - .withUsername("glvd").withPassword("glvd"); - - @Autowired - CveRepository cveRepository; - - @LocalServerPort - private Integer port; - - private RequestSpecification spec; - - @BeforeAll - static void beforeAll() { - postgres.start(); - } - - @AfterAll - static void afterAll() { - postgres.stop(); - } - - @DynamicPropertySource - static void configureProperties(DynamicPropertyRegistry registry) { - registry.add("spring.datasource.url", postgres::getJdbcUrl); - registry.add("spring.datasource.username", postgres::getUsername); - registry.add("spring.datasource.password", postgres::getPassword); - } - - @BeforeEach - void setUp(RestDocumentationContextProvider restDocumentation) { - this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(restDocumentation)).build(); - - RestAssured.baseURI = "http://localhost:" + port; - } - - @Test - public void shouldGetPackagesForDistro() { - given(this.spec).accept("application/json") - .filter(document("getPackages", - preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()), - preprocessResponse(prettyPrint()))) - .when().port(this.port).get("/v1/packages/1592.0") - .then(); - } - - -} \ No newline at end of file