diff --git a/FitConnect/Services/Models/v1/Api/Problems.cs b/FitConnect/Services/Models/v1/Api/Problems.cs index 2e67824cf5e52e600fe68bba43cadc82e5dfb6a0..20b8fa2b7313d66a5b1508ad7398c8cf4b1cec3a 100644 --- a/FitConnect/Services/Models/v1/Api/Problems.cs +++ b/FitConnect/Services/Models/v1/Api/Problems.cs @@ -23,6 +23,9 @@ public class Problems { public const string TitleMissingSchema = "Schema-Referenz fehlt"; public const string DetailMissingSchema = "Die Schema-Referenz fehlt im Metadatensatz."; + public const string TitleSchemaViolationData = "Schema-Fehler"; + public const string DetailsSchemaViolationData = "Der Fachdatensatz ist nicht schema-valide."; + public const string TitleUnsupportedService = "Verwaltungsleistung nicht unterstützt"; public const string DetailUnsupportedService = "Die angegebene Verwaltungsleistung wird nicht unterstützt."; @@ -64,6 +67,7 @@ public class Problems { public enum ProblemInstanceEnum { Submission, Metadata, + Data } internal Problems() { @@ -124,8 +128,8 @@ public class Problems { break; case ProblemTypeEnum.SchemaViolation: type += "schema-violation"; - title = TitleEventLogInconsistent; - instance = "submission"; + title = TitleSchemaViolationData; + instance = "data"; break; case ProblemTypeEnum.SyntaxViolation: type += "syntax-violation"; diff --git a/FitConnect/Subscriber.cs b/FitConnect/Subscriber.cs index 23b58c965d616899296a6a029dd180c26aca6129..6a0c4963f41777258c730d8591afe0d3528b0796 100644 --- a/FitConnect/Subscriber.cs +++ b/FitConnect/Subscriber.cs @@ -188,8 +188,14 @@ public class Subscriber : FitConnectClient, if (destinationService.SubmissionSchemas != null && destinationService.SubmissionSchemas .Select(s => s.SchemaUri) .Contains(dataSchema)) { - CheckDataSchema(dataSchema, submission); + var problem = new Problems(Problems.ProblemTypeEnum.UnsupportedDataSchema, + Problems.DetailUnsupportedDataSchema); + RejectSubmission(submission, problem); + throw new SecurityEventException(problem); } + + // SuccessCriteria:4.5 + CheckDataSchema(dataSchema, submission); } @@ -216,8 +222,8 @@ public class Subscriber : FitConnectClient, var isValidSchemaData = JObject.Parse(submission.Data!).IsValid(jSchema); if (!isValidSchemaData) { - var problem = new Problems(Problems.ProblemTypeEnum.UnsupportedDataSchema, - Problems.DetailUnsupportedDataSchema); + var problem = new Problems(Problems.ProblemTypeEnum.SchemaViolation, + Problems.DetailsSchemaViolationData); RejectSubmission(submission, problem); throw new SecurityEventException(problem); } diff --git a/IntegrationTests/Sender/SenderTestHappyPath.cs b/IntegrationTests/Sender/SenderTestHappyPath.cs index 0835df9794499caf2590f16666f25f95950f863f..90d46fa2bd0f277d41b1acb7862da0060de90ab1 100644 --- a/IntegrationTests/Sender/SenderTestHappyPath.cs +++ b/IntegrationTests/Sender/SenderTestHappyPath.cs @@ -90,6 +90,16 @@ public class SenderTestHappyPath : SenderTestBase { submission.Should().NotBeNull(); } + private class SampleData { + [JsonProperty(PropertyName = "$schema", Order = -2)] + public string Schema { get; set; } = + "https://git.fitko.de/fit-connect/sdk-dotnet/-/raw/feature/594-auto-reject/simple_schema.json"; + + public string FirstName { get; set; } + public string LastName { get; set; } + public int Age { get; set; } + } + [Test] public void Submit_FinishSubmissionWithData_ShouldGetIdFromServer() { // Arrange @@ -108,11 +118,11 @@ public class SenderTestHappyPath : SenderTestBase { .WithDestination(DestinationId) .WithServiceType("ServiceName", "urn:de:fim:leika:leistung:99400048079000") .WithAttachments(attachments) - .WithJsonData(JsonConvert.SerializeObject(new { + .WithJsonData(JsonConvert.SerializeObject(new SampleData{ FirstName = "John", LastName = "Doe", Age = 42, - Birthday = DateTime.Today.AddYears(-42) + // Birthday = DateTime.Today.AddYears(-42) })); // Act