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
de738b7311
commit
8d83cba2cd
4 changed files with 25 additions and 12 deletions
|
@ -24,9 +24,6 @@ public class Certificate {
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private CertificateType type;
|
private CertificateType type;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String commonName;
|
|
||||||
|
|
||||||
private String trustingAuthority;
|
private String trustingAuthority;
|
||||||
|
|
||||||
@Min(1)
|
@Min(1)
|
||||||
|
@ -35,6 +32,9 @@ public class Certificate {
|
||||||
@Min(1)
|
@Min(1)
|
||||||
private int requestedValidityDays;
|
private int requestedValidityDays;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String subjectCommonName;
|
||||||
|
|
||||||
private String subjectEmailAddress;
|
private String subjectEmailAddress;
|
||||||
private String subjectOrganization;
|
private String subjectOrganization;
|
||||||
private String subjectOrganizationalUnit;
|
private String subjectOrganizationalUnit;
|
||||||
|
@ -45,15 +45,15 @@ public class Certificate {
|
||||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private List<CertificateExtension> certificateExtension = new ArrayList<>();
|
private List<CertificateExtension> certificateExtension = new ArrayList<>();
|
||||||
|
|
||||||
@Lob
|
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private byte[] cert = new byte[0];
|
private byte[] cert = new byte[0];
|
||||||
|
|
||||||
@Lob
|
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private byte[] privateKey = new byte[0];
|
private byte[] privateKey = new byte[0];
|
||||||
|
|
||||||
@Lob
|
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
|
||||||
@Column
|
@Column
|
||||||
private byte[] fullchain;
|
private byte[] fullchain;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class CertificateCreationService {
|
||||||
private Certificate createEntityFromRequest(CertificateRequest certificateRequest) {
|
private Certificate createEntityFromRequest(CertificateRequest certificateRequest) {
|
||||||
final Certificate certificate = new Certificate();
|
final Certificate certificate = new Certificate();
|
||||||
certificate.setType(mapCertificateRequestType(certificateRequest.getType()));
|
certificate.setType(mapCertificateRequestType(certificateRequest.getType()));
|
||||||
certificate.setCommonName(certificateRequest.getSubject().getCommonName());
|
certificate.setSubjectCommonName(certificateRequest.getSubject().getCommonName());
|
||||||
certificate.setTrustingAuthority(certificateRequest.getTrustingAuthority());
|
certificate.setTrustingAuthority(certificateRequest.getTrustingAuthority());
|
||||||
certificate.setRequestedKeyLength(certificateRequest.getRequestedKeyLength());
|
certificate.setRequestedKeyLength(certificateRequest.getRequestedKeyLength());
|
||||||
certificate.setRequestedValidityDays(certificateRequest.getRequestedValidityDays());
|
certificate.setRequestedValidityDays(certificateRequest.getRequestedValidityDays());
|
||||||
|
|
|
@ -9,7 +9,10 @@ spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect
|
||||||
#TODO: Use flyway for db setup
|
#TODO: Use flyway for db setup
|
||||||
hibernate.hbm2ddl.auto=update
|
hibernate.hbm2ddl.auto=update
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=true
|
||||||
|
hibernate.format_sql=true
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
logging.level.root=INFO
|
logging.level.root=INFO
|
||||||
logging.level.de.mlessmann.certassist=DEBUG
|
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 de.mlessmann.certassist.models.CertificateType;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
@ -20,9 +22,15 @@ class CertificateRepositoryTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CertificateExtensionRepository extensionRepository;
|
private CertificateExtensionRepository extensionRepository;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void cleanUp() {
|
||||||
|
extensionRepository.deleteAll();
|
||||||
|
repository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
private Certificate getCertificate() {
|
private Certificate getCertificate() {
|
||||||
final Certificate certificate = new Certificate();
|
final Certificate certificate = new Certificate();
|
||||||
certificate.setCommonName("test-cn");
|
certificate.setSubjectCommonName("test-cn");
|
||||||
certificate.setType(CertificateType.SIGNED_CERT);
|
certificate.setType(CertificateType.SIGNED_CERT);
|
||||||
certificate.setRequestedKeyLength(1);
|
certificate.setRequestedKeyLength(1);
|
||||||
certificate.setRequestedValidityDays(1);
|
certificate.setRequestedValidityDays(1);
|
||||||
|
@ -37,7 +45,7 @@ class CertificateRepositoryTest {
|
||||||
repository.save(certificate);
|
repository.save(certificate);
|
||||||
|
|
||||||
Certificate foundCertificate = repository.findById(certificate.getId()).orElseThrow();
|
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);
|
assertThat(foundCertificate.getType()).isEqualTo(CertificateType.SIGNED_CERT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +59,10 @@ class CertificateRepositoryTest {
|
||||||
repository.save(certificate);
|
repository.save(certificate);
|
||||||
|
|
||||||
assertThat(repository.findById(certificate.getId()).orElseThrow().getCertificateExtension()).hasSize(1);
|
assertThat(repository.findById(certificate.getId()).orElseThrow().getCertificateExtension()).hasSize(1);
|
||||||
assertThat(extensionRepository.findAll())
|
List<CertificateExtension> extensions = StreamSupport
|
||||||
.singleElement()
|
.stream(extensionRepository.findAll().spliterator(), false)
|
||||||
.satisfies(ce -> assertThat(ce.getValue()).isEqualTo("test-ext-value"));
|
.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