Skip to content

Commit

Permalink
Do not use deprecated method in tests unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
lolepezy committed Jan 5, 2024
1 parent 1874b4a commit c1f149e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import net.ripe.rpki.commons.crypto.ValidityPeriod;
import org.joda.time.DateTime;
import org.junit.runner.RunWith;

Expand All @@ -14,27 +15,21 @@

@RunWith(JUnitQuickcheck.class)
public class ManifestCMSBuilderPropertyTest {

@Property public void buildEncodedParseCheck(
byte[] content,
BigInteger manifestNumber,
Integer validityHours
){
ManifestCmsBuilder builder = new ManifestCmsBuilder();
builder.addFile("test.crl", content);
builder.withManifestNumber(manifestNumber);
builder.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER);
builder.withCertificate(createValidManifestEECertificate(TEST_KEY_PAIR));
DateTime start = DateTime.now();
builder.withThisUpdateTime(start);
builder.withNextUpdateTime(start.plusHours(validityHours));
ManifestCms manifestCms = builder.build(TEST_KEY_PAIR.getPrivate());

ManifestCmsParser mftParser = new ManifestCmsParser();
mftParser.parse("test.mft", manifestCms.getEncoded());
assertTrue(mftParser.getManifestCms().containsFile("test.crl"));
@Property
public void buildEncodedParseCheck(byte[] content, BigInteger manifestNumber, Integer validityHours) {
ManifestCmsBuilder builder = new ManifestCmsBuilder();
builder.addFile("test.crl", content);
builder.withManifestNumber(manifestNumber);
builder.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER);
builder.withCertificate(createValidManifestEECertificate(TEST_KEY_PAIR));
DateTime start = DateTime.now();
builder.withValidityPeriod(new ValidityPeriod(start, start.plusHours(Math.abs(validityHours))));
ManifestCms manifestCms = builder.build(TEST_KEY_PAIR.getPrivate());

ManifestCmsParser mftParser = new ManifestCmsParser();
mftParser.parse("test.mft", manifestCms.getEncoded());
assertTrue(mftParser.getManifestCms().containsFile("test.crl"));
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class ManifestCmsBuilderTest {
@Before
public void setUp() {
subject.withManifestNumber(BigInteger.valueOf(68));
subject.withThisUpdateTime(THIS_UPDATE_TIME);
subject.withNextUpdateTime(NEXT_UPDATE_TIME);
subject.withValidityPeriod(new ValidityPeriod(THIS_UPDATE_TIME, NEXT_UPDATE_TIME));
subject.withCertificate(createValidManifestEECertificate());
subject.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void setUp() {
DateTimeUtils.setCurrentMillisFixed(THIS_UPDATE_TIME.getMillis());
ManifestCmsBuilder builder = new ManifestCmsBuilder();
builder.withCertificate(createValidManifestEECertificate()).withManifestNumber(BigInteger.valueOf(68));
builder.withThisUpdateTime(THIS_UPDATE_TIME).withNextUpdateTime(NEXT_UPDATE_TIME);
builder.withValidityPeriod(new ValidityPeriod(THIS_UPDATE_TIME, NEXT_UPDATE_TIME));
builder.addFile("foo1", FOO_CONTENT);
builder.addFile("BaR", BAR_CONTENT);
builder.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER);
Expand Down Expand Up @@ -201,7 +201,7 @@ public void shouldRejectManifestWithNonInheritEECert() {

// Use 10/8 EE cert
builder.withCertificate(createTenSlashEightResourceCertificate()).withManifestNumber(BigInteger.valueOf(68));
builder.withThisUpdateTime(THIS_UPDATE_TIME).withNextUpdateTime(NEXT_UPDATE_TIME);
builder.withValidityPeriod(new ValidityPeriod(THIS_UPDATE_TIME, NEXT_UPDATE_TIME));
builder.addFile("foo1", FOO_CONTENT);
builder.addFile("BaR", BAR_CONTENT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,19 @@ public void shouldRejectWhenThisUpdateTimeIsNotBeforeNextUpdateTime() {

IpResourceSet resources = rootCertificate.getResources();

CertificateRepositoryObjectValidationContext context = new CertificateRepositoryObjectValidationContext(ROOT_CERTIFICATE_LOCATION, rootCertificate, resources, Lists.newArrayList(rootCertificate.getSubject().getName()));
CertificateRepositoryObjectValidationContext context = new CertificateRepositoryObjectValidationContext(
ROOT_CERTIFICATE_LOCATION, rootCertificate, resources, Lists.newArrayList(rootCertificate.getSubject().getName()));
ValidationResult result = ValidationResult.withLocation(ROOT_SIA_MANIFEST_RSYNC_LOCATION);

subject.validateWithCrl(ROOT_SIA_MANIFEST_RSYNC_LOCATION.toASCIIString(), context, ValidationOptions.strictValidation(), result, crl);

assertTrue(result.hasFailures());
assertEquals(
new ValidationCheck(ValidationStatus.ERROR, ValidationString.MANIFEST_THIS_UPDATE_TIME_BEFORE_NEXT_UPDATE_TIME, NEXT_UPDATE_TIME.plusSeconds(1).toString(), NEXT_UPDATE_TIME.toString()),
result.getResult(new ValidationLocation(ROOT_SIA_MANIFEST_RSYNC_LOCATION), ValidationString.MANIFEST_THIS_UPDATE_TIME_BEFORE_NEXT_UPDATE_TIME)
new ValidationCheck(ValidationStatus.ERROR,
ValidationString.MANIFEST_THIS_UPDATE_TIME_BEFORE_NEXT_UPDATE_TIME,
NEXT_UPDATE_TIME.plusSeconds(1).toString(), NEXT_UPDATE_TIME.toString()),
result.getResult(new ValidationLocation(ROOT_SIA_MANIFEST_RSYNC_LOCATION),
ValidationString.MANIFEST_THIS_UPDATE_TIME_BEFORE_NEXT_UPDATE_TIME)
);
}

Expand Down Expand Up @@ -455,7 +459,7 @@ public static ManifestCmsBuilder getRootManifestBuilder(ValidityPeriod validityP
ManifestCmsBuilder builder = new ManifestCmsBuilder();
builder.withCertificate(getManifestEEResourceCertificateBuilder().build());
builder.withManifestNumber(BigInteger.valueOf(68));
builder.withThisUpdateTime(validityPeriod.getNotValidBefore()).withNextUpdateTime(validityPeriod.getNotValidAfter());
builder.withValidityPeriod(validityPeriod);
builder.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER);
return builder;
}
Expand Down

0 comments on commit c1f149e

Please sign in to comment.