chore: Fix JDBC driver issues caused by blob incompatibility
chore: Remove lob annotation from certificate entity chore: Rename commonName colum to reflect it being in the subject information chore: Add more verbose logging chore: Update test to yield actually usefull assertion errors fix: Delete all items in the repository before running test - This fixes an issue where non-deterministic test order would cause the #singleElement assertion to fail sometimes
This commit is contained in:
parent
3c583bad76
commit
be8b165d46
4 changed files with 25 additions and 12 deletions
|
@ -24,9 +24,6 @@ public class Certificate {
|
|||
@Enumerated(EnumType.STRING)
|
||||
private CertificateType type;
|
||||
|
||||
@NotNull
|
||||
private String commonName;
|
||||
|
||||
private String trustingAuthority;
|
||||
|
||||
@Min(1)
|
||||
|
@ -35,6 +32,9 @@ public class Certificate {
|
|||
@Min(1)
|
||||
private int requestedValidityDays;
|
||||
|
||||
@NotNull
|
||||
private String subjectCommonName;
|
||||
|
||||
private String subjectEmailAddress;
|
||||
private String subjectOrganization;
|
||||
private String subjectOrganizationalUnit;
|
||||
|
@ -45,15 +45,15 @@ public class Certificate {
|
|||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<CertificateExtension> certificateExtension = new ArrayList<>();
|
||||
|
||||
@Lob
|
||||
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
|
||||
@Column(nullable = false)
|
||||
private byte[] cert = new byte[0];
|
||||
|
||||
@Lob
|
||||
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
|
||||
@Column(nullable = false)
|
||||
private byte[] privateKey = new byte[0];
|
||||
|
||||
@Lob
|
||||
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
|
||||
@Column
|
||||
private byte[] fullchain;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CertificateCreationService {
|
|||
private Certificate createEntityFromRequest(CertificateRequest certificateRequest) {
|
||||
final Certificate certificate = new Certificate();
|
||||
certificate.setType(mapCertificateRequestType(certificateRequest.getType()));
|
||||
certificate.setCommonName(certificateRequest.getSubject().getCommonName());
|
||||
certificate.setSubjectCommonName(certificateRequest.getSubject().getCommonName());
|
||||
certificate.setTrustingAuthority(certificateRequest.getTrustingAuthority());
|
||||
certificate.setRequestedKeyLength(certificateRequest.getRequestedKeyLength());
|
||||
certificate.setRequestedValidityDays(certificateRequest.getRequestedValidityDays());
|
||||
|
|
|
@ -9,7 +9,10 @@ spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect
|
|||
#TODO: Use flyway for db setup
|
||||
hibernate.hbm2ddl.auto=update
|
||||
hibernate.show_sql=true
|
||||
hibernate.format_sql=true
|
||||
|
||||
# Logging
|
||||
logging.level.root=INFO
|
||||
logging.level.de.mlessmann.certassist=DEBUG
|
||||
logging.level.org.sqlite=TRACE
|
||||
logging.level.org.hibernate=DEBUG
|
|
@ -7,6 +7,8 @@ import de.mlessmann.certassist.models.CertificateExtension;
|
|||
import de.mlessmann.certassist.models.CertificateType;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
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;
|
||||
|
@ -20,9 +22,15 @@ class CertificateRepositoryTest {
|
|||
@Autowired
|
||||
private CertificateExtensionRepository extensionRepository;
|
||||
|
||||
@BeforeEach
|
||||
void cleanUp() {
|
||||
extensionRepository.deleteAll();
|
||||
repository.deleteAll();
|
||||
}
|
||||
|
||||
private Certificate getCertificate() {
|
||||
final Certificate certificate = new Certificate();
|
||||
certificate.setCommonName("test-cn");
|
||||
certificate.setSubjectCommonName("test-cn");
|
||||
certificate.setType(CertificateType.SIGNED_CERT);
|
||||
certificate.setRequestedKeyLength(1);
|
||||
certificate.setRequestedValidityDays(1);
|
||||
|
@ -37,7 +45,7 @@ class CertificateRepositoryTest {
|
|||
repository.save(certificate);
|
||||
|
||||
Certificate foundCertificate = repository.findById(certificate.getId()).orElseThrow();
|
||||
assertThat(foundCertificate.getCommonName()).isEqualTo("test-cn");
|
||||
assertThat(foundCertificate.getSubjectCommonName()).isEqualTo("test-cn");
|
||||
assertThat(foundCertificate.getType()).isEqualTo(CertificateType.SIGNED_CERT);
|
||||
}
|
||||
|
||||
|
@ -51,8 +59,10 @@ class CertificateRepositoryTest {
|
|||
repository.save(certificate);
|
||||
|
||||
assertThat(repository.findById(certificate.getId()).orElseThrow().getCertificateExtension()).hasSize(1);
|
||||
assertThat(extensionRepository.findAll())
|
||||
.singleElement()
|
||||
.satisfies(ce -> assertThat(ce.getValue()).isEqualTo("test-ext-value"));
|
||||
List<CertificateExtension> extensions = StreamSupport
|
||||
.stream(extensionRepository.findAll().spliterator(), false)
|
||||
.toList();
|
||||
assertThat(extensions).hasSize(1);
|
||||
assertThat(extensions).singleElement().satisfies(ce -> assertThat(ce.getValue()).isEqualTo("test-ext-value"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue