Skip to content

Commit

Permalink
Fixes to sonarlint problems (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaarni authored Oct 28, 2024
1 parent 8760d6f commit d697b10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void init() throws Exception {
}

@Test
public void testAdd() throws Exception {
void testAdd() throws Exception {
Credential anotherRevokedCert = new Credential().issuer(ca).subject("CN=revoked");
CertificateRevocationList crl = new CertificateRevocationList().add(revokedCert).add(anotherRevokedCert);
assertNotNull(crl);
Expand All @@ -65,7 +65,7 @@ public void testAdd() throws Exception {
}

@Test
public void testThisUpdate() throws Exception {
void testThisUpdate() throws Exception {
Date thisUpdate = Date.from(Instant.parse("2023-01-01T09:00:00Z"));
CertificateRevocationList crl = new CertificateRevocationList().thisUpdate(thisUpdate).add(revokedCert);
assertNotNull(crl);
Expand All @@ -76,7 +76,7 @@ public void testThisUpdate() throws Exception {
}

@Test
public void testNextUpdate() throws Exception {
void testNextUpdate() throws Exception {
Date nextUpdate = Date.from(Instant.parse("2100-01-01T09:00:00Z"));
CertificateRevocationList crl = new CertificateRevocationList().nextUpdate(nextUpdate).add(revokedCert);
assertNotNull(crl);
Expand All @@ -87,7 +87,7 @@ public void testNextUpdate() throws Exception {
}

@Test
public void testIssuer() throws Exception {
void testIssuer() throws Exception {
CertificateRevocationList crl = new CertificateRevocationList().issuer(ca).add(revokedCert);
assertNotNull(crl);

Expand All @@ -98,7 +98,7 @@ public void testIssuer() throws Exception {
}

@Test
public void testGetPem() throws Exception {
void testGetPem() throws Exception {
CertificateRevocationList crl = new CertificateRevocationList().add(revokedCert);
assertNotNull(crl);

Expand All @@ -115,7 +115,7 @@ public void testGetPem() throws Exception {
}

@Test
public void testWritingPem(@TempDir Path tempDir) throws Exception {
void testWritingPem(@TempDir Path tempDir) throws Exception {
Path crlPath = tempDir.resolve("crl.pem");

CertificateRevocationList crl = new CertificateRevocationList().add(revokedCert).writeAsPem(crlPath);
Expand All @@ -128,13 +128,13 @@ public void testWritingPem(@TempDir Path tempDir) throws Exception {
}

@Test
public void testUninitializedCaCertificate(@TempDir Path tempDir) throws Exception {
void testUninitializedCaCertificate(@TempDir Path tempDir) {
Credential uninitialized = new Credential().subject("cn=ca"); // We have not called generate() yet.
assertDoesNotThrow(() -> new CertificateRevocationList().issuer(uninitialized).writeAsPem(tempDir.resolve("crl.pem")));
}

@Test
public void testUninitializedRevokedCertificate(@TempDir Path tempDir) throws Exception {
void testUninitializedRevokedCertificate(@TempDir Path tempDir) {
Credential uninitialized = new Credential().issuer(ca).subject("cn=uninitialized"); // We have not called generate() yet.
assertDoesNotThrow(() -> new CertificateRevocationList().issuer(ca).add(uninitialized).writeAsPem(tempDir.resolve("crl.pem")));
}
Expand Down
13 changes: 6 additions & 7 deletions lib/src/test/java/fi/protonode/certy/TestCredential.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.asn1.x509.KeyPurposeId;
import org.bouncycastle.cert.X509CRLHolder;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.util.io.pem.PemObject;
Expand Down Expand Up @@ -61,7 +60,7 @@
import java.util.Arrays;
import java.util.Date;

public class TestCredential {
class TestCredential {

@Test
void testSubjectName() throws Exception {
Expand All @@ -77,7 +76,7 @@ void testSubjectAltName() throws Exception {
.getX509Certificate();
assertNotNull(cert);
assertEquals("CN=joe", cert.getSubjectX500Principal().getName());
Object expected[] = new Object[] {
Object[] expected = new Object[] {
Arrays.asList(GeneralName.dNSName, "host.example.com"),
Arrays.asList(GeneralName.uniformResourceIdentifier, "http://www.example.com"),
Arrays.asList(GeneralName.iPAddress, "1.2.3.4") };
Expand Down Expand Up @@ -239,20 +238,20 @@ void testNotBeforeAndNotAfter() throws Exception {
}

@Test
void testInvalidSubject() throws Exception {
void testInvalidSubject() {
Credential cred = new Credential();
assertThrows(IllegalArgumentException.class, () -> cred.subject("Foo=Bar"));
}

@Test
void testEmptySubjectAndSubjectAltNames() throws Exception {
void testEmptySubjectAndSubjectAltNames() {
// Both subject and subject alternative name cannot be empty.
Credential cred = new Credential();
assertThrows(IllegalArgumentException.class, () -> cred.getX509Certificate());
}

@Test
void testInvalidSubjectAltName() throws Exception {
void testInvalidSubjectAltName() {
Credential cred = new Credential().subject("CN=joe");
assertThrows(IllegalArgumentException.class, () -> cred.subjectAltName("EMAIL:[email protected]"));
assertThrows(IllegalArgumentException.class, () -> cred.subjectAltName("URL:"));
Expand All @@ -261,7 +260,7 @@ void testInvalidSubjectAltName() throws Exception {
}

@Test
void testInvalidKeySize() throws Exception {
void testInvalidKeySize() {
Credential cred1 = new Credential().subject("CN=joe").keyType(KeyType.EC).keySize(1);
assertThrows(IllegalArgumentException.class, () -> cred1.getX509Certificate());

Expand Down

0 comments on commit d697b10

Please sign in to comment.