From 03d702f49be732269d7c17262e0bf3c837522f54 Mon Sep 17 00:00:00 2001 From: James Fox Date: Fri, 25 Aug 2023 15:51:37 +0200 Subject: [PATCH 1/4] Add new AgeUtilService PHR-11742 --- pom.xml | 1 + util/pom.xml | 56 +++++++++++++++++++ .../pkb/pkbcommon/ageutil/AgeUtilService.java | 25 +++++++++ .../pkbcommon/ageutil/AgeUtilServiceTest.java | 43 ++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 util/pom.xml create mode 100644 util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java create mode 100644 util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java diff --git a/pom.xml b/pom.xml index d708583..4c7ae60 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,7 @@ spring-boot-infrastructure spring-boot-kotlin-infrastructure pubsub + util diff --git a/util/pom.xml b/util/pom.xml new file mode 100644 index 0000000..5e31bb8 --- /dev/null +++ b/util/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + pkb-common + com.pkb.pkbcommon + ${revision}${changelist} + + + util + + + + com.pkb.pkbcommon + date-time + + + org.hamcrest + hamcrest + + + org.mockito + mockito-core + test + + + org.hamcrest + hamcrest-core + + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + com.github.karsaig + approvalcrest-junit-jupiter + + + org.mockito + mockito-junit-jupiter + 4.5.1 + test + + + + diff --git a/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java b/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java new file mode 100644 index 0000000..477148b --- /dev/null +++ b/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java @@ -0,0 +1,25 @@ +package com.pkb.pkbcommon.ageutil; + +import com.pkb.common.datetime.DateTimeService; + +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; + +public class AgeUtilService { + + private final DateTimeService dateTimeService; + + public AgeUtilService(DateTimeService dateTimeService) { + this.dateTimeService = dateTimeService; + } + + public final static int MINIMUM_AGE_LETTER_INVITATION = 16; + + public boolean patientIsOlderThan(LocalDate dateOfBirth, int ageInYears) { + return dateOfBirth.plus(ageInYears, ChronoUnit.YEARS) + .atStartOfDay(ZoneOffset.UTC) + .toInstant() + .isBefore(dateTimeService.now()); + } +} diff --git a/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java b/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java new file mode 100644 index 0000000..bc71578 --- /dev/null +++ b/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java @@ -0,0 +1,43 @@ +package com.pkb.pkbcommon.ageutil; + +import com.pkb.common.datetime.DateTimeService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; + +import static com.github.karsaig.approvalcrest.jupiter.MatcherAssert.assertThat; +import static java.time.ZoneOffset.UTC; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class AgeUtilServiceTest { + + @Mock + DateTimeService dateTimeService; + @InjectMocks + AgeUtilService underTest; + + @Test + public void testUnderSixteen() { + Instant currentTime = Instant.parse("2020-01-02T00:00:00Z"); + when(dateTimeService.now()).thenReturn(currentTime); + LocalDate dateOfBirth = currentTime.atZone(UTC).minus(16, ChronoUnit.YEARS).toLocalDate(); + assertThat(underTest.patientIsOlderThan(dateOfBirth, 16), is(false)); + } + + @Test + public void testOverSixteen() { + Instant currentTime = Instant.parse("2020-01-02T00:00:00Z"); + when(dateTimeService.now()).thenReturn(currentTime); + LocalDate dateOfBirth = currentTime.atZone(UTC).minus(16, ChronoUnit.YEARS).minus(1, ChronoUnit.DAYS).toLocalDate(); + assertThat(underTest.patientIsOlderThan(dateOfBirth, 16), is(true)); + } + +} From 30d709b4ae5306596de65d628d1fea010e920cbd Mon Sep 17 00:00:00 2001 From: James Fox Date: Mon, 28 Aug 2023 17:06:16 +0200 Subject: [PATCH 2/4] Rewrite unit tests PHR-11742 --- .../com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java b/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java index bc71578..91c2857 100644 --- a/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java +++ b/util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.java @@ -9,10 +9,8 @@ import java.time.Instant; import java.time.LocalDate; -import java.time.temporal.ChronoUnit; import static com.github.karsaig.approvalcrest.jupiter.MatcherAssert.assertThat; -import static java.time.ZoneOffset.UTC; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.when; @@ -28,16 +26,15 @@ public class AgeUtilServiceTest { public void testUnderSixteen() { Instant currentTime = Instant.parse("2020-01-02T00:00:00Z"); when(dateTimeService.now()).thenReturn(currentTime); - LocalDate dateOfBirth = currentTime.atZone(UTC).minus(16, ChronoUnit.YEARS).toLocalDate(); + LocalDate dateOfBirth = LocalDate.of(2004,1,2); assertThat(underTest.patientIsOlderThan(dateOfBirth, 16), is(false)); } @Test - public void testOverSixteen() { - Instant currentTime = Instant.parse("2020-01-02T00:00:00Z"); + public void testOverSixteenByOneSecond() { + Instant currentTime = Instant.parse("2020-01-02T00:01:00Z"); when(dateTimeService.now()).thenReturn(currentTime); - LocalDate dateOfBirth = currentTime.atZone(UTC).minus(16, ChronoUnit.YEARS).minus(1, ChronoUnit.DAYS).toLocalDate(); + LocalDate dateOfBirth = LocalDate.of(2004,1,2); assertThat(underTest.patientIsOlderThan(dateOfBirth, 16), is(true)); } - } From a0d05b97dbb23104e0a6143400d638e37be0e108 Mon Sep 17 00:00:00 2001 From: James Fox Date: Fri, 1 Sep 2023 10:38:31 +0200 Subject: [PATCH 3/4] Move minimum age to config in PHR/FHIR PHR-11742 --- .../src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java b/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java index 477148b..9d72489 100644 --- a/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java +++ b/util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java @@ -14,8 +14,6 @@ public AgeUtilService(DateTimeService dateTimeService) { this.dateTimeService = dateTimeService; } - public final static int MINIMUM_AGE_LETTER_INVITATION = 16; - public boolean patientIsOlderThan(LocalDate dateOfBirth, int ageInYears) { return dateOfBirth.plus(ageInYears, ChronoUnit.YEARS) .atStartOfDay(ZoneOffset.UTC) From 8601bd8e3f0df28aed5938f212b316217283588a Mon Sep 17 00:00:00 2001 From: James Fox Date: Tue, 5 Sep 2023 09:10:02 +0200 Subject: [PATCH 4/4] Suppress false vulnerability PHR-11742 --- suppression.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/suppression.xml b/suppression.xml index b45ac82..f7f954d 100644 --- a/suppression.xml +++ b/suppression.xml @@ -38,5 +38,14 @@ CVE-2020-8908 CVE-2023-2976 - + + + ^pkg:maven/io\.netty/netty\-handler@.*$ + + + + CVE-2023-4586 +