feat: Implement working draft of importing existing certificates #15
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
|
||||
![]() Interessant. Ich werde mir das noch weiter anschauen. Die Bulk-Operation war halt in der Zeile, die in einer der Exceptions aufgetaucht ist. Aber dann war das wohl etwas unterliegendes. Interessant. Ich werde mir das noch weiter anschauen. Die Bulk-Operation war halt in der Zeile, die in einer der Exceptions aufgetaucht ist. Aber dann war das wohl etwas unterliegendes.
Jedenfalls zeigt sich einmal mehr, dass das Logging noch unzureichend ist. 😅
![]() Also das Hibernate-Problem scheint zu sein, dass er die BLOB-Felder über Also das Hibernate-Problem scheint zu sein, dass er die BLOB-Felder über ``ResultSet#getBlob`` lesen will.
Die Methode ist vom SQLite Driver aber nicht implementiert und wirft daher einen Fehler.
|
||||
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
Die Bulk-Operation ist kein Problem. Es scheint ein Problem beim Column-Mapping zu geben. Ich habe schon ein paar Sachen recherchiert und ausprobiert, aber bekomme es nicht gefixt. Interessanter Weise ist der Test in der IDE-Ausführung immer grün, auch mit dem Test-Profil. Es bricht nur der Gradle-Test ab, was ich auch lokal reproduzieren kann. Interessanter Weise kommt es gelegentlich zu einer erfolgreichen Test-Ausführung, sodass vermutlich irgendwo noch ein Reihenfolge oder Caching-Problem vorliegt.