-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
215 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity(name = "all_cve") | ||
public class Cve { | ||
@Id | ||
@Column(name = "cve_id", nullable = false) | ||
private String id; | ||
|
||
@Column(name = "last_mod", nullable = false) | ||
@Nonnull | ||
private String lastModified; | ||
|
||
@Column(name = "data", nullable = false) | ||
@Nonnull | ||
private String data; | ||
|
||
public Cve() { | ||
} | ||
|
||
public Cve(String id, @Nonnull String lastModified, @Nonnull String data) { | ||
this.id = id; | ||
this.lastModified = lastModified; | ||
this.data = data; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Nonnull | ||
public String getLastModified() { | ||
return lastModified; | ||
} | ||
|
||
@Nonnull | ||
public String getData() { | ||
return data; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Cve cve = (Cve) o; | ||
return Objects.equals(id, cve.id) && lastModified.equals(cve.lastModified) && data.equals(cve.data); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hashCode(id); | ||
result = 31 * result + lastModified.hashCode(); | ||
result = 31 * result + data.hashCode(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CveRepository extends JpaRepository<Cve, String> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(value = "/v1/cves", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class GlvdController { | ||
|
||
@Nonnull | ||
private final GlvdService glvdService; | ||
|
||
public GlvdController(@Nonnull GlvdService glvdService) { | ||
this.glvdService = glvdService; | ||
} | ||
|
||
@GetMapping("/{cveId}") | ||
ResponseEntity<?> getCveId(@PathVariable("cveId") final String cveId) { | ||
var cve = glvdService.getCve(cveId); | ||
return ResponseEntity.ok().body(cve); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class GlvdService { | ||
|
||
@Nonnull | ||
private final CveRepository cveRepository; | ||
|
||
public GlvdService(@Nonnull CveRepository cveRepository) { | ||
this.cveRepository = cveRepository; | ||
} | ||
|
||
public Cve getCve(String cveId) { | ||
var cve = cveRepository.findById(cveId); | ||
return cve.orElseThrow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
spring.application.name=glvd | ||
spring.datasource.url=jdbc:postgresql://localhost:5432/glvd | ||
spring.datasource.username=glvd | ||
spring.datasource.password=glvd | ||
spring.sql.init.mode=always | ||
|
||
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE | ||
|
||
|
||
spring.jpa.properties.hibernate.show_sql=true | ||
spring.jpa.properties.hibernate.use_sql_comments=true | ||
spring.jpa.properties.hibernate.format_sql=true | ||
logging.level.org.hibernate.type=trace | ||
|
||
|
||
logging.level.org.hibernate.orm.jdbc.bind=trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
@SpringBootTest | ||
class GlvdApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
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.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class GlvdControllerTest { | ||
|
||
static DockerImageName glvdPostgresImage = DockerImageName.parse("ghcr.io/gardenlinux/glvd-postgres:edgesampledata") | ||
.asCompatibleSubstituteFor("postgres"); | ||
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>( | ||
glvdPostgresImage | ||
).withDatabaseName("glvd").withUsername("glvd").withPassword("glvd"); | ||
@Autowired | ||
CveRepository cveRepository; | ||
@LocalServerPort | ||
private Integer port; | ||
|
||
@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() { | ||
RestAssured.baseURI = "http://localhost:" + port; | ||
} | ||
|
||
@Test | ||
void shouldGetCveById() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.get("/v1/cves/CVE-2024-1549") | ||
.then() | ||
.statusCode(200) | ||
.body("id", containsString("CVE-2024-1549")); | ||
} | ||
|
||
@Test | ||
void tryGetNonExistingCveById() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.get("/v1/cves/CVE-1989-1234") | ||
.then() | ||
.statusCode(500); | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/test/java/io/gardenlinux/glvd/TestGlvdApplication.java
This file was deleted.
Oops, something went wrong.