From e5600c3f4d805cf39b59b10e210d825da2dae539 Mon Sep 17 00:00:00 2001 From: Max Lambrecht Date: Wed, 12 Apr 2023 13:16:22 -0500 Subject: [PATCH] Update gradle version to 8.0.2 (#104) Update gradle version to 8.0.2 Signed-off-by: Max Lambrecht --- build.gradle | 12 ++++-- gradle/wrapper/gradle-wrapper.properties | 2 +- java-spiffe-core/build.gradle | 4 +- .../io/spiffe/workloadapi/AddressTest.java | 26 +++++++----- .../workloadapi/CachedJwtSourceTest.java | 41 ++++++++++--------- .../workloadapi/DefaultJwtSourceTest.java | 40 +++++++++--------- .../DefaultWorkloadApiClientTest.java | 16 ++++---- .../workloadapi/DefaultX509SourceTest.java | 22 +++++----- .../java/io/spiffe/utils/TestUtils.java | 31 -------------- java-spiffe-helper/build.gradle | 2 +- .../helper/keystore/KeyStoreHelperTest.java | 16 ++++---- java-spiffe-provider/build.gradle | 2 +- .../provider/X509SourceManagerTest.java | 14 ++++--- 13 files changed, 109 insertions(+), 119 deletions(-) diff --git a/build.gradle b/build.gradle index c1b022a..e9e8244 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,11 @@ subprojects { ext { grpcVersion = '1.54.0' - jupiterVersion = '5.7.0' - mockitoVersion = '3.5.15' + jupiterVersion = '5.9.2' + mockitoVersion = '3.12.4' lombokVersion = '1.18.20' nimbusVersion = '9.31' + shadowVersion = '8.1.1' //IMPORTANT: This must be in sync with the shaded netty version in gRPC nettyVersion = '4.1.91.Final' @@ -107,6 +108,9 @@ subprojects { testCompileOnly group: 'org.mockito', name: 'mockito-core', version: "${mockitoVersion}" testRuntimeOnly group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockitoVersion}" + testRuntimeOnly group: 'org.mockito', name: 'mockito-inline', version: "${mockitoVersion}" + + testImplementation group: 'uk.org.webcompere', name: 'system-stubs-core', version: '2.0.2' // Project Lombok dependency compileOnly group: 'org.projectlombok', name: 'lombok', version: "${lombokVersion}" @@ -145,8 +149,8 @@ task jacocoTestReport(type: JacocoReport) { } reports { - xml.enabled true - html.enabled true + xml.required = true + html.required = true } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f91f066..7f4b505 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip diff --git a/java-spiffe-core/build.gradle b/java-spiffe-core/build.gradle index 1e72d49..1002246 100644 --- a/java-spiffe-core/build.gradle +++ b/java-spiffe-core/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { - classpath group: 'com.google.protobuf', name: 'protobuf-gradle-plugin', version: '0.8.13' + classpath group: 'com.google.protobuf', name: 'protobuf-gradle-plugin', version: '0.9.2' } } @@ -31,6 +31,8 @@ sourceSets { } } +sourcesJar.duplicatesStrategy = DuplicatesStrategy.INCLUDE + configurations { integrationTestImplementation.extendsFrom testImplementation integrationTestCompile.extendsFrom testCompile diff --git a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/AddressTest.java b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/AddressTest.java index c860333..df8ccd2 100644 --- a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/AddressTest.java +++ b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/AddressTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.net.URI; import java.util.stream.Stream; @@ -74,19 +75,24 @@ public class AddressTest { @Test void getDefaultAddress() throws Exception { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test" ); - String defaultAddress = Address.getDefaultAddress(); - assertEquals("unix:/tmp/test", defaultAddress); + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test").execute(() -> { + String defaultAddress = Address.getDefaultAddress(); + assertEquals("unix:/tmp/test", defaultAddress); + }); } @Test void getDefaultAddress_isBlankThrowsException() throws Exception { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, ""); - try { - Address.getDefaultAddress(); - fail(); - } catch (Exception e) { - assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "").execute(() -> { + try { + Address.getDefaultAddress(); + fail(); + } catch (Exception e) { + assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); + } + }); + + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "").execute(() -> { + }); } } \ No newline at end of file diff --git a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/CachedJwtSourceTest.java b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/CachedJwtSourceTest.java index 92f8aa6..20144dc 100644 --- a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/CachedJwtSourceTest.java +++ b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/CachedJwtSourceTest.java @@ -9,11 +9,11 @@ import io.spiffe.exception.SocketEndpointAddressException; import io.spiffe.spiffeid.SpiffeId; import io.spiffe.spiffeid.TrustDomain; import io.spiffe.svid.jwtsvid.JwtSvid; -import io.spiffe.utils.TestUtils; import lombok.val; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.io.IOException; import java.time.Clock; @@ -495,28 +495,29 @@ class CachedJwtSourceTest { @Test void newSource_DefaultSocketAddress() throws Exception { - try { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test"); - CachedJwtSource.newSource(); - fail(); - } catch (JwtSourceException e) { - assertEquals("Error creating JWT source", e.getMessage()); - } catch (SocketEndpointAddressException e) { - fail(); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test").execute(() -> { + try { + CachedJwtSource.newSource(); + fail(); + } catch (JwtSourceException e) { + assertEquals("Error creating JWT source", e.getMessage()); + } catch (SocketEndpointAddressException e) { + fail(); + } + }); } @Test void newSource_noSocketAddress() throws Exception { - try { - // just in case it's defined in the environment - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, ""); - CachedJwtSource.newSource(); - fail(); - } catch (SocketEndpointAddressException e) { - fail(); - } catch (IllegalStateException e) { - assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "").execute(() -> { + try { + CachedJwtSource.newSource(); + fail(); + } catch (SocketEndpointAddressException e) { + fail(); + } catch (IllegalStateException e) { + assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); + } + }); } } diff --git a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultJwtSourceTest.java b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultJwtSourceTest.java index 2406746..fd89d1b 100644 --- a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultJwtSourceTest.java +++ b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultJwtSourceTest.java @@ -14,6 +14,7 @@ import lombok.val; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.io.IOException; import java.time.Duration; @@ -257,28 +258,29 @@ class DefaultJwtSourceTest { @Test void newSource_DefaultSocketAddress() throws Exception { - try { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test"); - DefaultJwtSource.newSource(); - fail(); - } catch (JwtSourceException e) { - assertEquals("Error creating JWT source", e.getMessage()); - } catch (SocketEndpointAddressException e) { - fail(); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test").execute(() -> { + try { + DefaultJwtSource.newSource(); + fail(); + } catch (JwtSourceException e) { + assertEquals("Error creating JWT source", e.getMessage()); + } catch (SocketEndpointAddressException e) { + fail(); + } + }); } @Test void newSource_noSocketAddress() throws Exception { - try { - // just in case it's defined in the environment - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, ""); - DefaultJwtSource.newSource(); - fail(); - } catch (SocketEndpointAddressException e) { - fail(); - } catch (IllegalStateException e) { - assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "").execute(() -> { + try { + DefaultJwtSource.newSource(); + fail(); + } catch (SocketEndpointAddressException e) { + fail(); + } catch (IllegalStateException e) { + assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); + } + }); } } \ No newline at end of file diff --git a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultWorkloadApiClientTest.java b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultWorkloadApiClientTest.java index face97a..6700605 100644 --- a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultWorkloadApiClientTest.java +++ b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultWorkloadApiClientTest.java @@ -20,6 +20,7 @@ import org.junit.Rule; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.io.IOException; import java.security.KeyPair; @@ -54,13 +55,14 @@ class DefaultWorkloadApiClientTest { @Test void testNewClient_defaultOptions() throws Exception { - try { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/agent.sock"); - WorkloadApiClient client = DefaultWorkloadApiClient.newClient(); - assertNotNull(client); - } catch (SocketEndpointAddressException e) { - fail(e); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/agent.sock").execute(() -> { + try { + WorkloadApiClient client = DefaultWorkloadApiClient.newClient(); + assertNotNull(client); + } catch (SocketEndpointAddressException e) { + fail(e); + } + }); } @Test diff --git a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultX509SourceTest.java b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultX509SourceTest.java index 4bed6a5..36587ba 100644 --- a/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultX509SourceTest.java +++ b/java-spiffe-core/src/test/java/io/spiffe/workloadapi/DefaultX509SourceTest.java @@ -7,11 +7,11 @@ import io.spiffe.exception.X509SourceException; import io.spiffe.spiffeid.SpiffeId; import io.spiffe.spiffeid.TrustDomain; import io.spiffe.svid.x509svid.X509Svid; -import io.spiffe.utils.TestUtils; import lombok.val; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.time.Duration; @@ -162,15 +162,15 @@ class DefaultX509SourceTest { @Test void newSource_noSocketAddress() throws Exception { - try { - // just in case the variable is defined in the environment - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, ""); - DefaultX509Source.newSource(); - fail(); - } catch (X509SourceException | SocketEndpointAddressException e) { - fail(); - } catch (IllegalStateException e) { - assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "").execute(() -> { + try { + DefaultX509Source.newSource(); + fail(); + } catch (X509SourceException | SocketEndpointAddressException e) { + fail(); + } catch (IllegalStateException e) { + assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); + } + }); } } \ No newline at end of file diff --git a/java-spiffe-core/src/testFixtures/java/io/spiffe/utils/TestUtils.java b/java-spiffe-core/src/testFixtures/java/io/spiffe/utils/TestUtils.java index 1b912bd..1e62feb 100644 --- a/java-spiffe-core/src/testFixtures/java/io/spiffe/utils/TestUtils.java +++ b/java-spiffe-core/src/testFixtures/java/io/spiffe/utils/TestUtils.java @@ -107,38 +107,7 @@ public class TestUtils { .build(); } - public static void setEnvironmentVariable(String variableName, String value) throws Exception { - Class processEnvironment = Class.forName("java.lang.ProcessEnvironment"); - - Field unmodifiableMapField = getField(processEnvironment, "theUnmodifiableEnvironment"); - Object unmodifiableMap = unmodifiableMapField.get(null); - injectIntoUnmodifiableMap(variableName, value, unmodifiableMap); - - Field mapField = getField(processEnvironment, "theEnvironment"); - Map map = (Map) mapField.get(null); - map.put(variableName, value); - } - - public static Object invokeMethod(Class clazz, String methodName, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = clazz.getDeclaredMethod(methodName); - method.setAccessible(true); - return method.invoke(args); - } - - public static Field getField(Class clazz, String fieldName) throws NoSuchFieldException { - Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } - public static URI toUri(String path) throws URISyntaxException { return Thread.currentThread().getContextClassLoader().getResource(path).toURI(); } - - private static void injectIntoUnmodifiableMap(String key, String value, Object map) throws ReflectiveOperationException { - Class unmodifiableMap = Class.forName("java.util.Collections$UnmodifiableMap"); - Field field = getField(unmodifiableMap, "m"); - Object obj = field.get(map); - ((Map) obj).put(key, value); - } } diff --git a/java-spiffe-helper/build.gradle b/java-spiffe-helper/build.gradle index 96c50ea..30777c4 100644 --- a/java-spiffe-helper/build.gradle +++ b/java-spiffe-helper/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "5.2.0" + id "com.github.johnrengelman.shadow" version "${shadowVersion}" } description = "Java SPIFFE Library Helper module to store X.509 SVIDs and Bundles in a Java KeyStore in disk" diff --git a/java-spiffe-helper/src/test/java/io/spiffe/helper/keystore/KeyStoreHelperTest.java b/java-spiffe-helper/src/test/java/io/spiffe/helper/keystore/KeyStoreHelperTest.java index 310de1f..d2fd8c3 100644 --- a/java-spiffe-helper/src/test/java/io/spiffe/helper/keystore/KeyStoreHelperTest.java +++ b/java-spiffe-helper/src/test/java/io/spiffe/helper/keystore/KeyStoreHelperTest.java @@ -13,6 +13,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.io.IOException; import java.nio.file.Files; @@ -190,13 +191,14 @@ class KeyStoreHelperTest { @Test void testCreateKeyStoreHelper_createNewClient() throws Exception { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test"); - val options = getKeyStoreValidOptions(null); - try { - KeyStoreHelper.create(options); - } catch (KeyStoreHelperException e) { - fail(); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "unix:/tmp/test").execute(() -> { + val options = getKeyStoreValidOptions(null); + try { + KeyStoreHelper.create(options); + } catch (KeyStoreHelperException e) { + fail(); + } + }); } @Test diff --git a/java-spiffe-provider/build.gradle b/java-spiffe-provider/build.gradle index fbfcefc..1025d88 100644 --- a/java-spiffe-provider/build.gradle +++ b/java-spiffe-provider/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "5.2.0" + id "com.github.johnrengelman.shadow" version "${shadowVersion}" } description = "Java Security Provider implementation supporting X.509-SVIDs and methods for " + diff --git a/java-spiffe-provider/src/test/java/io/spiffe/provider/X509SourceManagerTest.java b/java-spiffe-provider/src/test/java/io/spiffe/provider/X509SourceManagerTest.java index 9c84d72..4e87d86 100644 --- a/java-spiffe-provider/src/test/java/io/spiffe/provider/X509SourceManagerTest.java +++ b/java-spiffe-provider/src/test/java/io/spiffe/provider/X509SourceManagerTest.java @@ -4,6 +4,7 @@ import io.spiffe.utils.TestUtils; import io.spiffe.workloadapi.Address; import io.spiffe.workloadapi.X509Source; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import java.lang.reflect.Field; @@ -24,11 +25,12 @@ class X509SourceManagerTest { @Test void getX509Source_defaultAddressNotSet() throws Exception { - TestUtils.setEnvironmentVariable(Address.SOCKET_ENV_VARIABLE, "" ); - try { - X509SourceManager.getX509Source(); - } catch (IllegalStateException e) { - assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); - } + new EnvironmentVariables(Address.SOCKET_ENV_VARIABLE, "").execute(() -> { + try { + X509SourceManager.getX509Source(); + } catch (IllegalStateException e) { + assertEquals("Endpoint Socket Address Environment Variable is not set: SPIFFE_ENDPOINT_SOCKET", e.getMessage()); + } + }); } } \ No newline at end of file