From d7b6e81da5d31604e17ec3750ac5add42ebc889a Mon Sep 17 00:00:00 2001 From: Sebb Date: Sun, 29 Dec 2024 15:49:46 +0000 Subject: [PATCH 1/2] Warn if IBAN registry is old --- .../validator/routines/IBANValidatorTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java index 2490277d6..5abf3d974 100644 --- a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java @@ -32,7 +32,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -76,6 +78,10 @@ public class IBANValidatorTest { */ private static final String IBAN_REGISTRY = "iban_registry_v99.txt"; private static final Charset IBAN_REGISTRY_CHARSET = Charset.forName("windows-1252"); + private static final int MS_PER_DAY = 1000*60*60*24; + private static final long MAX_AGE_DAYS = 180; // how old registry can get (approx 6 months) + + // It's not clear whether IBANs can contain lower case characters // so we test for both where possible @@ -329,6 +335,7 @@ static Collection ibanRegistrySourceExamples() throws Exception { CSVRecord country = null; CSVRecord electronicExample = null; + CSVRecord lastUpdateDate = null; try (CSVParser p = new CSVParser(rdr, format)) { for (final CSVRecord o : p) { @@ -340,6 +347,9 @@ static Collection ibanRegistrySourceExamples() throws Exception { case "IBAN electronic format example": electronicExample = o; break; + case "Last update date": + lastUpdateDate = o; + break; default: break; } @@ -347,13 +357,28 @@ static Collection ibanRegistrySourceExamples() throws Exception { } assertNotNull(country); + final int arraySize = country.size(); assertNotNull(electronicExample); + assertEquals(arraySize, electronicExample.size()); + assertNotNull(lastUpdateDate); + assertEquals(arraySize, lastUpdateDate.size()); final Collection result = new ArrayList<>(); + Date lastDate = new Date(0); + String lastUpdated = null; for (int i = 1; i < country.size(); i++) { result.add(Arguments.of(country.get(i), electronicExample.get(i))); + final String mmyy = lastUpdateDate.get(i); + final Date dt = DateValidator.getInstance().validate(mmyy,"MMM-yy",Locale.ROOT); + if (dt.after(lastDate)) { + lastDate = dt; + lastUpdated = mmyy; + } + } + final long age = (new Date().getTime() - lastDate.getTime())/MS_PER_DAY; + if (age > MAX_AGE_DAYS) { // not necessarily a failure + System.out.println("WARNING: expected recent last update date, but found: " + lastUpdated); } - return result; } From 25bd912d56b87fa3a49570be733d706ddf06e2b6 Mon Sep 17 00:00:00 2001 From: Sebb Date: Sun, 29 Dec 2024 15:54:35 +0000 Subject: [PATCH 2/2] Ch**ckstyle --- .../commons/validator/routines/IBANValidatorTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java index 5abf3d974..8a87654ac 100644 --- a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java @@ -78,9 +78,9 @@ public class IBANValidatorTest { */ private static final String IBAN_REGISTRY = "iban_registry_v99.txt"; private static final Charset IBAN_REGISTRY_CHARSET = Charset.forName("windows-1252"); - private static final int MS_PER_DAY = 1000*60*60*24; + private static final int MS_PER_DAY = 1000 * 60 * 60 * 24; private static final long MAX_AGE_DAYS = 180; // how old registry can get (approx 6 months) - + // It's not clear whether IBANs can contain lower case characters @@ -369,13 +369,13 @@ static Collection ibanRegistrySourceExamples() throws Exception { for (int i = 1; i < country.size(); i++) { result.add(Arguments.of(country.get(i), electronicExample.get(i))); final String mmyy = lastUpdateDate.get(i); - final Date dt = DateValidator.getInstance().validate(mmyy,"MMM-yy",Locale.ROOT); + final Date dt = DateValidator.getInstance().validate(mmyy, "MMM-yy", Locale.ROOT); if (dt.after(lastDate)) { lastDate = dt; lastUpdated = mmyy; } } - final long age = (new Date().getTime() - lastDate.getTime())/MS_PER_DAY; + final long age = (new Date().getTime() - lastDate.getTime()) / MS_PER_DAY; if (age > MAX_AGE_DAYS) { // not necessarily a failure System.out.println("WARNING: expected recent last update date, but found: " + lastUpdated); }