Skip to content

Commit cf822e0

Browse files
committed
Add javadocs and update TODO's + add a simple test
1 parent 860b23b commit cf822e0

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

sign/src/main/java/com/itextpdf/signatures/validation/lotl/EuropeanLotlFetcher.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public class EuropeanLotlFetcher {
4242

4343
private final LotlService service;
4444

45+
/**
46+
* Constructs a new instance of {@link EuropeanLotlFetcher} with the specified LotlService.
47+
*
48+
* @param service the LotlService used to retrieve resources
49+
*/
4550
public EuropeanLotlFetcher(LotlService service) {
4651
this.service = service;
4752
}
@@ -86,7 +91,6 @@ public static class Result {
8691
*/
8792
public Result(byte[] lotlXml) {
8893
setLotlXml(lotlXml);
89-
9094
}
9195

9296
/**

sign/src/main/java/com/itextpdf/signatures/validation/lotl/IOnCountryFetchFailureStrategy.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ This file is part of the iText (R) project.
2626
* Interface for handling the failure of fetching a country-specific List of Trusted Lists (Lotl).
2727
* Implementations can define custom strategies for dealing with such failures.
2828
* <p>
29-
* //TODO mention default implementations
29+
* We provide 2 default implementations out of the box:
30+
* - {@link com.itextpdf.signatures.validation.lotl.IgnoreCountrySpecificCertificates} - which does nothing and won't
31+
* throw an exception, but will not add any country-specific certificates to the trust store.
32+
* - {@link com.itextpdf.signatures.validation.lotl.ThrowExceptionIOnFailureStrategy} - which will throw an exception
33+
* if the fetching of a country-specific Lotl fails so that the validation process can be halted.
3034
*/
3135
public interface IOnCountryFetchFailureStrategy {
3236

33-
//TODO add javadoc for doing stuff related certificates and validation report and their items will be added to
34-
// the main report
35-
//so if invalid is added main report will be invalidated
3637

3738
/**
3839
* This method is called when the fetching of a country-specific Lotl fails.
3940
* It allows for custom handling of the failure.
41+
* <p>
42+
* If the implementation does not throw an exception, the validation process will continue, and the certificates
43+
* from the {@code CountrySpecificLotlFetcher.Result } will not be added to the trust store.
4044
*
4145
* @param fetchResult the result of the fetch attempt, which may contain error details
4246
*/

sign/src/main/java/com/itextpdf/signatures/validation/lotl/PivotFetcher.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public class PivotFetcher {
5050
private final LotlService service;
5151
private final ValidatorChainBuilder builder;
5252

53+
/**
54+
* Constructs a PivotFetcher with the specified LotlService and ValidatorChainBuilder.
55+
*
56+
* @param service the LotlService used to retrieve resources
57+
* @param builder the ValidatorChainBuilder used to build the XML signature validator
58+
*/
5359
public PivotFetcher(LotlService service, ValidatorChainBuilder builder) {
5460
this.service = service;
5561
this.builder = builder;

sign/src/test/java/com/itextpdf/signatures/validation/lotl/InMemoryLotlServiceCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void cacheInvalidationWorks() throws InterruptedException {
8282
byte[] data = "test data".getBytes(StandardCharsets.UTF_8);
8383
EuropeanLotlFetcher.Result result = new EuropeanLotlFetcher.Result(data);
8484
// Simulate staleness by waiting longer than the max allowed staleness
85-
Thread.sleep(50);
85+
Thread.sleep(250);
8686

8787
cache.setLotlResult(result);
8888
assertArrayEquals(data, cache.getLotlResult().getLotlXml(), "The byte data should match the set data.");

sign/src/test/java/com/itextpdf/signatures/validation/lotl/LotlValidatorTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,33 @@ public Result fetch() {
338338
});
339339
}
340340

341+
342+
@Test
343+
public void inMemoryCacheThrowsException() throws InterruptedException {
344+
ValidatorChainBuilder chainBuilder = new ValidatorChainBuilder();
345+
chainBuilder.withLotlFetchingProperties(new LotlFetchingProperties(new IgnoreCountrySpecificCertificates()));
346+
chainBuilder.getLotlFetchingProperties().setCountryNames("NL");
347+
chainBuilder.getLotlFetchingProperties().setCacheStalenessInMilliseconds(100);
348+
chainBuilder.getLotlFetchingProperties().setRefreshIntervalCalculator((f) -> 100000);
349+
350+
LotlService service = new LotlService(chainBuilder);
351+
service.withCustomResourceRetriever(new FromDiskResourceRetriever(SOURCE_FOLDER_LOL_FILES));
352+
service.initializeCache();
353+
354+
chainBuilder.withLotlValidator(() -> new LotlValidator(chainBuilder).withService(service));
355+
356+
Thread.sleep(1000);
357+
358+
LotlValidator validator = chainBuilder.getLotlValidator();
359+
360+
Exception e = assertThrows(PdfException.class, () -> {
361+
// This should throw an exception because the cache is stale
362+
validator.validate();
363+
});
364+
Assertions.assertEquals(SignExceptionMessageConstant.STALE_DATA_IS_USED, e.getMessage());
365+
366+
}
367+
341368
@Test
342369
@LogMessages(
343370
messages = {

0 commit comments

Comments
 (0)