Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Client Certificate Tests Repeatedly #1625

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,6 @@
<threadCount>1</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
<runOrder>random</runOrder>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.MediaType;
import net.ripe.db.whois.api.SecureRestTest;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.test.annotation.DirtiesContext;

import java.io.IOException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.fail;

@Tag("IntegrationTest")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class ClientCertificateServiceTestIntegration extends AbstractClientCertificateIntegrationTest {

@Test
@RepeatedTest(value = 5, failureThreshold = 4)
public void client_certificate() {
final String response = SecureRestTest.target(getClientSSLContext(), getClientCertificatePort(), "whois/client")
.request()
Expand All @@ -26,7 +29,7 @@ public void client_certificate() {
assertThat(response, containsString("-----END CERTIFICATE-----"));
}

@Test
@RepeatedTest(value = 5, failureThreshold = 4)
public void fail_on_no_client_certificate() {
try {
SecureRestTest.target(getClientCertificatePort(), "whois/client")
Expand All @@ -35,7 +38,7 @@ public void fail_on_no_client_certificate() {
.get(String.class);
fail();
} catch (ProcessingException e) {
assertThat(e.getMessage(), containsString("javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate"));
assertThat(e, instanceOf(IOException.class)); // bad certificate
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import net.ripe.db.whois.api.rest.mapper.FormattedClientAttributeMapper;
import net.ripe.db.whois.api.rest.mapper.FormattedServerAttributeMapper;
import net.ripe.db.whois.api.rest.mapper.WhoisObjectMapper;
import net.ripe.db.whois.common.aspects.RetryFor;
import net.ripe.db.whois.common.domain.CIString;
import net.ripe.db.whois.common.rpsl.AttributeType;
import net.ripe.db.whois.common.rpsl.ObjectType;
import net.ripe.db.whois.common.rpsl.RpslAttribute;
import net.ripe.db.whois.common.rpsl.RpslObject;
import net.ripe.db.whois.common.rpsl.RpslObjectBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;

import javax.net.ssl.SSLContext;
import java.io.IOException;
Expand All @@ -38,10 +39,12 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.fail;

@Tag("IntegrationTest")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class WhoisRestServiceClientCertificateTestIntegration extends AbstractClientCertificateIntegrationTest {

private static final RpslObject OWNER_MNT = RpslObject.parse("" +
Expand Down Expand Up @@ -205,8 +208,7 @@ public void update_person_with_client_cert_and_mntner_cert_successful() {
assertThat(whoisResources.getWhoisObjects().get(0).getAttributes().get(3).getValue(), containsString("updated"));
}

@Test
@RetryFor(value = IOException.class, attempts = 10, intervalMs = 10000)
@RepeatedTest(value = 5, failureThreshold = 4)
public void update_person_missing_private_key_unauthorised() throws Exception {
// create certificate and don't use private key
final CertificatePrivateKeyPair certificatePrivateKeyPair = new CertificatePrivateKeyPair();
Expand Down Expand Up @@ -235,7 +237,7 @@ public void update_person_missing_private_key_unauthorised() throws Exception {
.put(Entity.entity(map(updatedPerson), MediaType.APPLICATION_XML), WhoisResources.class);
fail();
} catch (ProcessingException e) {
assertThat(e.getMessage(), containsString("javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate"));
assertThat(e.getCause(), instanceOf(IOException.class)); // bad certificate
}
}

Expand Down
Loading