Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • fit-connect/sdk-java
1 result
Show changes
Commits on Source (9)
......@@ -10,7 +10,6 @@ import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;
import com.nimbusds.jose.jwk.KeyOperation;
import com.nimbusds.jose.jwk.RSAKey;
import com.nimbusds.jose.util.StandardCharset;
import dev.fitko.fitconnect.api.config.ApplicationConfig;
import dev.fitko.fitconnect.api.domain.model.destination.Destination;
import dev.fitko.fitconnect.api.domain.model.destination.DestinationService;
......@@ -254,10 +253,18 @@ public class DefaultValidationService implements ValidationService {
// https://docs.fitko.de/fit-connect/docs/receiving/verification/#syntax-validierung-1
if (data.getSubmissionSchema().getMimeType().equals(MimeType.APPLICATION_JSON)) {
final ValidationResult jsonValidation = validateJsonFormat(new String(decryptedData, StandardCharsets.UTF_8));
final String jsonData = new String(decryptedData, StandardCharsets.UTF_8);
final ValidationResult jsonValidation = validateJsonFormat(jsonData);
if (jsonValidation.hasError()) {
return ValidationResult.problem(new DataJsonSyntaxViolation());
}
final ValidationResult dataSchemaValidation = validateSubmissionDataSchema(jsonData, data.getSubmissionSchema().getSchemaUri());
if (dataSchemaValidation.hasError()) {
return ValidationResult.problem(new DataSchemaViolation());
}
}
if (data.getSubmissionSchema().getMimeType().equals(MimeType.APPLICATION_XML)) {
......@@ -267,12 +274,6 @@ public class DefaultValidationService implements ValidationService {
}
}
final ValidationResult dataSchemaValidation = validateSubmissionDataSchema(new String(decryptedData, StandardCharset.UTF_8),
metadata.getContentStructure().getData().getSubmissionSchema().getSchemaUri());
if (dataSchemaValidation.hasError()) {
return ValidationResult.problem(new DataSchemaViolation());
}
return ValidationResult.ok();
}
......
......@@ -845,7 +845,7 @@ class DefaultValidationServiceTest {
}
@Test
void testValidData() throws IOException {
void testValidJsonData() throws IOException {
// Given
final SchemaProvider schemaProvider = mock(SchemaProvider.class);
......@@ -890,6 +890,44 @@ class DefaultValidationServiceTest {
assertTrue(validationResult.isValid());
}
@Test
void testValidXmlData() throws IOException {
// Given
final var decryptedXmlData = "<xml>test</xml>".getBytes();
final var submission = new Submission();
submission.setEncryptedData("part1.part2.part3.part4.dataAuthTag");
final var submissionSchema = new SubmissionSchema();
submissionSchema.setSchemaUri(URI.create("urn:de:fim:leika:leistung:99400048079000"));
submissionSchema.setMimeType(MimeType.APPLICATION_XML);
final var hash = new Hash();
hash.setContent(hashService.toHexString(hashService.createHash(decryptedXmlData)));
hash.setSignatureType(SignatureType.SHA_512);
final var data = new Data();
data.setHash(hash);
data.setSubmissionSchema(submissionSchema);
final var contentStructure = new ContentStructure();
contentStructure.setData(data);
contentStructure.setAttachments(Collections.emptyList());
final var metadata = new Metadata();
metadata.setContentStructure(contentStructure);
final var authenticationTags = new AuthenticationTags();
authenticationTags.setData("dataAuthTag");
// When
final ValidationResult validationResult = underTest.validateData(decryptedXmlData, submission, metadata, authenticationTags);
// Then
assertTrue(validationResult.isValid());
}
@Test
void testIncorrectDataAuthenticationTag() {
......
......@@ -6,13 +6,16 @@ import dev.fitko.fitconnect.api.config.EnvironmentName;
import dev.fitko.fitconnect.api.config.SenderConfig;
import dev.fitko.fitconnect.api.config.SubscriberConfig;
import dev.fitko.fitconnect.api.domain.model.event.problems.Problem;
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup;
import dev.fitko.fitconnect.client.SubscriberClient;
import dev.fitko.fitconnect.client.bootstrap.ClientFactory;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import static dev.fitko.fitconnect.api.domain.model.event.problems.Problem.SCHEMA_URL;
......@@ -25,11 +28,16 @@ public class IntegrationTestBase {
public static void cleanupTestSubmissions() {
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID"));
final UUID jsonDataDestinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA"));
final UUID xmlDataDestinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID_XML_DATA"));
final Problem problem = new Problem(SCHEMA_URL + "technical-error", "cleanup", "submission-cleanup", "other");
final SubscriberClient subscriberClient = ClientFactory.getSubscriberClient(getConfigWithCredentialsFromEnvironment("TEST", true));
subscriberClient.getAvailableSubmissionsForDestination(destinationId).forEach((s -> {
final Set<SubmissionForPickup> jsonSubmissions = subscriberClient.getAvailableSubmissionsForDestination(jsonDataDestinationId);
final Set<SubmissionForPickup> xmlSubmissions = subscriberClient.getAvailableSubmissionsForDestination(xmlDataDestinationId);
Stream.concat(jsonSubmissions.stream(), xmlSubmissions.stream()).forEach((s -> {
try {
subscriberClient.rejectSubmission(s, List.of(problem));
} catch (final Exception e) {
......
......@@ -63,7 +63,7 @@ public class SenderClientIT extends IntegrationTestBase {
}
@Test
void testSendAndConfirmCycle() throws IOException {
void testSendAndConfirmCycleWithJsonData() throws IOException {
// Given
final ApplicationConfig config = getConfigWithCredentialsFromEnvironment("TESTING", true);
......@@ -71,7 +71,7 @@ public class SenderClientIT extends IntegrationTestBase {
final String submissionData = getResourceAsString("/submission_data.json");
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
......@@ -99,6 +99,43 @@ public class SenderClientIT extends IntegrationTestBase {
assertThat(new String(receivedSubmission.getAttachments().get(0).getDataAsBytes()), is("Test attachment"));
}
@Test
void testSendAndConfirmCycleWithXmlData() throws IOException {
// Given
final ApplicationConfig config = getConfigWithCredentialsFromEnvironment("TESTING", true);
final String submissionData = getResourceAsString("/submission_data.xml");
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_XML_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setXmlData(submissionData, URI.create("urn:de:fim:leika:leistung:99400048079000"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
.addAttachment(Attachment.fromByteArray("attachment data".getBytes(), "text/plain"))
.addAttachment(Attachment.fromString("attachment data", "text/plain"))
.setReplyChannel(ReplyChannel.fromDeMail("test@mail.org"))
.build();
final var sentSubmission = ClientFactory.getSenderClient(config).send(submission);
assertNotNull(sentSubmission);
// When
final ReceivedSubmission receivedSubmission =
ClientFactory.getSubscriberClient(config)
.requestSubmission(sentSubmission.getSubmissionId());
// Then
assertNotNull(receivedSubmission);
assertThat(receivedSubmission.getDataAsString(), is(submissionData));
assertThat(receivedSubmission.getDataSchemaUri(), is(URI.create("urn:de:fim:leika:leistung:99400048079000")));
assertThat(receivedSubmission.getDataMimeType(), is("application/xml"));
assertThat(receivedSubmission.getAttachments(), hasSize(3));
assertThat(receivedSubmission.getMetadata().getReplyChannel(), is(ReplyChannel.fromDeMail("test@mail.org")));
assertThat(new String(receivedSubmission.getAttachments().get(0).getDataAsBytes()), is("Test attachment"));
}
@Test
void testSubmissionDataValidationFromLocalSchemaFile(@TempDir final Path tempDir) throws IOException {
......@@ -114,7 +151,7 @@ public class SenderClientIT extends IntegrationTestBase {
final URI submissionDataSchemaUri = URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json");
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, submissionDataSchemaUri)
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
......@@ -135,7 +172,7 @@ public class SenderClientIT extends IntegrationTestBase {
// Given
final ApplicationConfig config = getConfigWithCredentialsFromEnvironment("TESTING", true);
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID"));
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA"));
final CryptoService cryptoService = new JWECryptoService(new HashService());
final SenderClient senderClient = ClientFactory.getSenderClient(config);
......@@ -213,7 +250,7 @@ public class SenderClientIT extends IntegrationTestBase {
// When
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(getResourceAsString("/submission_data.json"), URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.build();
......@@ -236,7 +273,7 @@ public class SenderClientIT extends IntegrationTestBase {
final SenderClient senderClient = ClientFactory.getSenderClient(config);
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "plain/text"))
......
......@@ -60,7 +60,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final var senderClient = ClientFactory.getSenderClient(config);
final var subscriberClient = ClientFactory.getSubscriberClient(config);
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID"));
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA"));
final String leikaKey = "urn:de:fim:leika:leistung:99400048079000";
final String serviceName = "Test Service";
......@@ -109,7 +109,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final var senderClient = ClientFactory.getSenderClient(config);
final var subscriberClient = ClientFactory.getSubscriberClient(config);
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID"));
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA"));
final String leikaKey = "urn:de:fim:leika:leistung:99400048079000";
final String serviceName = "Test Service";
......@@ -147,7 +147,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final SenderClient senderClient = ClientFactory.getSenderClient(config);
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "plain/text"))
......@@ -188,7 +188,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final SubscriberClient subscriberClient = ClientFactory.getSubscriberClient(config);
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "plain/text"))
......@@ -225,7 +225,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final String submissionData = getResourceAsString("/submission_data.json");
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "plain/text"))
......@@ -268,7 +268,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final SubscriberClient subscriberClient = ClientFactory.getSubscriberClient(config);
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
......@@ -311,7 +311,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
final SubscriberClient subscriberClient = ClientFactory.getSubscriberClient(config);
final var submission = SendableSubmission.Builder()
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID")))
.setDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID_JSON_DATA")))
.setServiceType("urn:de:fim:leika:leistung:99400048079000", "Test Service")
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "plain/text"))
......
......@@ -17,11 +17,12 @@ public class EnableIfEnvironmentVariablesAreSetCondition implements ExecutionCon
}
private boolean allVariablesSet() {
final String destinationId = System.getenv("TEST_DESTINATION_ID");
final String destinationIdJsonData = System.getenv("TEST_DESTINATION_ID_JSON_DATA");
final String destinationIdXmlData = System.getenv("TEST_DESTINATION_ID_XML_DATA");
final String senderClientId = System.getenv("SENDER_CLIENT_ID");
final String senderClientSecret = System.getenv("SENDER_CLIENT_SECRET");
final String subscriberClientId = System.getenv("SUBSCRIBER_CLIENT_ID");
final String subscriberClientSecret = System.getenv("SUBSCRIBER_CLIENT_SECRET");
return Stream.of(destinationId, senderClientId, senderClientSecret, subscriberClientId, subscriberClientSecret).allMatch(Strings::isNotNullOrEmpty);
return Stream.of(destinationIdJsonData, destinationIdXmlData, senderClientId, senderClientSecret, subscriberClientId, subscriberClientSecret).allMatch(Strings::isNotNullOrEmpty);
}
}
This diff is collapsed.
......@@ -75,7 +75,7 @@
<apache-tika.version>2.8.0</apache-tika.version>
<snakeyaml.version>2.0</snakeyaml.version>
<open-csv.version>5.7.1</open-csv.version>
<json-schema-validator.version>1.0.83</json-schema-validator.version>
<json-schema-validator.version>1.0.84</json-schema-validator.version>
<!-- Testing -->
<junit.version>5.9.3</junit.version>
......@@ -87,8 +87,8 @@
<awaitility-version>4.2.0</awaitility-version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.1.0</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.1.2</maven-failsafe-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-install-plugin.version>3.1.1</maven-install-plugin.version>
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
......@@ -97,6 +97,7 @@
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<git-commit-id-maven-plugin.version>6.0.0</git-commit-id-maven-plugin.version>
......