Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Aug 19, 2024
1 parent 84a311f commit 6eed34d
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void testSignNonEformHappyScenario(ProtectedInMemoryDocument document) {

@ParameterizedTest
@MethodSource({ "digital.slovensko.autogram.TestMethodSources#nonEformXmlProvider"})
void testSignNonEformNegativeScenario(InMemoryDocument document) {
void testSignNonEformNegativeScenario(ProtectedInMemoryDocument document) {
Assertions.assertThrows(UnknownEformException.class, () -> SigningParameters.buildForASiCWithXAdES(document, false, false, null, false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import digital.slovensko.autogram.core.SigningParameters;
import digital.slovensko.autogram.core.eforms.dto.EFormAttributes;
import digital.slovensko.autogram.core.errors.*;
import digital.slovensko.autogram.model.ProtectedDSSDocument;
import digital.slovensko.autogram.model.ProtectedInMemoryDocument;
import eu.europa.esig.dss.enumerations.ASiCContainerType;
import eu.europa.esig.dss.enumerations.MimeTypeEnum;
import eu.europa.esig.dss.enumerations.SignatureLevel;
Expand Down Expand Up @@ -56,7 +58,7 @@ void setDefaultValues() throws IOException {

@Test
void testThrowsAutogramExceptionWhenNoMimeType() throws IOException {
var document = new InMemoryDocument(generalAgendaXml);
var document = new ProtectedInMemoryDocument(generalAgendaXml);

Assertions.assertThrows(SigningParametersException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, enveloping,
Expand All @@ -72,7 +74,7 @@ void testThrowsAutogramExceptionWhenNoDocument() {

@Test
void testThrowsXMLValidationFailedWhenNoXML() {
var document = new InMemoryDocument("not xml".getBytes(), "doc.xml", MimeTypeEnum.XML);
var document = new ProtectedInMemoryDocument("not xml".getBytes(), "doc.xml", MimeTypeEnum.XML);

Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, enveloping,
Expand All @@ -91,7 +93,7 @@ void testThrowsAutogramExceptionWhenNoSignatureLevel() {

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider")
void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(DSSDocument document) {
void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(ProtectedDSSDocument document) {
Assertions.assertDoesNotThrow(
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
false, null, null, null, null,
Expand All @@ -100,7 +102,7 @@ void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(DSSDocument docume

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider")
void testDoesNotThrowWithMinimalParametersForXadesInAsice(DSSDocument document) {
void testDoesNotThrowWithMinimalParametersForXadesInAsice(ProtectedDSSDocument document) {
Assertions.assertDoesNotThrow(
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null,
false, null, null, null, null,
Expand All @@ -109,7 +111,7 @@ void testDoesNotThrowWithMinimalParametersForXadesInAsice(DSSDocument document)

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider")
void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceWith(DSSDocument document) {
void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceWith(ProtectedDSSDocument document) {
Assertions.assertDoesNotThrow(
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null,
false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema,
Expand All @@ -118,7 +120,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider")
void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(DSSDocument document) {
void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(ProtectedDSSDocument document) {
// TODO: mock eform S3 resource
Assertions.assertDoesNotThrow(
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
Expand All @@ -128,7 +130,7 @@ void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(DSSDoc

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#invalidXmlProvider")
void testThrowsAutogramExceptionWithInvalidXml(DSSDocument document) {
void testThrowsAutogramExceptionWithInvalidXml(ProtectedDSSDocument document) {
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null,
false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema,
Expand All @@ -137,7 +139,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#invalidXmlProvider")
void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(DSSDocument document) {
void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(ProtectedDSSDocument document) {
// TODO: mock eform S3 resource
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
Expand All @@ -147,7 +149,7 @@ void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(DSSDocument docu

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#nonEFormXmlProvider")
void testThrowsUnknownEformExceptionWithInvalidXmlEform(DSSDocument document) {
void testThrowsUnknownEformExceptionWithInvalidXmlEform(ProtectedDSSDocument document) {
// TODO: mock eform S3 resource
Assertions.assertThrows(UnknownEformException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
Expand All @@ -158,7 +160,7 @@ void testThrowsUnknownEformExceptionWithInvalidXmlEform(DSSDocument document) {

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#xsdSchemaFailedValidationXmlProvider")
void testThrowsAutogramExceptionWithInvalidXmlSchema(DSSDocument document) {
void testThrowsAutogramExceptionWithInvalidXmlSchema(ProtectedDSSDocument document) {
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null,
false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema,
Expand All @@ -167,7 +169,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#xsdSchemaFailedValidationXmlProvider")
void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(DSSDocument document) {
void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(ProtectedDSSDocument document) {
// TODO: mock eform S3 resource
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
Expand All @@ -177,7 +179,7 @@ void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(DSSDocumen

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider")
void testThrowsAutogramExceptionWithUnknownEformXml(DSSDocument document) {
void testThrowsAutogramExceptionWithUnknownEformXml(ProtectedDSSDocument document) {
Assertions.assertThrows(EFormException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null,
false, null, null, null, new EFormAttributes(null, null, null,
Expand All @@ -187,7 +189,7 @@ false, null, null, null, new EFormAttributes(null, null, null,

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#unknownEfomXmlProvider")
void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(DSSDocument document) {
void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(ProtectedDSSDocument document) {
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
false, null, null, null, null, true,
Expand All @@ -196,7 +198,7 @@ void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(DSSDocument

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#mismatchedDigestsXmlProvider")
void testThrowsAutogramExceptionWithMismatchedDigestsXml(DSSDocument document) {
void testThrowsAutogramExceptionWithMismatchedDigestsXml(ProtectedDSSDocument document) {
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null,
false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema,
Expand All @@ -206,7 +208,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran
@ParameterizedTest
@MethodSource({ "digital.slovensko.autogram.TestMethodSources#mismatchedDigestsXmlProvider",
"digital.slovensko.autogram.TestMethodSources#mismatchedDigestsFSXmlProvider"})
void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(DSSDocument document) {
void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(ProtectedDSSDocument document) {
Assertions.assertThrows(XMLValidationException.class,
() -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null,
false, null, null, null, null, true,
Expand All @@ -215,14 +217,14 @@ void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(DSSDoc

@ParameterizedTest
@MethodSource("digital.slovensko.autogram.TestMethodSources#invalidAsiceProvider")
void testThrowsOriginalDocumentNotFoundWithAsiceWithoutSignature(DSSDocument document) throws IOException {
void testThrowsOriginalDocumentNotFoundWithAsiceWithoutSignature(ProtectedDSSDocument document) throws IOException {
Assertions.assertThrows(OriginalDocumentNotFoundException.class,
() -> SigningParameters.buildForASiCWithXAdES(document, false, false, tspSource, true));
}

@Test
void testThrowsExceptionWithAsiceWithEmptyXml() throws IOException {
var document = new InMemoryDocument(
var document = new ProtectedInMemoryDocument(
this.getClass().getResourceAsStream("empty_xml.asice").readAllBytes(),
"empty_xml.asice");

Expand All @@ -233,7 +235,7 @@ void testThrowsExceptionWithAsiceWithEmptyXml() throws IOException {
@Test
void testInvalidTransformation() throws IOException {
var generalAgendaXml = this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes();
var document = new InMemoryDocument(generalAgendaXml, "doc.xml", MimeTypeEnum.XML);
var document = new ProtectedInMemoryDocument(generalAgendaXml, "doc.xml", MimeTypeEnum.XML);

var transformation = "invalid transformation";
Assertions.assertThrows(TransformationParsingErrorException.class,
Expand Down
Loading

0 comments on commit 6eed34d

Please sign in to comment.