aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/src/test/java/com/yahoo/application/ApplicationTest.java3
-rw-r--r--athenz-identity-provider-service/pom.xml35
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/IdentityDocumentGeneratorTest.java32
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java28
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java16
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/CertificateAuthorityApiTest.java68
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/ContainerTester.java10
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/InstanceSerializerTest.java38
-rw-r--r--hosted-zone-api/pom.xml19
-rw-r--r--hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java14
-rw-r--r--http-utils/pom.xml9
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java10
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java16
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java20
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java14
-rw-r--r--jdisc-security-filters/pom.xml22
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java34
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java16
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java8
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsPreflightRequestFilterTest.java18
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsResponseFilterTest.java18
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/LocalhostFilterTest.java8
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/VespaTlsFilterTest.java8
-rw-r--r--jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/rule/RuleBasedRequestFilterTest.java3
-rw-r--r--parent/pom.xml31
-rw-r--r--security-tools/pom.xml13
-rw-r--r--security-tools/src/test/java/com/yahoo/vespa/security/tool/securityenv/MainTest.java24
-rw-r--r--security-utils/pom.xml16
-rw-r--r--security-utils/src/test/java/com/yahoo/security/AutoReloadingX509KeyManagerTest.java17
-rw-r--r--security-utils/src/test/java/com/yahoo/security/KeyStoreBuilderTest.java20
-rw-r--r--security-utils/src/test/java/com/yahoo/security/KeyUtilsTest.java24
-rw-r--r--security-utils/src/test/java/com/yahoo/security/MutableX509KeyManagerTest.java4
-rw-r--r--security-utils/src/test/java/com/yahoo/security/MutableX509TrustManagerTest.java4
-rw-r--r--security-utils/src/test/java/com/yahoo/security/Pkcs10CsrBuilderTest.java6
-rw-r--r--security-utils/src/test/java/com/yahoo/security/Pkcs10CsrTest.java12
-rw-r--r--security-utils/src/test/java/com/yahoo/security/Pkcs10CsrUtilsTest.java8
-rw-r--r--security-utils/src/test/java/com/yahoo/security/SslContextBuilderTest.java26
-rw-r--r--security-utils/src/test/java/com/yahoo/security/X509CertificateBuilderTest.java39
-rw-r--r--security-utils/src/test/java/com/yahoo/security/X509CertificateUtilsTest.java16
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/AuthorizedPeersTest.java17
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/ConfigFileBasedTlsContextTest.java21
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/DefaultTlsContextTest.java4
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/HostGlobPatternTest.java20
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/PeerAuthorizerTest.java20
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsJsonSerializerTest.java30
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsTest.java8
-rw-r--r--vespa-athenz/pom.xml39
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java17
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzResourceNameTest.java6
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/NTokenGeneratorTest.java12
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialsTest.java14
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identity/SiaIdentityProviderTest.java27
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/api/VespaUniqueInstanceIdTest.java6
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/AthenzIdentityProviderImplTest.java36
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/IdentityDocumentSignerTest.java6
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/InstanceCsrGeneratorTest.java6
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentitiesTest.java6
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentityVerifierTest.java8
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java18
59 files changed, 567 insertions, 481 deletions
diff --git a/application/src/test/java/com/yahoo/application/ApplicationTest.java b/application/src/test/java/com/yahoo/application/ApplicationTest.java
index 7b7ad4ad002..1b542b4ac98 100644
--- a/application/src/test/java/com/yahoo/application/ApplicationTest.java
+++ b/application/src/test/java/com/yahoo/application/ApplicationTest.java
@@ -63,9 +63,8 @@ public class ApplicationTest {
}
}
- /** Tests that an application with query profile sets up the QueryProfileRegistry */
@Test
- public void container_and_query_profile() {
+ public void application_with_query_profile_sets_up_query_profile_registry() {
try (Application application =
Application.fromApplicationPackage(new File("src/test/app-packages/withqueryprofile"), Networking.disable)) {
Query query = new Query(HttpRequest.createTestRequest("?query=substring:foobar&timeout=20000", com.yahoo.jdisc.http.HttpRequest.Method.GET), application.getCompiledQueryProfileRegistry().findQueryProfile("default"));
diff --git a/athenz-identity-provider-service/pom.xml b/athenz-identity-provider-service/pom.xml
index d5e6b85f571..f4daa43b8e3 100644
--- a/athenz-identity-provider-service/pom.xml
+++ b/athenz-identity-provider-service/pom.xml
@@ -93,14 +93,19 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>orchestrator</artifactId>
- <version>${project.version}</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>orchestrator</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -113,12 +118,32 @@
<artifactId>application</artifactId>
<version>${project.version}</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.yahoo.vespa</groupId>
<artifactId>testutil</artifactId>
<version>${project.version}</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.yahoo.vespa</groupId>
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/IdentityDocumentGeneratorTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/IdentityDocumentGeneratorTest.java
index 508124935c1..9205baff0fc 100644
--- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/IdentityDocumentGeneratorTest.java
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/IdentityDocumentGeneratorTest.java
@@ -25,14 +25,14 @@ import com.yahoo.vespa.hosted.provision.node.Generation;
import com.yahoo.vespa.hosted.provision.node.IP;
import com.yahoo.vespa.hosted.provision.node.Nodes;
import com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Optional;
import java.util.Set;
import static com.yahoo.vespa.hosted.athenz.instanceproviderservice.TestUtils.getAthenzProviderConfig;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -45,27 +45,27 @@ public class IdentityDocumentGeneratorTest {
private static final Zone ZONE = new Zone(SystemName.cd, Environment.dev, RegionName.from("us-north-1"));
@Test
- public void generates_valid_identity_document() {
+ void generates_valid_identity_document() {
String parentHostname = "docker-host";
String containerHostname = "docker-container";
ApplicationId appid = ApplicationId.from(
TenantName.from("tenant"), ApplicationName.from("application"), InstanceName.from("default"));
Allocation allocation = new Allocation(appid,
- ClusterMembership.from("container/default/0/0", Version.fromString("1.2.3"), Optional.empty()),
- new NodeResources(1, 1, 1, 1),
- Generation.initial(),
- false);
+ ClusterMembership.from("container/default/0/0", Version.fromString("1.2.3"), Optional.empty()),
+ new NodeResources(1, 1, 1, 1),
+ Generation.initial(),
+ false);
Node parentNode = Node.create("ostkid",
- IP.Config.ofEmptyPool(Set.of("127.0.0.1")),
- parentHostname,
- new MockNodeFlavors().getFlavorOrThrow("default"),
- NodeType.host).build();
+ IP.Config.ofEmptyPool(Set.of("127.0.0.1")),
+ parentHostname,
+ new MockNodeFlavors().getFlavorOrThrow("default"),
+ NodeType.host).build();
Node containerNode = Node.reserve(Set.of("::1"),
- containerHostname,
- parentHostname,
- new MockNodeFlavors().getFlavorOrThrow("default").resources(),
- NodeType.tenant)
+ containerHostname,
+ parentHostname,
+ new MockNodeFlavors().getFlavorOrThrow("default").resources(),
+ NodeType.tenant)
.allocation(allocation).build();
NodeRepository nodeRepository = mock(NodeRepository.class);
Nodes nodes = mock(Nodes.class);
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java
index 6dc2e58059f..9a91d7372da 100644
--- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java
@@ -25,7 +25,7 @@ import com.yahoo.vespa.hosted.provision.NodeRepository;
import com.yahoo.vespa.hosted.provision.node.IP;
import com.yahoo.vespa.hosted.provision.node.Nodes;
import com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.ArrayList;
@@ -42,8 +42,8 @@ import java.util.stream.Stream;
import static com.yahoo.vespa.hosted.athenz.instanceproviderservice.InstanceValidator.SERVICE_PROPERTIES_DOMAIN_KEY;
import static com.yahoo.vespa.hosted.athenz.instanceproviderservice.InstanceValidator.SERVICE_PROPERTIES_SERVICE_KEY;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -62,14 +62,14 @@ public class InstanceValidatorTest {
private final AthenzService vespaTenantDomain = new AthenzService("vespa.vespa.tenant");
@Test
- public void application_does_not_exist() {
+ void application_does_not_exist() {
SuperModelProvider superModelProvider = mockSuperModelProvider();
InstanceValidator instanceValidator = new InstanceValidator(null, superModelProvider, null, null, vespaTenantDomain);
assertFalse(instanceValidator.isValidInstance(createRegisterInstanceConfirmation(applicationId, domain, service)));
}
@Test
- public void application_does_not_have_domain_set() {
+ void application_does_not_have_domain_set() {
SuperModelProvider superModelProvider = mockSuperModelProvider(
mockApplicationInfo(applicationId, 5, Collections.emptyList()));
InstanceValidator instanceValidator = new InstanceValidator(null, superModelProvider, null, new IdentityDocumentSigner(), vespaTenantDomain);
@@ -78,9 +78,9 @@ public class InstanceValidatorTest {
}
@Test
- public void application_has_wrong_domain() {
+ void application_has_wrong_domain() {
ServiceInfo serviceInfo = new ServiceInfo("serviceName", "type", Collections.emptyList(),
- Collections.singletonMap(SERVICE_PROPERTIES_DOMAIN_KEY, "not-domain"), "confId", "hostName");
+ Collections.singletonMap(SERVICE_PROPERTIES_DOMAIN_KEY, "not-domain"), "confId", "hostName");
SuperModelProvider superModelProvider = mockSuperModelProvider(
mockApplicationInfo(applicationId, 5, Collections.singletonList(serviceInfo)));
@@ -90,13 +90,13 @@ public class InstanceValidatorTest {
}
@Test
- public void application_has_same_domain_and_service() {
+ void application_has_same_domain_and_service() {
Map<String, String> properties = new HashMap<>();
properties.put(SERVICE_PROPERTIES_DOMAIN_KEY, domain);
properties.put(SERVICE_PROPERTIES_SERVICE_KEY, service);
ServiceInfo serviceInfo = new ServiceInfo("serviceName", "type", Collections.emptyList(),
- properties, "confId", "hostName");
+ properties, "confId", "hostName");
SuperModelProvider superModelProvider = mockSuperModelProvider(
mockApplicationInfo(applicationId, 5, Collections.singletonList(serviceInfo)));
@@ -108,7 +108,7 @@ public class InstanceValidatorTest {
}
@Test
- public void rejects_invalid_provider_unique_id_in_csr() {
+ void rejects_invalid_provider_unique_id_in_csr() {
SuperModelProvider superModelProvider = mockSuperModelProvider();
InstanceValidator instanceValidator = new InstanceValidator(null, superModelProvider, null, null, vespaTenantDomain);
InstanceConfirmation instanceConfirmation = createRegisterInstanceConfirmation(applicationId, domain, service);
@@ -118,7 +118,7 @@ public class InstanceValidatorTest {
}
@Test
- public void rejects_unknown_ips_in_csr() {
+ void rejects_unknown_ips_in_csr() {
NodeRepository nodeRepository = mockNodeRepo();
InstanceValidator instanceValidator = new InstanceValidator(null, mockSuperModelProvider(), nodeRepository, null, vespaTenantDomain);
InstanceConfirmation instanceConfirmation = createRegisterInstanceConfirmation(applicationId, domain, service);
@@ -134,7 +134,7 @@ public class InstanceValidatorTest {
}
@Test
- public void accepts_valid_refresh_requests() {
+ void accepts_valid_refresh_requests() {
NodeRepository nodeRepository = mock(NodeRepository.class);
Nodes nodes = mock(Nodes.class);
when(nodeRepository.nodes()).thenReturn(nodes);
@@ -151,7 +151,7 @@ public class InstanceValidatorTest {
}
@Test
- public void rejects_refresh_on_ip_mismatch() {
+ void rejects_refresh_on_ip_mismatch() {
NodeRepository nodeRepository = mockNodeRepo();
InstanceValidator instanceValidator = new InstanceValidator(null, null, nodeRepository, new IdentityDocumentSigner(), vespaTenantDomain);
@@ -169,7 +169,7 @@ public class InstanceValidatorTest {
}
@Test
- public void rejects_refresh_when_node_is_not_allocated() {
+ void rejects_refresh_when_node_is_not_allocated() {
NodeRepository nodeRepository = mock(NodeRepository.class);
Nodes nodes = mock(Nodes.class);
when(nodeRepository.nodes()).thenReturn(nodes);
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java
index 19ee3d22330..dd3ddeeb804 100644
--- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java
@@ -5,7 +5,7 @@ import com.yahoo.security.KeyAlgorithm;
import com.yahoo.security.KeyUtils;
import com.yahoo.security.SubjectAlternativeName;
import com.yahoo.test.ManualClock;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
@@ -13,8 +13,8 @@ import java.time.Duration;
import java.util.List;
import static java.time.temporal.ChronoUnit.SECONDS;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author mpolden
@@ -25,7 +25,7 @@ public class CertificatesTest {
private final X509Certificate caCertificate = CertificateTester.createCertificate("CA", keyPair);
@Test
- public void expiry() {
+ void expiry() {
var clock = new ManualClock();
var certificates = new Certificates(clock);
var csr = CertificateTester.createCsr();
@@ -37,7 +37,7 @@ public class CertificatesTest {
}
@Test
- public void add_san_from_csr() throws Exception {
+ void add_san_from_csr() throws Exception {
var certificates = new Certificates(new ManualClock());
var dnsName = "host.example.com";
var ip = "192.0.2.42";
@@ -49,13 +49,13 @@ public class CertificatesTest {
var subjectAlternativeNames = List.copyOf(certificate.getSubjectAlternativeNames());
assertEquals(List.of(SubjectAlternativeName.Type.DNS.getTag(), dnsName),
- subjectAlternativeNames.get(0));
+ subjectAlternativeNames.get(0));
assertEquals(List.of(SubjectAlternativeName.Type.IP.getTag(), ip),
- subjectAlternativeNames.get(1));
+ subjectAlternativeNames.get(1));
}
@Test
- public void parse_instance_id() {
+ void parse_instance_id() {
var instanceId = "1.cluster1.default.app1.tenant1.us-north-1.prod.node";
var instanceIdWithSuffix = instanceId + ".instanceid.athenz.dev-us-north-1.vespa.aws.oath.cloud";
var csr = CertificateTester.createCsr(List.of("foo", "bar", instanceIdWithSuffix));
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/CertificateAuthorityApiTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/CertificateAuthorityApiTest.java
index 7bfc4ad41a4..bf2115e8759 100644
--- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/CertificateAuthorityApiTest.java
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/CertificateAuthorityApiTest.java
@@ -17,8 +17,8 @@ import com.yahoo.vespa.athenz.client.zts.DefaultZtsClient;
import com.yahoo.vespa.hosted.ca.CertificateTester;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext;
import java.net.URI;
@@ -28,9 +28,9 @@ import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author mpolden
@@ -45,25 +45,25 @@ public class CertificateAuthorityApiTest extends ContainerTester {
private static final String CONTAINER_IDENTITY = "vespa.external.tenant";
private static final String HOST_IDENTITY = "vespa.external.tenant-host";
- @Before
+ @BeforeEach
public void before() {
setCaCertificateAndKey();
}
@Test
- public void register_instance() throws Exception {
+ void register_instance() throws Exception {
// POST instance registration
var csr = CertificateTester.createCsr(List.of("node1.example.com", INSTANCE_ID_WITH_SUFFIX));
assertIdentityResponse(new Request("http://localhost:12345/ca/v1/instance/",
- instanceRegistrationJson(csr),
- Request.Method.POST));
+ instanceRegistrationJson(csr),
+ Request.Method.POST));
// POST instance registration with ZTS client
var ztsClient = new TestZtsClient(new AthenzPrincipal(new AthenzService(HOST_IDENTITY)), null, URI.create("http://localhost:12345/ca/v1/"), SSLContext.getDefault());
var instanceIdentity = ztsClient.registerInstance(new AthenzService("vespa.external", "provider_prod_us-north-1"),
- new AthenzService(CONTAINER_IDENTITY),
- getAttestationData(),
- csr);
+ new AthenzService(CONTAINER_IDENTITY),
+ getAttestationData(),
+ csr);
assertEquals("CN=Vespa CA", instanceIdentity.certificate().getIssuerX500Principal().getName());
}
@@ -84,7 +84,7 @@ public class CertificateAuthorityApiTest extends ContainerTester {
}
@Test
- public void refresh_instance() throws Exception {
+ void refresh_instance() throws Exception {
// Register instance to get cert
var certificate = registerInstance();
@@ -92,41 +92,41 @@ public class CertificateAuthorityApiTest extends ContainerTester {
var principal = new AthenzPrincipal(new AthenzService(CONTAINER_IDENTITY));
var csr = CertificateTester.createCsr(principal.getIdentity().getFullName(), List.of("node1.example.com", INSTANCE_ID_WITH_SUFFIX));
var request = new Request("http://localhost:12345/ca/v1/instance/vespa.external.provider_prod_us-north-1/vespa.external/tenant/" + INSTANCE_ID,
- instanceRefreshJson(csr),
- Request.Method.POST,
- principal);
+ instanceRefreshJson(csr),
+ Request.Method.POST,
+ principal);
request.getAttributes().put(RequestUtils.JDISC_REQUEST_X509CERT, new X509Certificate[]{certificate});
assertIdentityResponse(request);
// POST instance refresh with ZTS client
var ztsClient = new TestZtsClient(principal, certificate, URI.create("http://localhost:12345/ca/v1/"), SSLContext.getDefault());
var instanceIdentity = ztsClient.refreshInstance(new AthenzService("vespa.external", "provider_prod_us-north-1"),
- new AthenzService(CONTAINER_IDENTITY),
- INSTANCE_ID,
- csr);
+ new AthenzService(CONTAINER_IDENTITY),
+ INSTANCE_ID,
+ csr);
assertEquals("CN=Vespa CA", instanceIdentity.certificate().getIssuerX500Principal().getName());
}
@Test
- public void invalid_requests() throws Exception {
+ void invalid_requests() throws Exception {
// POST instance registration with missing fields
assertResponse(400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"POST http://localhost:12345/ca/v1/instance/ failed: Missing required field 'provider'\"}",
- new Request("http://localhost:12345/ca/v1/instance/",
- new byte[0],
- Request.Method.POST));
+ new Request("http://localhost:12345/ca/v1/instance/",
+ new byte[0],
+ Request.Method.POST));
// POST instance registration without DNS name in CSR
var csr = CertificateTester.createCsr();
var request = new Request("http://localhost:12345/ca/v1/instance/",
- instanceRegistrationJson(csr),
- Request.Method.POST);
+ instanceRegistrationJson(csr),
+ Request.Method.POST);
assertResponse(400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"POST http://localhost:12345/ca/v1/instance/ failed: No instance ID found in CSR\"}", request);
// POST instance refresh with missing field
assertResponse(400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"POST http://localhost:12345/ca/v1/instance/vespa.external.provider_prod_us-north-1/vespa.external/tenant/1.cluster1.default.app1.tenant1.us-north-1.prod.node failed: Missing required field 'csr'\"}",
- new Request("http://localhost:12345/ca/v1/instance/vespa.external.provider_prod_us-north-1/vespa.external/tenant/" + INSTANCE_ID,
- new byte[0],
- Request.Method.POST));
+ new Request("http://localhost:12345/ca/v1/instance/vespa.external.provider_prod_us-north-1/vespa.external/tenant/" + INSTANCE_ID,
+ new byte[0],
+ Request.Method.POST));
// POST instance refresh where instanceId does not match CSR dnsName
var principal = new AthenzPrincipal(new AthenzService(CONTAINER_IDENTITY));
@@ -148,9 +148,9 @@ public class CertificateAuthorityApiTest extends ContainerTester {
try {
var invalidCsr = CertificateTester.createCsr(principal.getIdentity().getFullName(), List.of("node1.example.com", INVALID_INSTANCE_ID_WITH_SUFFIX));
var instanceIdentity = ztsClient.refreshInstance(new AthenzService("vespa.external", "provider_prod_us-north-1"),
- new AthenzService(CONTAINER_IDENTITY),
- INSTANCE_ID,
- invalidCsr);
+ new AthenzService(CONTAINER_IDENTITY),
+ INSTANCE_ID,
+ invalidCsr);
fail("Refresh instance should have failed");
} catch (Exception e) {
String expectedMessage = "Received error from ZTS: code=0, message=\"POST http://localhost:12345/ca/v1/instance/vespa.external.provider_prod_us-north-1/vespa.external/tenant/1.cluster1.default.app1.tenant1.us-north-1.prod.node failed: Mismatch between instance ID in URL path and instance ID in CSR [instanceId=1.cluster1.default.app1.tenant1.us-north-1.prod.node,instanceIdFromCsr=1.cluster1.default.otherapp.othertenant.us-north-1.prod.node]\"";
@@ -174,9 +174,9 @@ public class CertificateAuthorityApiTest extends ContainerTester {
assertEquals("tenant", root.field("service").asString());
assertEquals(INSTANCE_ID, root.field("instanceId").asString());
var pemEncodedCertificate = root.field("x509Certificate").asString();
- assertTrue("Response contains PEM certificate",
- pemEncodedCertificate.startsWith("-----BEGIN CERTIFICATE-----") &&
- pemEncodedCertificate.endsWith("-----END CERTIFICATE-----\n"));
+ assertTrue(pemEncodedCertificate.startsWith("-----BEGIN CERTIFICATE-----") &&
+ pemEncodedCertificate.endsWith("-----END CERTIFICATE-----\n"),
+ "Response contains PEM certificate");
}, request);
}
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/ContainerTester.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/ContainerTester.java
index ad0715cbbea..8112f5779e5 100644
--- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/ContainerTester.java
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/ContainerTester.java
@@ -5,14 +5,14 @@ import com.yahoo.application.Networking;
import com.yahoo.application.container.JDisc;
import com.yahoo.application.container.handler.Request;
import com.yahoo.vespa.hosted.ca.restapi.mock.SecretStoreMock;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import java.io.UncheckedIOException;
import java.nio.charset.CharacterCodingException;
import java.util.function.Consumer;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The superclass of REST API tests which require a functional container instance.
@@ -23,12 +23,12 @@ public class ContainerTester {
private JDisc container;
- @Before
+ @BeforeEach
public void startContainer() {
container = JDisc.fromServicesXml(servicesXml(), Networking.enable);
}
- @After
+ @AfterEach
public void stopContainer() {
container.close();
}
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/InstanceSerializerTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/InstanceSerializerTest.java
index 904ebc65f35..df75e09b957 100644
--- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/InstanceSerializerTest.java
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/restapi/InstanceSerializerTest.java
@@ -15,7 +15,7 @@ import com.yahoo.vespa.hosted.ca.CertificateTester;
import com.yahoo.vespa.hosted.ca.instance.InstanceIdentity;
import com.yahoo.vespa.hosted.ca.instance.InstanceRefresh;
import com.yahoo.vespa.hosted.ca.instance.InstanceRegistration;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -25,7 +25,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author mpolden
@@ -33,7 +33,7 @@ import static org.junit.Assert.assertEquals;
public class InstanceSerializerTest {
@Test
- public void deserialize_instance_registration() {
+ void deserialize_instance_registration() {
var csr = CertificateTester.createCsr();
var csrPem = Pkcs10CsrUtils.toPem(csr);
SignedIdentityDocument signedIdentityDocument = new SignedIdentityDocument(
@@ -49,36 +49,36 @@ public class InstanceSerializerTest {
IdentityType.NODE);
var json = String.format("{\n" +
- " \"provider\": \"provider_prod_us-north-1\",\n" +
- " \"domain\": \"vespa.external\",\n" +
- " \"service\": \"tenant\",\n" +
- " \"attestationData\":\"%s\",\n" +
- " \"csr\": \"" + csrPem + "\"\n" +
- "}", StringUtilities.escape(EntityBindingsMapper.toAttestationData(signedIdentityDocument)));
+ " \"provider\": \"provider_prod_us-north-1\",\n" +
+ " \"domain\": \"vespa.external\",\n" +
+ " \"service\": \"tenant\",\n" +
+ " \"attestationData\":\"%s\",\n" +
+ " \"csr\": \"" + csrPem + "\"\n" +
+ "}", StringUtilities.escape(EntityBindingsMapper.toAttestationData(signedIdentityDocument)));
var instanceRegistration = new InstanceRegistration("provider_prod_us-north-1", "vespa.external",
- "tenant", signedIdentityDocument,
- csr);
+ "tenant", signedIdentityDocument,
+ csr);
var deserialized = InstanceSerializer.registrationFromSlime(SlimeUtils.jsonToSlime(json));
assertEquals(instanceRegistration, deserialized);
}
@Test
- public void serialize_instance_identity() {
+ void serialize_instance_identity() {
var certificate = CertificateTester.createCertificate();
var pem = X509CertificateUtils.toPem(certificate);
var identity = new InstanceIdentity("provider_prod_us-north-1", "tenant", "node1.example.com",
- Optional.of(certificate));
+ Optional.of(certificate));
var json = "{" +
- "\"provider\":\"provider_prod_us-north-1\"," +
- "\"service\":\"tenant\"," +
- "\"instanceId\":\"node1.example.com\"," +
- "\"x509Certificate\":\"" + pem.replace("\n", "\\n") + "\"" +
- "}";
+ "\"provider\":\"provider_prod_us-north-1\"," +
+ "\"service\":\"tenant\"," +
+ "\"instanceId\":\"node1.example.com\"," +
+ "\"x509Certificate\":\"" + pem.replace("\n", "\\n") + "\"" +
+ "}";
assertEquals(json, asJsonString(InstanceSerializer.identityToSlime(identity)));
}
@Test
- public void serialize_instance_refresh() {
+ void serialize_instance_refresh() {
var csr = CertificateTester.createCsr();
var csrPem = Pkcs10CsrUtils.toPem(csr);
var json = "{\"csr\": \"" + csrPem + "\"}";
diff --git a/hosted-zone-api/pom.xml b/hosted-zone-api/pom.xml
index 87012df8479..4227d457c4d 100644
--- a/hosted-zone-api/pom.xml
+++ b/hosted-zone-api/pom.xml
@@ -25,14 +25,25 @@
<artifactId>jdisc_core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
-
- <!-- test -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- test -->
</dependencies>
<build>
<plugins>
diff --git a/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java b/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java
index 80b22a185bb..2bae9f0c9e2 100644
--- a/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java
+++ b/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java
@@ -1,12 +1,12 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.cloud;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author bratseth
@@ -14,7 +14,7 @@ import static org.junit.Assert.fail;
public class SystemInfoTest {
@Test
- public void testSystemInfo() {
+ void testSystemInfo() {
ApplicationId application = new ApplicationId("tenant1", "application1", "instance1");
Zone zone = new Zone(Environment.dev, "us-west-1");
Cloud cloud = new Cloud("aws");
@@ -30,7 +30,7 @@ public class SystemInfoTest {
}
@Test
- public void testZone() {
+ void testZone() {
Zone zone = Zone.from("dev.us-west-1");
zone = Zone.from(zone.toString());
assertEquals(Environment.dev, zone.environment());
@@ -58,7 +58,7 @@ public class SystemInfoTest {
}
@Test
- public void testCluster() {
+ void testCluster() {
int size = 1;
var indices = List.of(1);
Cluster cluster = new Cluster(size, indices);
@@ -67,7 +67,7 @@ public class SystemInfoTest {
}
@Test
- public void testNode() {
+ void testNode() {
int index = 0;
Node node = new Node(index);
assertEquals(index, node.index());
diff --git a/http-utils/pom.xml b/http-utils/pom.xml
index 5b26235b62e..6cb6cd018c8 100644
--- a/http-utils/pom.xml
+++ b/http-utils/pom.xml
@@ -50,8 +50,13 @@
<!-- test scope -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java
index cf80375611f..27819ff0117 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java
@@ -7,9 +7,9 @@ import org.apache.http.HttpRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
/**
@@ -18,17 +18,17 @@ import static org.mockito.Mockito.mock;
public class VespaHttpClientBuilderTest {
@Test
- public void route_planner_modifies_scheme_of_requests() throws HttpException {
+ void route_planner_modifies_scheme_of_requests() throws HttpException {
verifyProcessedUriMatchesExpectedOutput("http://dummyhostname:8080", "https://dummyhostname:8080");
}
@Test
- public void route_planer_handles_implicit_http_port() throws HttpException {
+ void route_planer_handles_implicit_http_port() throws HttpException {
verifyProcessedUriMatchesExpectedOutput("http://dummyhostname", "https://dummyhostname:80");
}
@Test
- public void route_planer_handles_https_port() throws HttpException {
+ void route_planer_handles_https_port() throws HttpException {
verifyProcessedUriMatchesExpectedOutput("http://dummyhostname:443", "https://dummyhostname:443");
}
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java
index bd034ab9ef2..0b83227d538 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java
@@ -2,7 +2,7 @@
package ai.vespa.util.http.hc4.retry;
import org.apache.http.client.protocol.HttpClientContext;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLException;
import java.io.IOException;
@@ -10,8 +10,8 @@ import java.net.ConnectException;
import java.time.Duration;
import java.util.Arrays;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -23,7 +23,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
@SuppressWarnings("unchecked")
@Test
- public void retry_consumers_are_invoked() {
+ void retry_consumers_are_invoked() {
RetryConsumer<IOException> retryConsumer = (RetryConsumer<IOException>) mock(RetryConsumer.class);
RetryFailedConsumer<IOException> retryFailedConsumer = (RetryFailedConsumer<IOException>) mock(RetryFailedConsumer.class);
@@ -51,7 +51,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_delay_sleeps_for_expected_duration() {
+ void retry_with_fixed_delay_sleeps_for_expected_duration() {
Sleeper sleeper = mock(Sleeper.class);
Duration delay = Duration.ofSeconds(2);
@@ -73,7 +73,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_backoff_sleeps_for_expected_durations() {
+ void retry_with_fixed_backoff_sleeps_for_expected_durations() {
Sleeper sleeper = mock(Sleeper.class);
Duration startDelay = Duration.ofMillis(500);
@@ -100,7 +100,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void retries_for_listed_exceptions_until_max_retries_exceeded() {
+ void retries_for_listed_exceptions_until_max_retries_exceeded() {
int maxRetries = 2;
DelayedConnectionLevelRetryHandler handler = DelayedConnectionLevelRetryHandler.Builder
@@ -119,7 +119,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void does_not_retry_for_non_listed_exception() {
+ void does_not_retry_for_non_listed_exception() {
DelayedConnectionLevelRetryHandler handler = DelayedConnectionLevelRetryHandler.Builder
.withFixedDelay(Duration.ofSeconds(2), 2)
.retryForExceptions(Arrays.asList(SSLException.class, ConnectException.class))
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java
index adbc445de1a..374dee63019 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java
@@ -7,15 +7,15 @@ import org.apache.http.HttpVersion;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -26,7 +26,7 @@ public class DelayedResponseLevelRetryHandlerTest {
@Test
@SuppressWarnings("unchecked")
- public void retry_consumers_are_invoked() {
+ void retry_consumers_are_invoked() {
RetryConsumer<HttpResponse> retryConsumer = mock(RetryConsumer.class);
RetryFailedConsumer<HttpResponse> retryFailedConsumer = mock(RetryFailedConsumer.class);
@@ -53,7 +53,7 @@ public class DelayedResponseLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_delay_sleeps_for_expected_duration() {
+ void retry_with_fixed_delay_sleeps_for_expected_duration() {
Duration delay = Duration.ofSeconds(2);
int maxRetries = 2;
@@ -71,7 +71,7 @@ public class DelayedResponseLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_backoff_sleeps_for_expected_durations() {
+ void retry_with_fixed_backoff_sleeps_for_expected_durations() {
Duration startDelay = Duration.ofMillis(500);
Duration maxDelay = Duration.ofSeconds(5);
int maxRetries = 10;
@@ -90,12 +90,12 @@ public class DelayedResponseLevelRetryHandlerTest {
Duration.ofSeconds(5), Duration.ofSeconds(5), Duration.ofSeconds(5));
for (int i = 1; i <= lastExecutionCount; i++) {
handler.retryRequest(response, i, ctx);
- assertEquals(expectedIntervals.get(i-1).toMillis(), handler.getRetryInterval());
+ assertEquals(expectedIntervals.get(i - 1).toMillis(), handler.getRetryInterval());
}
}
@Test
- public void retries_for_listed_exceptions_until_max_retries_exceeded() {
+ void retries_for_listed_exceptions_until_max_retries_exceeded() {
int maxRetries = 2;
DelayedResponseLevelRetryHandler handler = DelayedResponseLevelRetryHandler.Builder
@@ -113,7 +113,7 @@ public class DelayedResponseLevelRetryHandlerTest {
}
@Test
- public void does_not_retry_for_non_listed_exception() {
+ void does_not_retry_for_non_listed_exception() {
DelayedResponseLevelRetryHandler handler = DelayedResponseLevelRetryHandler.Builder
.withFixedDelay(Duration.ofSeconds(2), 2)
.retryForStatusCodes(Arrays.asList(HttpStatus.SC_SERVICE_UNAVAILABLE, HttpStatus.SC_BAD_GATEWAY))
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java
index 78c413fba56..b20d801e39c 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java
@@ -6,9 +6,9 @@ import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author jonmv
@@ -18,7 +18,7 @@ public class HttpToHttpsRoutePlannerTest {
final HttpToHttpsRoutePlanner planner = new HttpToHttpsRoutePlanner();
@Test
- public void verifySchemeMustBeHttp() throws HttpException {
+ void verifySchemeMustBeHttp() throws HttpException {
try {
planner.determineRoute(new HttpHost("https", "host", 1), new HttpClientContext());
}
@@ -28,7 +28,7 @@ public class HttpToHttpsRoutePlannerTest {
}
@Test
- public void verifyPortMustBeSet() throws HttpException {
+ void verifyPortMustBeSet() throws HttpException {
try {
planner.determineRoute(new HttpHost("http", "host", -1), new HttpClientContext());
}
@@ -39,7 +39,7 @@ public class HttpToHttpsRoutePlannerTest {
@Test
- public void verifyProxyIsDisallowed() throws HttpException {
+ void verifyProxyIsDisallowed() throws HttpException {
HttpClientContext context = new HttpClientContext();
context.setRequestConfig(RequestConfig.custom().setProxy(new HttpHost("proxy")).build());
try {
@@ -51,9 +51,9 @@ public class HttpToHttpsRoutePlannerTest {
}
@Test
- public void verifySchemeIsRewritten() throws HttpException {
+ void verifySchemeIsRewritten() throws HttpException {
assertEquals(new HttpRoute(new HttpHost("https", "host", 1)),
- planner.determineRoute(new HttpHost("http", "host", 1), new HttpClientContext()));
+ planner.determineRoute(new HttpHost("http", "host", 1), new HttpClientContext()));
}
}
diff --git a/jdisc-security-filters/pom.xml b/jdisc-security-filters/pom.xml
index dd44a114236..a452327f6ff 100644
--- a/jdisc-security-filters/pom.xml
+++ b/jdisc-security-filters/pom.xml
@@ -28,6 +28,12 @@
<artifactId>container-dev</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.yahoo.vespa</groupId>
@@ -38,11 +44,6 @@
<!-- test -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
@@ -52,17 +53,6 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>testutil</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java
index d74075831f1..752f1026f3d 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java
@@ -21,7 +21,7 @@ import com.yahoo.vespa.athenz.api.ZToken;
import com.yahoo.vespa.athenz.utils.AthenzIdentities;
import com.yahoo.vespa.athenz.zpe.AuthorizationResult;
import com.yahoo.vespa.athenz.zpe.Zpe;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
@@ -39,10 +39,10 @@ import static com.yahoo.jdisc.http.filter.security.athenz.AthenzAuthorizationFil
import static com.yahoo.security.SignatureAlgorithm.SHA256_WITH_ECDSA;
import static com.yahoo.security.SubjectAlternativeName.Type.EMAIL;
import static com.yahoo.vespa.athenz.zpe.AuthorizationResult.Type;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -72,7 +72,7 @@ public class AthenzAuthorizationFilterTest {
private static final String REJECTED_METRIC_NAME = "jdisc.http.filter.athenz.rejected_requests";
@Test
- public void accepts_request_with_access_token() {
+ void accepts_request_with_access_token() {
AthenzAuthorizationFilter filter = createFilter(new AllowingZpe(), List.of());
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -86,7 +86,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void accepts_request_with_role_certificate() {
+ void accepts_request_with_role_certificate() {
AthenzAuthorizationFilter filter = createFilter(new AllowingZpe(), List.of());
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -100,7 +100,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void accepts_request_with_role_token() {
+ void accepts_request_with_role_token() {
AthenzAuthorizationFilter filter = createFilter(new AllowingZpe(), List.of());
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -114,7 +114,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void accepts_request_with_proxied_access_token() {
+ void accepts_request_with_proxied_access_token() {
Zpe zpe = mock(Zpe.class);
when(zpe.checkAccessAllowed(any(), any(), any(), any())).thenReturn(new AuthorizationResult(Type.ALLOW, ROLE));
when(zpe.checkAccessAllowed((AthenzAccessToken) any(), any(), any())).thenReturn(new AuthorizationResult(Type.ALLOW, ROLE));
@@ -135,7 +135,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void accepts_request_with_access_token_and_matching_identity_certificate_with_proxy_support_enabled() {
+ void accepts_request_with_access_token_and_matching_identity_certificate_with_proxy_support_enabled() {
Zpe zpe = mock(Zpe.class);
when(zpe.checkAccessAllowed(any(), any(), any(), any())).thenReturn(new AuthorizationResult(Type.ALLOW, ROLE));
when(zpe.checkAccessAllowed((AthenzAccessToken) any(), any(), any())).thenReturn(new AuthorizationResult(Type.ALLOW, ROLE));
@@ -156,7 +156,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void returns_forbidden_when_identity_certificate_has_unknown_proxy_identity() {
+ void returns_forbidden_when_identity_certificate_has_unknown_proxy_identity() {
Zpe zpe = mock(Zpe.class);
when(zpe.checkAccessAllowed(any(), any(), any(), any())).thenReturn(new AuthorizationResult(Type.DENY, ROLE));
when(zpe.checkAccessAllowed((AthenzAccessToken) any(), any(), any())).thenReturn(new AuthorizationResult(Type.DENY, ROLE));
@@ -174,7 +174,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void returns_unauthorized_for_request_with_disabled_credential_type() {
+ void returns_unauthorized_for_request_with_disabled_credential_type() {
AthenzAuthorizationFilter filter =
createFilter(new AllowingZpe(), List.of(EnabledCredentials.ROLE_CERTIFICATE, EnabledCredentials.ACCESS_TOKEN));
@@ -188,7 +188,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void returns_forbidden_for_credentials_rejected_by_zpe() {
+ void returns_forbidden_for_credentials_rejected_by_zpe() {
AthenzAuthorizationFilter filter = createFilter(new DenyingZpe(), List.of());
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -200,7 +200,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void reports_metrics_for_rejected_requests() {
+ void reports_metrics_for_rejected_requests() {
MetricMock metric = new MetricMock();
AthenzAuthorizationFilter filter = createFilter(new DenyingZpe(), List.of(), metric, null);
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -211,7 +211,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void reports_metrics_for_accepted_requests() {
+ void reports_metrics_for_accepted_requests() {
MetricMock metric = new MetricMock();
AthenzAuthorizationFilter filter = createFilter(new AllowingZpe(), List.of(EnabledCredentials.ACCESS_TOKEN), metric, null);
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -222,7 +222,7 @@ public class AthenzAuthorizationFilterTest {
}
@Test
- public void ignores_access_token_if_client_has_role_certificate() {
+ void ignores_access_token_if_client_has_role_certificate() {
AthenzAuthorizationFilter filter = createFilter(new AllowingZpe(), List.of());
MockResponseHandler responseHandler = new MockResponseHandler();
@@ -238,7 +238,7 @@ public class AthenzAuthorizationFilterTest {
private void assertMetrics(MetricMock metric, String metricName, Map<String, String> dimensions) {
assertTrue(metric.addInvocations.keySet().contains(metricName));
SimpleMetricContext metricContext = metric.addInvocations.get(metricName);
- assertNotNull("Metric not found " + metricName, metricName);
+ assertNotNull(metricName, "Metric not found " + metricName);
for (Map.Entry<String, String> entry : dimensions.entrySet()) {
String dimensionName = entry.getKey();
String expected = entry.getValue();
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java
index d670c969e5c..0b04993a723 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java
@@ -12,7 +12,7 @@ import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.vespa.athenz.api.AthenzIdentity;
import com.yahoo.vespa.athenz.api.AthenzPrincipal;
import com.yahoo.vespa.athenz.api.AthenzUser;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.io.BufferedReader;
@@ -31,10 +31,10 @@ import static com.yahoo.security.SignatureAlgorithm.SHA256_WITH_ECDSA;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.joining;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -48,7 +48,7 @@ public class AthenzPrincipalFilterTest {
private static final X509Certificate CERTIFICATE = createSelfSignedCertificate(IDENTITY);
@Test
- public void missing_certificate_is_unauthorized() {
+ void missing_certificate_is_unauthorized() {
DiscFilterRequest request = createRequestMock();
when(request.getClientCertificateChain()).thenReturn(emptyList());
@@ -61,7 +61,7 @@ public class AthenzPrincipalFilterTest {
}
@Test
- public void certificate_is_accepted() {
+ void certificate_is_accepted() {
DiscFilterRequest request = createRequestMock();
when(request.getClientCertificateChain()).thenReturn(singletonList(CERTIFICATE));
@@ -81,7 +81,7 @@ public class AthenzPrincipalFilterTest {
@Test
- public void no_response_produced_when_passthrough_mode_is_enabled() {
+ void no_response_produced_when_passthrough_mode_is_enabled() {
DiscFilterRequest request = createRequestMock();
when(request.getClientCertificateChain()).thenReturn(emptyList());
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java
index 0f5512a6ec5..34db051aa28 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java
@@ -6,13 +6,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.container.jdisc.RequestHandlerTestDriver;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.http.filter.DiscFilterRequest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
/**
@@ -23,7 +23,7 @@ public class JsonSecurityRequestFilterBaseTest {
private final ObjectMapper mapper = new ObjectMapper();
@Test
- public void filter_renders_errors_as_json() throws IOException {
+ void filter_renders_errors_as_json() throws IOException {
int statusCode = 403;
String message = "Forbidden";
DiscFilterRequest request = mock(DiscFilterRequest.class);
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsPreflightRequestFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsPreflightRequestFilterTest.java
index ead816afdfd..b5b94d5a2c2 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsPreflightRequestFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsPreflightRequestFilterTest.java
@@ -8,16 +8,16 @@ import com.yahoo.jdisc.handler.ResponseHandler;
import com.yahoo.jdisc.http.filter.DiscFilterRequest;
import com.yahoo.jdisc.http.filter.SecurityRequestFilter;
import com.yahoo.jdisc.http.filter.security.cors.CorsFilterConfig.Builder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static com.yahoo.jdisc.http.HttpRequest.Method.OPTIONS;
import static com.yahoo.jdisc.http.filter.security.cors.CorsLogic.ACCESS_CONTROL_HEADERS;
import static com.yahoo.jdisc.http.filter.security.cors.CorsLogic.ALLOW_ORIGIN_HEADER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,28 +29,28 @@ import static org.mockito.Mockito.when;
public class CorsPreflightRequestFilterTest {
@Test
- public void any_options_request_yields_access_control_headers_in_response() {
+ void any_options_request_yields_access_control_headers_in_response() {
HeaderFields headers = doFilterRequest(newRequestFilter(), "http://any.origin");
ACCESS_CONTROL_HEADERS.keySet().forEach(
- header -> assertFalse("Empty header: " + header, headers.getFirst(header).isEmpty()));
+ header -> assertFalse(headers.getFirst(header).isEmpty(), "Empty header: " + header));
}
@Test
- public void allowed_request_origin_yields_allow_origin_header_in_response() {
+ void allowed_request_origin_yields_allow_origin_header_in_response() {
final String ALLOWED_ORIGIN = "http://allowed.origin";
HeaderFields headers = doFilterRequest(newRequestFilter(ALLOWED_ORIGIN), ALLOWED_ORIGIN);
assertEquals(ALLOWED_ORIGIN, headers.getFirst(ALLOW_ORIGIN_HEADER));
}
@Test
- public void allowed_wildcard_origin_yields_origin_header_in_response() {
+ void allowed_wildcard_origin_yields_origin_header_in_response() {
final String ALLOWED_ORIGIN = "http://allowed.origin";
HeaderFields headers = doFilterRequest(newRequestFilter("*"), ALLOWED_ORIGIN);
assertEquals(ALLOWED_ORIGIN, headers.getFirst(ALLOW_ORIGIN_HEADER));
}
@Test
- public void disallowed_request_origin_does_not_yield_allow_origin_header_in_response() {
+ void disallowed_request_origin_does_not_yield_allow_origin_header_in_response() {
HeaderFields headers = doFilterRequest(newRequestFilter("http://allowed.origin"), "http://disallowed.origin");
assertNull(headers.getFirst(ALLOW_ORIGIN_HEADER));
}
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsResponseFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsResponseFilterTest.java
index e3a3568700c..7762fde1a72 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsResponseFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/cors/CorsResponseFilterTest.java
@@ -6,7 +6,7 @@ import com.yahoo.jdisc.http.filter.DiscFilterResponse;
import com.yahoo.jdisc.http.filter.RequestView;
import com.yahoo.jdisc.http.filter.SecurityResponseFilter;
import com.yahoo.jdisc.http.filter.security.cors.CorsFilterConfig.Builder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@@ -16,9 +16,9 @@ import java.util.Optional;
import static com.yahoo.jdisc.http.filter.security.cors.CorsLogic.ACCESS_CONTROL_HEADERS;
import static com.yahoo.jdisc.http.filter.security.cors.CorsLogic.ALLOW_ORIGIN_HEADER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,27 +29,27 @@ import static org.mockito.Mockito.when;
public class CorsResponseFilterTest {
@Test
- public void any_request_yields_access_control_headers_in_response() {
+ void any_request_yields_access_control_headers_in_response() {
Map<String, String> headers = doFilterRequest(newResponseFilter(), "http://any.origin");
ACCESS_CONTROL_HEADERS.keySet().forEach(
- header -> assertFalse("Empty header: " + header, headers.get(header).isEmpty()));
+ header -> assertFalse(headers.get(header).isEmpty(), "Empty header: " + header));
}
@Test
- public void allowed_request_origin_yields_allow_origin_header_in_response() {
+ void allowed_request_origin_yields_allow_origin_header_in_response() {
final String ALLOWED_ORIGIN = "http://allowed.origin";
Map<String, String> headers = doFilterRequest(newResponseFilter(ALLOWED_ORIGIN), ALLOWED_ORIGIN);
assertEquals(ALLOWED_ORIGIN, headers.get(ALLOW_ORIGIN_HEADER));
}
@Test
- public void disallowed_request_origin_does_not_yield_allow_origin_header_in_response() {
+ void disallowed_request_origin_does_not_yield_allow_origin_header_in_response() {
Map<String, String> headers = doFilterRequest(newResponseFilter("http://allowed.origin"), "http://disallowed.origin");
assertNull(headers.get(ALLOW_ORIGIN_HEADER));
}
@Test
- public void any_request_origin_yields_allow_origin_header_in_response_when_wildcard_is_allowed() {
+ void any_request_origin_yields_allow_origin_header_in_response_when_wildcard_is_allowed() {
Map<String, String> headers = doFilterRequest(newResponseFilter("*"), "http://any.origin");
assertEquals("http://any.origin", headers.get(ALLOW_ORIGIN_HEADER));
}
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/LocalhostFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/LocalhostFilterTest.java
index 676c3e23ad7..aaf6ebf1aee 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/LocalhostFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/LocalhostFilterTest.java
@@ -4,13 +4,13 @@ package com.yahoo.jdisc.http.filter.security.misc;
import com.yahoo.container.jdisc.RequestHandlerTestDriver;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.http.filter.DiscFilterRequest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.net.URI;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
/**
@@ -20,7 +20,7 @@ import static org.mockito.Mockito.when;
public class LocalhostFilterTest {
@Test
- public void filter() {
+ void filter() {
// Reject from non-loopback
assertUnauthorized(createRequest("1.2.3.4", null));
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/VespaTlsFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/VespaTlsFilterTest.java
index d1d74d30572..95bc1f92572 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/VespaTlsFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/misc/VespaTlsFilterTest.java
@@ -9,7 +9,7 @@ import com.yahoo.security.KeyAlgorithm;
import com.yahoo.security.KeyUtils;
import com.yahoo.security.SignatureAlgorithm;
import com.yahoo.security.X509CertificateBuilder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javax.security.auth.x500.X500Principal;
@@ -21,14 +21,14 @@ import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
public class VespaTlsFilterTest {
@Test
- public void testFilter() {
+ void testFilter() {
assertSuccess(createRequest(List.of(createCertificate())));
assertForbidden(createRequest(Collections.emptyList()));
}
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/rule/RuleBasedRequestFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/rule/RuleBasedRequestFilterTest.java
index bb3408f0089..4ad593efe82 100644
--- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/rule/RuleBasedRequestFilterTest.java
+++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/rule/RuleBasedRequestFilterTest.java
@@ -11,7 +11,6 @@ import com.yahoo.jdisc.http.filter.DiscFilterRequest;
import com.yahoo.vespa.config.jdisc.http.filter.RuleBasedFilterConfig;
import com.yahoo.vespa.config.jdisc.http.filter.RuleBasedFilterConfig.DefaultRule;
import com.yahoo.vespa.config.jdisc.http.filter.RuleBasedFilterConfig.Rule;
-import com.yahoo.test.json.JsonTestHelper;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -238,7 +237,7 @@ class RuleBasedRequestFilterTest {
ObjectNode expectedJson = jsonMapper.createObjectNode();
expectedJson.put("message", expectedMessage).put("code", expectedCode);
JsonNode actualJson = jsonMapper.readTree(handler.readAll().getBytes());
- JsonTestHelper.assertJsonEquals(expectedJson, actualJson);
+ assertEquals(expectedJson, actualJson);
}
} \ No newline at end of file
diff --git a/parent/pom.xml b/parent/pom.xml
index 05060c57ec9..5c0b4d5c570 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -301,6 +301,27 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <!--
+ Configure rewrite-maven-plugin to facilitate Junit4 to Junit5 conversion.
+ Run "mvn rewrite:run" to perform automated rewrite to Junit5.
+ -->
+ <groupId>org.openrewrite.maven</groupId>
+ <artifactId>rewrite-maven-plugin</artifactId>
+ <version>4.27.0</version>
+ <configuration>
+ <activeRecipes>
+ <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
+ </activeRecipes>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.openrewrite.recipe</groupId>
+ <artifactId>rewrite-testing-frameworks</artifactId>
+ <version>1.24.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</pluginManagement>
</build>
@@ -422,7 +443,6 @@
</profiles>
<dependencyManagement>
<dependencies>
-
<!-- Please keep this list lexically sorted by groupId, then artifactId.-->
<dependency>
@@ -919,6 +939,15 @@
<scope>test</scope> <!-- TODO: remove scope from parent pom -->
</dependency>
<dependency>
+ <!-- Facilitates automated Junit4 to Junit5 conversion.
+ See pluginManagement of rewrite-maven-plugin for more details -->
+ <groupId>org.openrewrite.recipe</groupId>
+ <artifactId>rewrite-recipe-bom</artifactId>
+ <version>1.5.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
diff --git a/security-tools/pom.xml b/security-tools/pom.xml
index 7f248c185a2..2af6e09a84d 100644
--- a/security-tools/pom.xml
+++ b/security-tools/pom.xml
@@ -27,13 +27,18 @@
<!-- test scope -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/security-tools/src/test/java/com/yahoo/vespa/security/tool/securityenv/MainTest.java b/security-tools/src/test/java/com/yahoo/vespa/security/tool/securityenv/MainTest.java
index 4b8f4bf0156..b1d263a1a82 100644
--- a/security-tools/src/test/java/com/yahoo/vespa/security/tool/securityenv/MainTest.java
+++ b/security-tools/src/test/java/com/yahoo/vespa/security/tool/securityenv/MainTest.java
@@ -4,11 +4,11 @@ package com.yahoo.vespa.security.tool.securityenv;
import com.yahoo.security.tls.MixedMode;
import com.yahoo.security.tls.TransportSecurityOptions;
import com.yahoo.security.tls.TransportSecurityUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
@@ -30,18 +30,18 @@ public class MainTest {
private final PrintStream stdOut = new PrintStream(stdOutBytes);
private final PrintStream stdError = new PrintStream(stdErrBytes);
- @Rule
- public TemporaryFolder tmpFolder = new TemporaryFolder();
+ @TempDir
+ public File tmpFolder;
@Test
- public void prints_help_page_on_help_option() throws IOException {
+ void prints_help_page_on_help_option() throws IOException {
int exitCode = runMain(List.of("--help"), Map.of());
assertThat(exitCode).isEqualTo(0);
assertThat(stdOut()).isEqualTo(readTestResource("expected-help-output.txt"));
}
@Test
- public void unsets_all_variables_when_no_security_config() throws IOException {
+ void unsets_all_variables_when_no_security_config() throws IOException {
int exitCode = runMain(List.of(), Map.of());
assertThat(exitCode).isEqualTo(0);
assertThat(stdErr()).isEmpty();
@@ -49,7 +49,7 @@ public class MainTest {
}
@Test
- public void prints_security_variables_with_specified_shell() throws IOException {
+ void prints_security_variables_with_specified_shell() throws IOException {
Path configFile = generateConfigFile();
Map<String, String> env = Map.of(TransportSecurityUtils.CONFIG_FILE_ENVIRONMENT_VARIABLE, configFile.toString());
int exitCode = runMain(List.of(), env);
@@ -58,7 +58,7 @@ public class MainTest {
}
@Test
- public void prints_security_variables_with_auto_detected_shell() throws IOException {
+ void prints_security_variables_with_auto_detected_shell() throws IOException {
Path configFile = generateConfigFile();
Map<String, String> env = Map.of(
TransportSecurityUtils.CONFIG_FILE_ENVIRONMENT_VARIABLE, configFile.toString(),
@@ -71,14 +71,14 @@ public class MainTest {
@Test
- public void prints_error_message_on_unknown_shell_name() {
+ void prints_error_message_on_unknown_shell_name() {
int exitCode = runMain(List.of("--shell", "invalid-shell-name"), Map.of());
assertThat(exitCode).isEqualTo(1);
assertThat(stdErr()).isEqualTo("Invalid command line arguments: Unknown shell: invalid-shell-name\n");
}
@Test
- public void prints_error_message_on_unknown_command_line_parameter() {
+ void prints_error_message_on_unknown_command_line_parameter() {
int exitCode = runMain(List.of("--unknown-parameter"), Map.of());
assertThat(exitCode).isEqualTo(1);
assertThat(stdErr()).isEqualTo("Failed to parse command line arguments: Unrecognized option: --unknown-parameter\n");
@@ -108,7 +108,7 @@ public class MainTest {
.withCaCertificates(Paths.get("/path/to/cacerts"))
.withHostnameValidationDisabled(true)
.build();
- Path configFile = tmpFolder.newFile().toPath();
+ Path configFile = File.createTempFile("junit", null, tmpFolder).toPath();
options.toJsonFile(configFile);
return configFile;
}
diff --git a/security-utils/pom.xml b/security-utils/pom.xml
index 0a2e1251d6a..71920327fbb 100644
--- a/security-utils/pom.xml
+++ b/security-utils/pom.xml
@@ -35,17 +35,6 @@
<!-- test scope -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>testutil</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
@@ -60,11 +49,6 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
<plugins>
diff --git a/security-utils/src/test/java/com/yahoo/security/AutoReloadingX509KeyManagerTest.java b/security-utils/src/test/java/com/yahoo/security/AutoReloadingX509KeyManagerTest.java
index 5bde63598c0..c335acc12be 100644
--- a/security-utils/src/test/java/com/yahoo/security/AutoReloadingX509KeyManagerTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/AutoReloadingX509KeyManagerTest.java
@@ -7,13 +7,14 @@ import com.yahoo.security.KeyUtils;
import com.yahoo.security.SignatureAlgorithm;
import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.security.X509CertificateUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import javax.security.auth.x500.X500Principal;
+
+import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
@@ -36,16 +37,16 @@ import static org.mockito.Mockito.verify;
public class AutoReloadingX509KeyManagerTest {
private static final X500Principal SUBJECT = new X500Principal("CN=dummy");
- @Rule
- public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
@Test
- public void crypto_material_is_reloaded_when_scheduler_task_is_executed() throws IOException {
+ void crypto_material_is_reloaded_when_scheduler_task_is_executed() throws IOException {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC);
- Path privateKeyFile = tempDirectory.newFile().toPath();
+ Path privateKeyFile = File.createTempFile("junit", null, tempDirectory).toPath();
Files.write(privateKeyFile, KeyUtils.toPem(keyPair.getPrivate()).getBytes());
- Path certificateFile = tempDirectory.newFile().toPath();
+ Path certificateFile = File.createTempFile("junit", null, tempDirectory).toPath();
BigInteger serialNumberInitialCertificate = BigInteger.ONE;
X509Certificate initialCertificate = generateCertificate(keyPair, serialNumberInitialCertificate);
Files.write(certificateFile, X509CertificateUtils.toPem(initialCertificate).getBytes());
diff --git a/security-utils/src/test/java/com/yahoo/security/KeyStoreBuilderTest.java b/security-utils/src/test/java/com/yahoo/security/KeyStoreBuilderTest.java
index 0d3924063f3..d9ca9731065 100644
--- a/security-utils/src/test/java/com/yahoo/security/KeyStoreBuilderTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/KeyStoreBuilderTest.java
@@ -1,10 +1,10 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import java.io.File;
import java.nio.file.Path;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
@@ -20,11 +20,11 @@ public class KeyStoreBuilderTest {
private static final char[] PASSWORD = new char[0];
- @Rule
- public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
@Test
- public void can_create_jks_keystore_from_privatekey_and_certificate() throws Exception {
+ void can_create_jks_keystore_from_privatekey_and_certificate() throws Exception {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X509Certificate certificate = createCertificate(keyPair);
KeyStoreBuilder.withType(KeyStoreType.JKS)
@@ -33,8 +33,8 @@ public class KeyStoreBuilderTest {
}
@Test
- public void can_build_jks_keystore_from_file() throws Exception {
- Path keystoreFile = tempDirectory.newFile().toPath();
+ void can_build_jks_keystore_from_file() throws Exception {
+ Path keystoreFile = File.createTempFile("junit", null, tempDirectory).toPath();
createKeystoreFile(keystoreFile, KeyStoreType.JKS, PASSWORD);
KeyStoreBuilder.withType(KeyStoreType.JKS)
@@ -43,8 +43,8 @@ public class KeyStoreBuilderTest {
}
@Test
- public void can_build_pcks12_keystore_from_file() throws Exception {
- Path keystoreFile = tempDirectory.newFile().toPath();
+ void can_build_pcks12_keystore_from_file() throws Exception {
+ Path keystoreFile = File.createTempFile("junit", null, tempDirectory).toPath();
createKeystoreFile(keystoreFile, KeyStoreType.PKCS12, PASSWORD);
KeyStoreBuilder.withType(KeyStoreType.PKCS12)
diff --git a/security-utils/src/test/java/com/yahoo/security/KeyUtilsTest.java b/security-utils/src/test/java/com/yahoo/security/KeyUtilsTest.java
index f6f48d8b1b8..afaa25ce606 100644
--- a/security-utils/src/test/java/com/yahoo/security/KeyUtilsTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/KeyUtilsTest.java
@@ -1,15 +1,15 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -17,41 +17,41 @@ import static org.junit.Assert.assertTrue;
public class KeyUtilsTest {
@Test
- public void can_extract_public_key_from_rsa_private() {
+ void can_extract_public_key_from_rsa_private() {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
PublicKey publicKey = KeyUtils.extractPublicKey(keyPair.getPrivate());
assertNotNull(publicKey);
}
@Test
- public void can_extract_public_key_from_ecdsa_private() {
+ void can_extract_public_key_from_ecdsa_private() {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC);
PublicKey publicKey = KeyUtils.extractPublicKey(keyPair.getPrivate());
assertNotNull(publicKey);
}
@Test
- public void can_serialize_and_deserialize_rsa_privatekey_using_pkcs1_pem_format() {
+ void can_serialize_and_deserialize_rsa_privatekey_using_pkcs1_pem_format() {
testPrivateKeySerialization(KeyAlgorithm.RSA, KeyFormat.PKCS1, "RSA PRIVATE KEY");
}
@Test
- public void can_serialize_and_deserialize_rsa_privatekey_using_pkcs8_pem_format() {
+ void can_serialize_and_deserialize_rsa_privatekey_using_pkcs8_pem_format() {
testPrivateKeySerialization(KeyAlgorithm.RSA, KeyFormat.PKCS8, "PRIVATE KEY");
}
@Test
- public void can_serialize_and_deserialize_ec_privatekey_using_pkcs1_pem_format() {
+ void can_serialize_and_deserialize_ec_privatekey_using_pkcs1_pem_format() {
testPrivateKeySerialization(KeyAlgorithm.EC, KeyFormat.PKCS1, "EC PRIVATE KEY");
}
@Test
- public void can_serialize_and_deserialize_ec_privatekey_using_pkcs8_pem_format() {
+ void can_serialize_and_deserialize_ec_privatekey_using_pkcs8_pem_format() {
testPrivateKeySerialization(KeyAlgorithm.EC, KeyFormat.PKCS8, "PRIVATE KEY");
}
@Test
- public void can_serialize_and_deserialize_rsa_publickey_using_pem_format() {
+ void can_serialize_and_deserialize_rsa_publickey_using_pem_format() {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
String pem = KeyUtils.toPem(keyPair.getPublic());
assertTrue(pem.contains("BEGIN PUBLIC KEY"));
@@ -62,7 +62,7 @@ public class KeyUtilsTest {
}
@Test
- public void can_serialize_and_deserialize_ec_publickey_using_pem_format() {
+ void can_serialize_and_deserialize_ec_publickey_using_pem_format() {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC);
String pem = KeyUtils.toPem(keyPair.getPublic());
assertTrue(pem.contains("BEGIN PUBLIC KEY"));
diff --git a/security-utils/src/test/java/com/yahoo/security/MutableX509KeyManagerTest.java b/security-utils/src/test/java/com/yahoo/security/MutableX509KeyManagerTest.java
index 871b0937f18..ddceb762d2a 100644
--- a/security-utils/src/test/java/com/yahoo/security/MutableX509KeyManagerTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/MutableX509KeyManagerTest.java
@@ -8,7 +8,7 @@ import com.yahoo.security.KeyUtils;
import com.yahoo.security.MutableX509KeyManager;
import com.yahoo.security.SignatureAlgorithm;
import com.yahoo.security.X509CertificateBuilder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
@@ -29,7 +29,7 @@ public class MutableX509KeyManagerTest {
private static final X500Principal SUBJECT = new X500Principal("CN=dummy");
@Test
- public void key_manager_can_be_updated_with_new_certificate() {
+ void key_manager_can_be_updated_with_new_certificate() {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC);
BigInteger serialNumberInitialCertificate = BigInteger.ONE;
diff --git a/security-utils/src/test/java/com/yahoo/security/MutableX509TrustManagerTest.java b/security-utils/src/test/java/com/yahoo/security/MutableX509TrustManagerTest.java
index 489aa7eb4da..ea9f9a4a68a 100644
--- a/security-utils/src/test/java/com/yahoo/security/MutableX509TrustManagerTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/MutableX509TrustManagerTest.java
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class MutableX509TrustManagerTest {
@Test
- public void key_manager_can_be_updated_with_new_certificate() {
+ void key_manager_can_be_updated_with_new_certificate() {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC);
X509Certificate initialCertificate = generateCertificate(new X500Principal("CN=issuer1"), keyPair);
diff --git a/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrBuilderTest.java b/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrBuilderTest.java
index 5ad49bbc599..ca8fb280ec7 100644
--- a/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrBuilderTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrBuilderTest.java
@@ -1,12 +1,12 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.security.KeyPair;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
@@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals;
public class Pkcs10CsrBuilderTest {
@Test
- public void can_build_csr_with_sans() {
+ void can_build_csr_with_sans() {
X500Principal subject = new X500Principal("CN=subject");
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
Pkcs10Csr csr = Pkcs10CsrBuilder.fromKeypair(subject, keypair, SignatureAlgorithm.SHA512_WITH_ECDSA)
diff --git a/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrTest.java b/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrTest.java
index d03c52027bf..3fe36dc6a7c 100644
--- a/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrTest.java
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.security.KeyPair;
@@ -9,8 +9,8 @@ import java.util.Arrays;
import java.util.List;
import static com.yahoo.security.SubjectAlternativeName.Type.DNS;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -18,7 +18,7 @@ import static org.junit.Assert.assertTrue;
public class Pkcs10CsrTest {
@Test
- public void can_read_subject_alternative_names() {
+ void can_read_subject_alternative_names() {
X500Principal subject = new X500Principal("CN=subject");
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
SubjectAlternativeName san1 = new SubjectAlternativeName(DNS, "san1.com");
@@ -31,7 +31,7 @@ public class Pkcs10CsrTest {
}
@Test
- public void can_read_basic_constraints() {
+ void can_read_basic_constraints() {
X500Principal subject = new X500Principal("CN=subject");
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
Pkcs10Csr csr = Pkcs10CsrBuilder.fromKeypair(subject, keypair, SignatureAlgorithm.SHA512_WITH_ECDSA)
@@ -42,7 +42,7 @@ public class Pkcs10CsrTest {
}
@Test
- public void can_read_extensions() {
+ void can_read_extensions() {
X500Principal subject = new X500Principal("CN=subject");
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
Pkcs10Csr csr = Pkcs10CsrBuilder.fromKeypair(subject, keypair, SignatureAlgorithm.SHA512_WITH_ECDSA)
diff --git a/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrUtilsTest.java b/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrUtilsTest.java
index 32b8dfc5bcd..48ff3e9a6fd 100644
--- a/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrUtilsTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/Pkcs10CsrUtilsTest.java
@@ -1,13 +1,13 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.security.KeyPair;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -15,7 +15,7 @@ import static org.junit.Assert.assertTrue;
public class Pkcs10CsrUtilsTest {
@Test
- public void can_deserialize_serialized_pem_csr() {
+ void can_deserialize_serialized_pem_csr() {
X500Principal subject = new X500Principal("CN=subject");
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
Pkcs10Csr csr = Pkcs10CsrBuilder.fromKeypair(subject, keypair, SignatureAlgorithm.SHA512_WITH_ECDSA).build();
diff --git a/security-utils/src/test/java/com/yahoo/security/SslContextBuilderTest.java b/security-utils/src/test/java/com/yahoo/security/SslContextBuilderTest.java
index 3c40cb89e6c..b08494bb8da 100644
--- a/security-utils/src/test/java/com/yahoo/security/SslContextBuilderTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/SslContextBuilderTest.java
@@ -1,10 +1,10 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import java.io.File;
import java.nio.file.Path;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
@@ -20,25 +20,25 @@ public class SslContextBuilderTest {
private static final char[] PASSWORD = new char[0];
- @Rule
- public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
@Test
- public void can_build_sslcontext_with_truststore_only() throws Exception {
+ void can_build_sslcontext_with_truststore_only() throws Exception {
new SslContextBuilder()
.withTrustStore(createKeystore(KeyStoreType.JKS, PASSWORD))
.build();
}
@Test
- public void can_build_sslcontext_with_keystore_only() throws Exception {
+ void can_build_sslcontext_with_keystore_only() throws Exception {
new SslContextBuilder()
.withKeyStore(createKeystore(KeyStoreType.JKS, PASSWORD), PASSWORD)
.build();
}
@Test
- public void can_build_sslcontext_with_truststore_and_keystore() throws Exception {
+ void can_build_sslcontext_with_truststore_and_keystore() throws Exception {
new SslContextBuilder()
.withKeyStore(createKeystore(KeyStoreType.JKS, PASSWORD), PASSWORD)
.withTrustStore(createKeystore(KeyStoreType.JKS, PASSWORD))
@@ -46,7 +46,7 @@ public class SslContextBuilderTest {
}
@Test
- public void can_build_sslcontext_with_keystore_from_private_key_and_certificate() throws Exception {
+ void can_build_sslcontext_with_keystore_from_private_key_and_certificate() throws Exception {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X509Certificate certificate = createCertificate(keyPair);
new SslContextBuilder()
@@ -55,8 +55,8 @@ public class SslContextBuilderTest {
}
@Test
- public void can_build_sslcontext_with_jks_keystore_from_file() throws Exception {
- Path keystoreFile = tempDirectory.newFile().toPath();
+ void can_build_sslcontext_with_jks_keystore_from_file() throws Exception {
+ Path keystoreFile = File.createTempFile("junit", null, tempDirectory).toPath();
createKeystoreFile(keystoreFile, KeyStoreType.JKS, PASSWORD);
new SslContextBuilder()
@@ -65,8 +65,8 @@ public class SslContextBuilderTest {
}
@Test
- public void can_build_sslcontext_with_pcks12_keystore_from_file() throws Exception {
- Path keystoreFile = tempDirectory.newFile().toPath();
+ void can_build_sslcontext_with_pcks12_keystore_from_file() throws Exception {
+ Path keystoreFile = File.createTempFile("junit", null, tempDirectory).toPath();
createKeystoreFile(keystoreFile, KeyStoreType.PKCS12, PASSWORD);
new SslContextBuilder()
diff --git a/security-utils/src/test/java/com/yahoo/security/X509CertificateBuilderTest.java b/security-utils/src/test/java/com/yahoo/security/X509CertificateBuilderTest.java
index eb6fe4286d8..1a9c4999146 100644
--- a/security-utils/src/test/java/com/yahoo/security/X509CertificateBuilderTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/X509CertificateBuilderTest.java
@@ -1,9 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
@@ -14,35 +13,35 @@ import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collection;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
*/
-@RunWith(Parameterized.class)
public class X509CertificateBuilderTest {
- @Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
+ return Arrays.asList(new Object[][]{
{KeyAlgorithm.RSA, 2048, SignatureAlgorithm.SHA512_WITH_RSA},
{KeyAlgorithm.EC, 256, SignatureAlgorithm.SHA512_WITH_ECDSA}});
}
- private final KeyAlgorithm keyAlgorithm;
- private final int keySize;
- private final SignatureAlgorithm signatureAlgorithm;
+ private KeyAlgorithm keyAlgorithm;
+ private int keySize;
+ private SignatureAlgorithm signatureAlgorithm;
- public X509CertificateBuilderTest(KeyAlgorithm keyAlgorithm,
- int keySize,
- SignatureAlgorithm signatureAlgorithm) {
+ public void initX509CertificateBuilderTest(KeyAlgorithm keyAlgorithm,
+ int keySize,
+ SignatureAlgorithm signatureAlgorithm) {
this.keyAlgorithm = keyAlgorithm;
this.keySize = keySize;
this.signatureAlgorithm = signatureAlgorithm;
}
- @Test
- public void can_build_self_signed_certificate() {
+ @MethodSource("data")
+ @ParameterizedTest(name = "{0}")
+ void can_build_self_signed_certificate(KeyAlgorithm keyAlgorithm, int keySize, SignatureAlgorithm signatureAlgorithm) {
+ initX509CertificateBuilderTest(keyAlgorithm, keySize, signatureAlgorithm);
KeyPair keyPair = KeyUtils.generateKeypair(keyAlgorithm, keySize);
X500Principal subject = new X500Principal("CN=myservice");
X509Certificate cert =
@@ -53,13 +52,15 @@ public class X509CertificateBuilderTest {
Instant.now().plus(1, ChronoUnit.DAYS),
signatureAlgorithm,
BigInteger.valueOf(1))
- .setBasicConstraints(true, true)
- .build();
+ .setBasicConstraints(true, true)
+ .build();
assertEquals(subject, cert.getSubjectX500Principal());
}
- @Test
- public void can_build_certificate_from_csr() {
+ @MethodSource("data")
+ @ParameterizedTest(name = "{0}")
+ void can_build_certificate_from_csr(KeyAlgorithm keyAlgorithm, int keySize, SignatureAlgorithm signatureAlgorithm) {
+ initX509CertificateBuilderTest(keyAlgorithm, keySize, signatureAlgorithm);
X500Principal subject = new X500Principal("CN=subject");
X500Principal issuer = new X500Principal("CN=issuer");
KeyPair csrKeypair = KeyUtils.generateKeypair(keyAlgorithm, keySize);
diff --git a/security-utils/src/test/java/com/yahoo/security/X509CertificateUtilsTest.java b/security-utils/src/test/java/com/yahoo/security/X509CertificateUtilsTest.java
index 6bb87554de3..c0560627661 100644
--- a/security-utils/src/test/java/com/yahoo/security/X509CertificateUtilsTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/X509CertificateUtilsTest.java
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
@@ -14,16 +14,16 @@ import java.util.List;
import static com.yahoo.security.SubjectAlternativeName.Type.DNS;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
*/
public class X509CertificateUtilsTest {
@Test
- public void can_deserialize_serialized_pem_certificate() {
+ void can_deserialize_serialized_pem_certificate() {
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X500Principal subject = new X500Principal("CN=myservice");
X509Certificate cert = TestUtils.createCertificate(keypair, subject);
@@ -36,7 +36,7 @@ public class X509CertificateUtilsTest {
}
@Test
- public void can_deserialize_serialized_pem_certificate_list() {
+ void can_deserialize_serialized_pem_certificate_list() {
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X500Principal subject1 = new X500Principal("CN=myservice1");
X509Certificate cert1 = TestUtils.createCertificate(keypair, subject1);
@@ -51,7 +51,7 @@ public class X509CertificateUtilsTest {
}
@Test
- public void can_list_subject_alternative_names() {
+ void can_list_subject_alternative_names() {
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X500Principal subject = new X500Principal("CN=myservice");
SubjectAlternativeName san = new SubjectAlternativeName(DNS, "dns-san");
@@ -72,7 +72,7 @@ public class X509CertificateUtilsTest {
}
@Test
- public void verifies_matching_cert_and_key() {
+ void verifies_matching_cert_and_key() {
KeyPair ecKeypairA = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
KeyPair ecKeypairB = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
KeyPair rsaKeypairA = KeyUtils.generateKeypair(KeyAlgorithm.RSA, 1024);
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/AuthorizedPeersTest.java b/security-utils/src/test/java/com/yahoo/security/tls/AuthorizedPeersTest.java
index e4c530dbb0b..2a7149ba2e3 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/AuthorizedPeersTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/AuthorizedPeersTest.java
@@ -1,26 +1,27 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;
-import com.yahoo.security.tls.PeerPolicy;
-import com.yahoo.security.tls.RequiredPeerCredential;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashSet;
import static com.yahoo.security.tls.RequiredPeerCredential.Field.CN;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author bjorncs
*/
public class AuthorizedPeersTest {
- @Test(expected = IllegalArgumentException.class)
- public void throws_exception_on_peer_policies_with_duplicate_names() {
- PeerPolicy peerPolicy1 = new PeerPolicy("duplicate-name", singletonList(RequiredPeerCredential.of(CN, "mycfgserver")));
- PeerPolicy peerPolicy2 = new PeerPolicy("duplicate-name", singletonList(RequiredPeerCredential.of(CN, "myclient")));
- new AuthorizedPeers(new HashSet<>(asList(peerPolicy1, peerPolicy2)));
+ @Test
+ void throws_exception_on_peer_policies_with_duplicate_names() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ PeerPolicy peerPolicy1 = new PeerPolicy("duplicate-name", singletonList(RequiredPeerCredential.of(CN, "mycfgserver")));
+ PeerPolicy peerPolicy2 = new PeerPolicy("duplicate-name", singletonList(RequiredPeerCredential.of(CN, "myclient")));
+ new AuthorizedPeers(new HashSet<>(asList(peerPolicy1, peerPolicy2)));
+ });
}
}
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/ConfigFileBasedTlsContextTest.java b/security-utils/src/test/java/com/yahoo/security/tls/ConfigFileBasedTlsContextTest.java
index 0af6d231701..7b70c842a4c 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/ConfigFileBasedTlsContextTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/ConfigFileBasedTlsContextTest.java
@@ -4,12 +4,13 @@ package com.yahoo.security.tls;
import com.yahoo.security.KeyUtils;
import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.security.X509CertificateUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import javax.net.ssl.SSLEngine;
import javax.security.auth.x500.X500Principal;
+
+import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
@@ -28,23 +29,23 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ConfigFileBasedTlsContextTest {
- @Rule
- public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
@Test
- public void can_create_sslcontext_from_credentials() throws IOException, InterruptedException {
+ void can_create_sslcontext_from_credentials() throws IOException, InterruptedException {
KeyPair keyPair = KeyUtils.generateKeypair(EC);
- Path privateKeyFile = tempDirectory.newFile().toPath();
+ Path privateKeyFile = File.createTempFile("junit", null, tempDirectory).toPath();
Files.write(privateKeyFile, KeyUtils.toPem(keyPair.getPrivate()).getBytes());
X509Certificate certificate = X509CertificateBuilder
.fromKeypair(keyPair, new X500Principal("CN=dummy"), EPOCH, EPOCH.plus(1, DAYS), SHA256_WITH_ECDSA, BigInteger.ONE)
.build();
- Path certificateChainFile = tempDirectory.newFile().toPath();
+ Path certificateChainFile = File.createTempFile("junit", null, tempDirectory).toPath();
String certificatePem = X509CertificateUtils.toPem(certificate);
Files.write(certificateChainFile, certificatePem.getBytes());
- Path caCertificatesFile = tempDirectory.newFile().toPath();
+ Path caCertificatesFile = File.createTempFile("junit", null, tempDirectory).toPath();
Files.write(caCertificatesFile, certificatePem.getBytes());
TransportSecurityOptions options = new TransportSecurityOptions.Builder()
@@ -52,7 +53,7 @@ public class ConfigFileBasedTlsContextTest {
.withCaCertificates(caCertificatesFile)
.build();
- Path optionsFile = tempDirectory.newFile().toPath();
+ Path optionsFile = File.createTempFile("junit", null, tempDirectory).toPath();
options.toJsonFile(optionsFile);
try (TlsContext tlsContext = new ConfigFileBasedTlsContext(optionsFile, AuthorizationMode.ENFORCE)) {
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/DefaultTlsContextTest.java b/security-utils/src/test/java/com/yahoo/security/tls/DefaultTlsContextTest.java
index b6c40a0c2e1..bf4a618d9ce 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/DefaultTlsContextTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/DefaultTlsContextTest.java
@@ -3,7 +3,7 @@ package com.yahoo.security.tls;
import com.yahoo.security.KeyUtils;
import com.yahoo.security.X509CertificateBuilder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLEngine;
import javax.security.auth.x500.X500Principal;
@@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class DefaultTlsContextTest {
@Test
- public void can_create_sslcontext_from_credentials() {
+ void can_create_sslcontext_from_credentials() {
KeyPair keyPair = KeyUtils.generateKeypair(EC);
X509Certificate certificate = X509CertificateBuilder
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/HostGlobPatternTest.java b/security-utils/src/test/java/com/yahoo/security/tls/HostGlobPatternTest.java
index a5628a637f8..b63b1dfeaa0 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/HostGlobPatternTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/HostGlobPatternTest.java
@@ -1,10 +1,10 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -13,28 +13,28 @@ import static org.junit.Assert.assertTrue;
public class HostGlobPatternTest {
@Test
- public void glob_without_wildcards_matches_entire_string() {
+ void glob_without_wildcards_matches_entire_string() {
assertTrue(globMatches("foo", "foo"));
assertFalse(globMatches("foo", "fooo"));
assertFalse(globMatches("foo", "ffoo"));
}
@Test
- public void wildcard_glob_can_match_prefix() {
+ void wildcard_glob_can_match_prefix() {
assertTrue(globMatches("foo*", "foo"));
assertTrue(globMatches("foo*", "foobar"));
assertFalse(globMatches("foo*", "ffoo"));
}
@Test
- public void wildcard_glob_can_match_suffix() {
+ void wildcard_glob_can_match_suffix() {
assertTrue(globMatches("*foo", "foo"));
assertTrue(globMatches("*foo", "ffoo"));
assertFalse(globMatches("*foo", "fooo"));
}
@Test
- public void wildcard_glob_can_match_substring() {
+ void wildcard_glob_can_match_substring() {
assertTrue(globMatches("f*o", "fo"));
assertTrue(globMatches("f*o", "foo"));
assertTrue(globMatches("f*o", "ffoo"));
@@ -42,7 +42,7 @@ public class HostGlobPatternTest {
}
@Test
- public void wildcard_glob_does_not_cross_multiple_dot_delimiter_boundaries() {
+ void wildcard_glob_does_not_cross_multiple_dot_delimiter_boundaries() {
assertTrue(globMatches("*.bar.baz", "foo.bar.baz"));
assertTrue(globMatches("*.bar.baz", ".bar.baz"));
assertFalse(globMatches("*.bar.baz", "zoid.foo.bar.baz"));
@@ -51,7 +51,7 @@ public class HostGlobPatternTest {
}
@Test
- public void single_char_glob_matches_non_dot_characters() {
+ void single_char_glob_matches_non_dot_characters() {
assertTrue(globMatches("f?o", "foo"));
assertFalse(globMatches("f?o", "fooo"));
assertFalse(globMatches("f?o", "ffoo"));
@@ -59,7 +59,7 @@ public class HostGlobPatternTest {
}
@Test
- public void other_regex_meta_characters_are_matched_as_literal_characters() {
+ void other_regex_meta_characters_are_matched_as_literal_characters() {
assertTrue(globMatches("<([{\\^-=$!|]})+.>", "<([{\\^-=$!|]})+.>"));
}
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/PeerAuthorizerTest.java b/security-utils/src/test/java/com/yahoo/security/tls/PeerAuthorizerTest.java
index 94b0dc4f83e..bea5c6108f2 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/PeerAuthorizerTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/PeerAuthorizerTest.java
@@ -6,7 +6,7 @@ import com.yahoo.security.KeyUtils;
import com.yahoo.security.SubjectAlternativeName.Type;
import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.security.tls.RequiredPeerCredential.Field;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
@@ -28,8 +28,8 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toSet;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -40,7 +40,7 @@ public class PeerAuthorizerTest {
private static final String POLICY_1 = "policy-1", POLICY_2 = "policy-2";
@Test
- public void certificate_must_match_both_san_and_cn_pattern() {
+ void certificate_must_match_both_san_and_cn_pattern() {
RequiredPeerCredential cnRequirement = createRequiredCredential(CN, "*.matching.cn");
RequiredPeerCredential sanRequirement = createRequiredCredential(SAN_DNS, "*.matching.san");
PeerAuthorizer authorizer = createPeerAuthorizer(createPolicy(POLICY_1, cnRequirement, sanRequirement));
@@ -50,12 +50,12 @@ public class PeerAuthorizerTest {
assertThat(result.matchedPolicies()).containsOnly(POLICY_1);
assertUnauthorized(authorizer.authorizePeer(createCertificate("foo.invalid.cn", singletonList("foo.matching.san"), emptyList())));
- assertUnauthorized(authorizer.authorizePeer(createCertificate("foo.invalid.cn", asList("foo.matching.san", "foo.invalid.san"),emptyList())));
+ assertUnauthorized(authorizer.authorizePeer(createCertificate("foo.invalid.cn", asList("foo.matching.san", "foo.invalid.san"), emptyList())));
assertUnauthorized(authorizer.authorizePeer(createCertificate("foo.matching.cn", singletonList("foo.invalid.san"), emptyList())));
}
@Test
- public void can_match_multiple_policies() {
+ void can_match_multiple_policies() {
RequiredPeerCredential cnRequirement = createRequiredCredential(CN, "*.matching.cn");
RequiredPeerCredential sanRequirement = createRequiredCredential(SAN_DNS, "*.matching.san");
@@ -70,7 +70,7 @@ public class PeerAuthorizerTest {
}
@Test
- public void can_match_subset_of_policies() {
+ void can_match_subset_of_policies() {
PeerAuthorizer peerAuthorizer = createPeerAuthorizer(
createPolicy(POLICY_1, createRequiredCredential(CN, "*.matching.cn")),
createPolicy(POLICY_2, createRequiredCredential(SAN_DNS, "*.matching.san")));
@@ -81,7 +81,7 @@ public class PeerAuthorizerTest {
}
@Test
- public void must_match_all_cn_and_san_patterns() {
+ void must_match_all_cn_and_san_patterns() {
RequiredPeerCredential cnSuffixRequirement = createRequiredCredential(CN, "*.*.matching.suffix.cn");
RequiredPeerCredential cnPrefixRequirement = createRequiredCredential(CN, "matching.prefix.*.*.*");
RequiredPeerCredential sanPrefixRequirement = createRequiredCredential(SAN_DNS, "*.*.matching.suffix.san");
@@ -95,7 +95,7 @@ public class PeerAuthorizerTest {
}
@Test
- public void can_match_policy_with_san_uri_pattern() {
+ void can_match_policy_with_san_uri_pattern() {
RequiredPeerCredential cnRequirement = createRequiredCredential(CN, "*.matching.cn");
RequiredPeerCredential sanUriRequirement = createRequiredCredential(SAN_URI, "myscheme://my/*/uri");
PeerAuthorizer authorizer = createPeerAuthorizer(createPolicy(POLICY_1, cnRequirement, sanUriRequirement));
@@ -108,7 +108,7 @@ public class PeerAuthorizerTest {
}
@Test
- public void auth_context_contains_union_of_granted_capabilities_from_policies() {
+ void auth_context_contains_union_of_granted_capabilities_from_policies() {
RequiredPeerCredential cnRequirement = createRequiredCredential(CN, "*.matching.cn");
RequiredPeerCredential sanRequirement = createRequiredCredential(SAN_DNS, "*.matching.san");
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsJsonSerializerTest.java b/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsJsonSerializerTest.java
index 476ab689903..895428037ed 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsJsonSerializerTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsJsonSerializerTest.java
@@ -1,9 +1,10 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -21,20 +22,21 @@ import java.util.Optional;
import static com.yahoo.security.tls.RequiredPeerCredential.Field.CN;
import static com.yahoo.security.tls.RequiredPeerCredential.Field.SAN_DNS;
import static com.yahoo.security.tls.RequiredPeerCredential.Field.SAN_URI;
-import static com.yahoo.test.json.JsonTestHelper.assertJsonEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
*/
public class TransportSecurityOptionsJsonSerializerTest {
- @Rule public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
private static final Path TEST_CONFIG_FILE = Paths.get("src/test/resources/transport-security-options.json");
+ private static final ObjectMapper mapper = new ObjectMapper();
@Test
- public void can_serialize_and_deserialize_transport_security_options() throws IOException {
+ void can_serialize_and_deserialize_transport_security_options() throws IOException {
TransportSecurityOptions options = new TransportSecurityOptions.Builder()
.withCaCertificates(Paths.get("/path/to/ca-certs.pem"))
.withCertificates(Paths.get("/path/to/cert.pem"), Paths.get("/path/to/key.pem"))
@@ -61,15 +63,15 @@ public class TransportSecurityOptionsJsonSerializerTest {
}
@Test
- public void can_serialize_options_without_authorized_peers() throws IOException {
+ void can_serialize_options_without_authorized_peers() throws IOException {
TransportSecurityOptions options = new TransportSecurityOptions.Builder()
.withCertificates(Paths.get("certs.pem"), Paths.get("myhost.key"))
.withCaCertificates(Paths.get("my_cas.pem"))
- .withAcceptedCiphers(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" , "TLS_AES_256_GCM_SHA384"))
+ .withAcceptedCiphers(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_AES_256_GCM_SHA384"))
.withAcceptedProtocols(Collections.singletonList("TLSv1.2"))
.withHostnameValidationDisabled(true)
.build();
- File outputFile = tempDirectory.newFile();
+ File outputFile = File.createTempFile("junit", null, tempDirectory);
try (OutputStream out = Files.newOutputStream(outputFile.toPath())) {
new TransportSecurityOptionsJsonSerializer().serialize(out, options);
}
@@ -79,13 +81,13 @@ public class TransportSecurityOptionsJsonSerializerTest {
}
@Test
- public void disable_hostname_validation_is_not_serialized_if_false() throws IOException {
+ void disable_hostname_validation_is_not_serialized_if_false() throws IOException {
TransportSecurityOptions options = new TransportSecurityOptions.Builder()
.withCertificates(Paths.get("certs.pem"), Paths.get("myhost.key"))
.withCaCertificates(Paths.get("my_cas.pem"))
.withHostnameValidationDisabled(false)
.build();
- File outputFile = tempDirectory.newFile();
+ File outputFile = File.createTempFile("junit", null, tempDirectory);
try (OutputStream out = Files.newOutputStream(outputFile.toPath())) {
new TransportSecurityOptionsJsonSerializer().serialize(out, options);
}
@@ -96,4 +98,8 @@ public class TransportSecurityOptionsJsonSerializerTest {
assertJsonEquals(expectedOutput, actualOutput);
}
+ private static void assertJsonEquals(String inputJson, String expectedJson) throws JsonProcessingException {
+ assertEquals(mapper.readTree(expectedJson), mapper.readTree(inputJson));
+ }
+
}
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsTest.java b/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsTest.java
index 7d67c492170..089a4ca6de5 100644
--- a/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsTest.java
+++ b/security-utils/src/test/java/com/yahoo/security/tls/TransportSecurityOptionsTest.java
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -11,7 +11,7 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
@@ -28,13 +28,13 @@ public class TransportSecurityOptionsTest {
.build();
@Test
- public void can_read_options_from_json_file() {
+ void can_read_options_from_json_file() {
TransportSecurityOptions actualOptions = TransportSecurityOptions.fromJsonFile(TEST_CONFIG_FILE);
assertEquals(OPTIONS, actualOptions);
}
@Test
- public void can_read_options_from_json() throws IOException {
+ void can_read_options_from_json() throws IOException {
String tlsJson = new String(Files.readAllBytes(TEST_CONFIG_FILE), StandardCharsets.UTF_8);
TransportSecurityOptions actualOptions = TransportSecurityOptions.fromJson(tlsJson);
assertEquals(OPTIONS, actualOptions);
diff --git a/vespa-athenz/pom.xml b/vespa-athenz/pom.xml
index 580910799c1..55482dd1fed 100644
--- a/vespa-athenz/pom.xml
+++ b/vespa-athenz/pom.xml
@@ -22,6 +22,12 @@
<artifactId>container-dev</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.yahoo.vespa</groupId>
@@ -38,11 +44,6 @@
<!-- test -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
@@ -52,6 +53,30 @@
<artifactId>testutil</artifactId>
<version>${project.version}</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
</dependency>
<!-- compile -->
@@ -90,6 +115,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency> <!-- needed by auth-core -->
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java
index ff3d8d20797..d7d5428c11b 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java
@@ -1,14 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.function.Supplier;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author bjorncs
@@ -16,28 +13,28 @@ import static org.junit.Assert.fail;
public class AthenzDomainTest {
@Test
- public void domain_can_be_constructed_from_valid_string() {
+ void domain_can_be_constructed_from_valid_string() {
new AthenzDomain("home.john.my-app");
}
@Test
- public void invalid_domain_throws_exception() {
+ void invalid_domain_throws_exception() {
assertInvalid(() -> new AthenzDomain("endswithdot."));
assertInvalid(() -> new AthenzDomain(".startswithdot"));
}
@Test
- public void parent_domain_is_without_name_suffix() {
+ void parent_domain_is_without_name_suffix() {
assertEquals(new AthenzDomain("home.john"), new AthenzDomain("home.john.myapp").getParent());
}
@Test
- public void domain_name_suffix_is_the_suffix_after_last_dot() {
+ void domain_name_suffix_is_the_suffix_after_last_dot() {
assertEquals("myapp", new AthenzDomain("home.john.myapp").getNameSuffix());
}
@Test
- public void domain_without_dot_is_toplevel() {
+ void domain_without_dot_is_toplevel() {
assertTrue(new AthenzDomain("toplevel").isTopLevelDomain());
assertFalse(new AthenzDomain("not.toplevel").isTopLevelDomain());
}
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzResourceNameTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzResourceNameTest.java
index ececa45d5fb..a2de235906c 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzResourceNameTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzResourceNameTest.java
@@ -1,9 +1,9 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
@@ -11,7 +11,7 @@ import static org.junit.Assert.*;
public class AthenzResourceNameTest {
@Test
- public void can_serialize_and_deserialize_to_string() {
+ void can_serialize_and_deserialize_to_string() {
AthenzResourceName resourceName = new AthenzResourceName(new AthenzDomain("domain"), "entity");
String resourceNameString = resourceName.toResourceNameString();
assertEquals("domain:entity", resourceNameString);
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/NTokenGeneratorTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/NTokenGeneratorTest.java
index 7c4ee36926f..dd12bca03f3 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/NTokenGeneratorTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/NTokenGeneratorTest.java
@@ -3,13 +3,13 @@ package com.yahoo.vespa.athenz.api;
import com.yahoo.athenz.auth.util.CryptoException;
import com.yahoo.test.ManualClock;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.security.PrivateKey;
import java.time.Instant;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
/**
@@ -19,14 +19,14 @@ public class NTokenGeneratorTest {
private final PrivateKey key = mock(PrivateKey.class);
@Test
- public void ntoken() {
+ void ntoken() {
var signer = new Signer("signature");
NTokenGenerator generator = new NTokenGenerator(signer, new ManualClock(Instant.ofEpochSecond(12L)), () -> 3L);
AthenzIdentity identity = new AthenzService("domain", "service");
NToken token = generator.setIdentity(identity)
- .setKeyVersion("0")
- .sign(key);
+ .setKeyVersion("0")
+ .sign(key);
assertEquals("v=S1;d=domain;n=service;k=0;a=3;t=12;e=612", signer.message);
assertSame(key, signer.key);
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialsTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialsTest.java
index 39ab8294409..48ff3ab651a 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialsTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialsTest.java
@@ -2,14 +2,14 @@
package com.yahoo.vespa.athenz.aws;
import com.yahoo.vespa.athenz.api.AwsTemporaryCredentials;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author tokle
@@ -17,19 +17,19 @@ import static org.junit.Assert.assertFalse;
public class AwsCredentialsTest {
@Test
- public void refreshes_correctly() {
+ void refreshes_correctly() {
Clock clock = Clock.systemUTC();
// Does not require refresh when expires in 10 minutes
assertFalse(AwsCredentials.shouldRefresh(getCredentials(clock.instant().plus(Duration.ofMinutes(10)))));
// Requires refresh when expires in 3 minutes
- Assert.assertTrue(AwsCredentials.shouldRefresh(getCredentials(clock.instant().plus(Duration.ofMinutes(3)))));
+ assertTrue(AwsCredentials.shouldRefresh(getCredentials(clock.instant().plus(Duration.ofMinutes(3)))));
// Requires refresh when expired
- Assert.assertTrue(AwsCredentials.shouldRefresh(getCredentials(clock.instant().minus(Duration.ofMinutes(1)))));
+ assertTrue(AwsCredentials.shouldRefresh(getCredentials(clock.instant().minus(Duration.ofMinutes(1)))));
// Refreshes when no credentials provided
- Assert.assertTrue(AwsCredentials.shouldRefresh(null));
+ assertTrue(AwsCredentials.shouldRefresh(null));
}
private AwsTemporaryCredentials getCredentials(Instant expiration) {
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identity/SiaIdentityProviderTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identity/SiaIdentityProviderTest.java
index f502951572c..764b2d26006 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identity/SiaIdentityProviderTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identity/SiaIdentityProviderTest.java
@@ -7,9 +7,8 @@ import com.yahoo.security.SignatureAlgorithm;
import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.security.X509CertificateUtils;
import com.yahoo.vespa.athenz.api.AthenzService;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import javax.security.auth.x500.X500Principal;
import java.io.File;
@@ -22,27 +21,27 @@ import java.time.Duration;
import java.time.Instant;
import static com.yahoo.yolean.Exceptions.uncheck;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author bjorncs
*/
public class SiaIdentityProviderTest {
- @Rule
- public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
@Test
- public void constructs_ssl_context_from_file() throws IOException {
- File keyFile = tempDirectory.newFile();
+ void constructs_ssl_context_from_file() throws IOException {
+ File keyFile = File.createTempFile("junit", null, tempDirectory);
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
createPrivateKeyFile(keyFile, keypair);
X509Certificate certificate = createCertificate(keypair);
- File certificateFile = tempDirectory.newFile();
+ File certificateFile = File.createTempFile("junit", null, tempDirectory);
createCertificateFile(certificate, certificateFile);
- File trustStoreFile = tempDirectory.newFile();
+ File trustStoreFile = File.createTempFile("junit", null, tempDirectory);
createTrustStoreFile(certificate, trustStoreFile);
SiaIdentityProvider provider =
@@ -56,16 +55,16 @@ public class SiaIdentityProviderTest {
}
@Test
- public void constructs_ssl_context_with_pem_trust_store() throws IOException {
- File keyFile = tempDirectory.newFile();
+ void constructs_ssl_context_with_pem_trust_store() throws IOException {
+ File keyFile = File.createTempFile("junit", null, tempDirectory);
KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
createPrivateKeyFile(keyFile, keypair);
X509Certificate certificate = createCertificate(keypair);
- File certificateFile = tempDirectory.newFile();
+ File certificateFile = File.createTempFile("junit", null, tempDirectory);
createCertificateFile(certificate, certificateFile);
- File trustStoreFile = tempDirectory.newFile();
+ File trustStoreFile = File.createTempFile("junit", null, tempDirectory);
createPemTrustStoreFile(certificate, trustStoreFile);
SiaIdentityProvider provider =
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/api/VespaUniqueInstanceIdTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/api/VespaUniqueInstanceIdTest.java
index 81f2d2a08cb..d22a791fa60 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/api/VespaUniqueInstanceIdTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/api/VespaUniqueInstanceIdTest.java
@@ -1,10 +1,10 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.identityprovider.api;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static com.yahoo.vespa.athenz.identityprovider.api.IdentityType.*;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
@@ -12,7 +12,7 @@ import static org.junit.Assert.*;
public class VespaUniqueInstanceIdTest {
@Test
- public void can_serialize_to_and_deserialize_from_string() {
+ void can_serialize_to_and_deserialize_from_string() {
VespaUniqueInstanceId id =
new VespaUniqueInstanceId(1, "cluster-id", "instance", "application", "tenant", "region", "environment", TENANT);
String stringRepresentation = id.asDottedString();
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/AthenzIdentityProviderImplTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/AthenzIdentityProviderImplTest.java
index 21f2c84710a..c9d2ea581bb 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/AthenzIdentityProviderImplTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/AthenzIdentityProviderImplTest.java
@@ -14,12 +14,13 @@ import com.yahoo.security.Pkcs10CsrBuilder;
import com.yahoo.security.SignatureAlgorithm;
import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.test.ManualClock;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import javax.security.auth.x500.X500Principal;
+
+import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Path;
@@ -32,6 +33,7 @@ import java.util.Date;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Supplier;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -44,8 +46,8 @@ import static org.mockito.Mockito.when;
*/
public class AthenzIdentityProviderImplTest {
- @Rule
- public TemporaryFolder tempDir = new TemporaryFolder();
+ @TempDir
+ public File tempDir;
public static final Duration certificateValidity = Duration.ofDays(30);
@@ -63,7 +65,7 @@ public class AthenzIdentityProviderImplTest {
private Path trustStoreFile;
private X509Certificate caCertificate;
- @Before
+ @BeforeEach
public void createTrustStoreFile() throws IOException {
caCertificate = X509CertificateBuilder
.fromKeypair(
@@ -74,7 +76,7 @@ public class AthenzIdentityProviderImplTest {
SignatureAlgorithm.SHA256_WITH_ECDSA,
BigInteger.ONE)
.build();
- trustStoreFile = tempDir.newFile().toPath();
+ trustStoreFile = File.createTempFile("junit", null, tempDir).toPath();
KeyStoreUtils.writeKeyStoreToFile(
KeyStoreBuilder.withType(KeyStoreType.JKS)
.withKeyEntry("default", caKeypair.getPrivate(), caCertificate)
@@ -82,17 +84,19 @@ public class AthenzIdentityProviderImplTest {
trustStoreFile);
}
- @Test(expected = AthenzIdentityProviderException.class)
- public void component_creation_fails_when_credentials_not_found() {
- AthenzCredentialsService credentialService = mock(AthenzCredentialsService.class);
- when(credentialService.registerInstance())
- .thenThrow(new RuntimeException("athenz unavailable"));
-
- new AthenzIdentityProviderImpl(IDENTITY_CONFIG, mock(Metric.class), trustStoreFile ,credentialService, mock(ScheduledExecutorService.class), new ManualClock(Instant.EPOCH));
+ @Test
+ void component_creation_fails_when_credentials_not_found() {
+ assertThrows(AthenzIdentityProviderException.class, () -> {
+ AthenzCredentialsService credentialService = mock(AthenzCredentialsService.class);
+ when(credentialService.registerInstance())
+ .thenThrow(new RuntimeException("athenz unavailable"));
+
+ new AthenzIdentityProviderImpl(IDENTITY_CONFIG, mock(Metric.class), trustStoreFile, credentialService, mock(ScheduledExecutorService.class), new ManualClock(Instant.EPOCH));
+ });
}
@Test
- public void metrics_updated_on_refresh() {
+ void metrics_updated_on_refresh() {
ManualClock clock = new ManualClock(Instant.EPOCH);
Metric metric = mock(Metric.class);
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/IdentityDocumentSignerTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/IdentityDocumentSignerTest.java
index 5a3099aff76..5253fee0802 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/IdentityDocumentSignerTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/IdentityDocumentSignerTest.java
@@ -7,7 +7,7 @@ import com.yahoo.vespa.athenz.api.AthenzService;
import com.yahoo.vespa.athenz.identityprovider.api.IdentityType;
import com.yahoo.vespa.athenz.identityprovider.api.SignedIdentityDocument;
import com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.security.KeyPair;
import java.time.Instant;
@@ -16,7 +16,7 @@ import java.util.HashSet;
import static com.yahoo.vespa.athenz.identityprovider.api.IdentityType.TENANT;
import static com.yahoo.vespa.athenz.identityprovider.api.SignedIdentityDocument.DEFAULT_DOCUMENT_VERSION;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -25,7 +25,7 @@ public class IdentityDocumentSignerTest {
public static final int KEY_VERSION = 0;
@Test
- public void generates_and_validates_signature() {
+ void generates_and_validates_signature() {
IdentityDocumentSigner signer = new IdentityDocumentSigner();
IdentityType identityType = TENANT;
VespaUniqueInstanceId id =
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/InstanceCsrGeneratorTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/InstanceCsrGeneratorTest.java
index fc0b0a9c85f..3e4f8541aaa 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/InstanceCsrGeneratorTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/identityprovider/client/InstanceCsrGeneratorTest.java
@@ -6,13 +6,13 @@ import com.yahoo.security.KeyUtils;
import com.yahoo.vespa.athenz.api.AthenzService;
import com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId;
import com.yahoo.security.Pkcs10Csr;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.security.auth.x500.X500Principal;
import java.security.KeyPair;
import java.util.Collections;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author mortent
@@ -24,7 +24,7 @@ public class InstanceCsrGeneratorTest {
private static final String ATHENZ_SERVICE = "foo.bar";
@Test
- public void it_generates_csr_with_correct_subject() {
+ void it_generates_csr_with_correct_subject() {
CsrGenerator csrGenerator = new CsrGenerator(DNS_SUFFIX, PROVIDER_SERVICE);
AthenzService service = new AthenzService(ATHENZ_SERVICE);
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentitiesTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentitiesTest.java
index 1b5dc3b7a71..262bac012b8 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentitiesTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentitiesTest.java
@@ -4,9 +4,9 @@ package com.yahoo.vespa.athenz.utils;
import com.yahoo.vespa.athenz.api.AthenzDomain;
import com.yahoo.vespa.athenz.api.AthenzIdentity;
import com.yahoo.vespa.athenz.api.AthenzService;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author bjorncs
@@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals;
public class AthenzIdentitiesTest {
@Test
- public void athenz_identity_is_parsed_from_dot_separated_string() {
+ void athenz_identity_is_parsed_from_dot_separated_string() {
AthenzIdentity expectedIdentity = new AthenzService(new AthenzDomain("my.subdomain"), "myservicename");
String fullName = expectedIdentity.getFullName();
AthenzIdentity actualIdentity = AthenzIdentities.from(fullName);
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentityVerifierTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentityVerifierTest.java
index 5b699be4088..e59d9998170 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentityVerifierTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/AthenzIdentityVerifierTest.java
@@ -7,7 +7,7 @@ import com.yahoo.security.X509CertificateBuilder;
import com.yahoo.vespa.athenz.api.AthenzIdentity;
import com.yahoo.vespa.athenz.api.AthenzService;
import com.yahoo.vespa.athenz.tls.AthenzIdentityVerifier;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
@@ -21,8 +21,8 @@ import java.time.Instant;
import static com.yahoo.security.SignatureAlgorithm.SHA256_WITH_ECDSA;
import static java.util.Collections.singleton;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.when;
public class AthenzIdentityVerifierTest {
@Test
- public void verifies_certificate_with_athenz_service_as_common_name() throws Exception {
+ void verifies_certificate_with_athenz_service_as_common_name() throws Exception {
AthenzIdentity trustedIdentity = new AthenzService("mydomain", "alice");
AthenzIdentity unknownIdentity = new AthenzService("mydomain", "mallory");
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC);
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java
index 62c187b8c2c..7be55ec18a8 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java
@@ -3,29 +3,29 @@ package com.yahoo.vespa.athenz.utils;
import com.yahoo.vespa.athenz.api.AthenzIdentity;
import com.yahoo.vespa.athenz.api.AthenzService;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
*/
public class SiaUtilsTest {
- @Rule
- public TemporaryFolder tempDirectory = new TemporaryFolder();
+ @TempDir
+ public File tempDirectory;
@Test
- public void it_finds_all_identity_names_from_files_in_sia_keys_directory() throws IOException {
- Path siaRoot = tempDirectory.getRoot().toPath();
+ void it_finds_all_identity_names_from_files_in_sia_keys_directory() throws IOException {
+ Path siaRoot = tempDirectory.toPath();
assertTrue(SiaUtils.findSiaServices(siaRoot).isEmpty());
Files.createDirectory(siaRoot.resolve("keys"));
AthenzService fooService = new AthenzService("my.domain.foo");