From c7528b531080f4b79a0adc10b321f1337c0a4f96 Mon Sep 17 00:00:00 2001
From: Jarrod Young
@@ -58,7 +59,21 @@ public Debug withNameSpace(final String nameSpace) { **/ public HealthResponse health() throws VaultException { - return health(null, null, null, null); + return health(null, null, null, null, null, + null, null, null); + } + + /** + *
A deprecated, overloaded version of {@link Debug#health()} that allows for passing one or more of the previous four optional parameters.
+ * Please consider using the new constructor that adds support for perfStandbyOk, drSecondaryCode, etc/ + */ + @Deprecated + public HealthResponse health( + final Boolean standbyOk, + final Integer activeCode, + final Integer standbyCode, + final Integer sealedCode) throws VaultException { + return health(standbyOk, activeCode, standbyCode, sealedCode, null, null, null, null); } /** @@ -71,10 +86,14 @@ public HealthResponse health() throws VaultException { * will need to checkHealthReponse.getRestResponse().getStatus() to determine the result of
* the operation.
*
- * @param standbyOk (optional) Indicates that being a standby should still return the active status code instead of the standby code
- * @param activeCode (optional) Indicates the status code that should be returned for an active node instead of the default of 200
- * @param standbyCode (optional) Indicates the status code that should be returned for a standby node instead of the default of 429
- * @param sealedCode (optional) Indicates the status code that should be returned for a sealed node instead of the default of 500
+ * @param standbyOk (optional) Indicates that being a standby should still return the active status code instead of the standby code
+ * @param activeCode (optional) Indicates the status code that should be returned for an active node instead of the default of 200
+ * @param standbyCode (optional) Indicates the status code that should be returned for a standby node instead of the default of 429
+ * @param sealedCode (optional) Indicates the status code that should be returned for a sealed node instead of the default of 500
+ * @param perfStandbyOk (optional) Specifies if being a performance standby should still return the active status code instead of the performance standby status code
+ * @param drSecondaryCode (optional) Indicates the status code that should be returned for a DR secondary node instead of the default of 472
+ * @param performanceStandbyCode (optional) Indicates the status code that should be returned for a performance standby node instead of the default of 473
+ * @param unInitCode (optional) Indicates the status code that should be returned for an uninitialized node instead of the default of 501
* @return The response information returned from Vault
* @throws VaultException If an error occurs or unexpected response received from Vault
*/
@@ -82,7 +101,11 @@ public HealthResponse health(
final Boolean standbyOk,
final Integer activeCode,
final Integer standbyCode,
- final Integer sealedCode
+ final Integer sealedCode,
+ final Boolean perfStandbyOk,
+ final Integer drSecondaryCode,
+ final Integer performanceStandbyCode,
+ final Integer unInitCode
) throws VaultException {
final String path = "sys/health";
int retryCount = 0;
@@ -105,6 +128,11 @@ public HealthResponse health(
if (activeCode != null) rest.parameter("activecode", activeCode.toString());
if (standbyCode != null) rest.parameter("standbycode", standbyCode.toString());
if (sealedCode != null) rest.parameter("sealedcode", sealedCode.toString());
+ if (perfStandbyOk != null) rest.parameter("perfstandbyok", perfStandbyOk.toString());
+ if (drSecondaryCode != null) rest.parameter("drsecondarycode", drSecondaryCode.toString());
+ if (performanceStandbyCode != null)
+ rest.parameter("performancestandbycode", performanceStandbyCode.toString());
+ if (unInitCode != null) rest.parameter("uninitcode", unInitCode.toString());
// Execute request
final RestResponse restResponse = rest.get();
@@ -112,12 +140,20 @@ public HealthResponse health(
final SetConstructs a HealthResponse object from the data received in a health
@@ -34,7 +38,7 @@ public class HealthResponse implements Serializable {
* {@link com.bettercloud.vault.api.Debug#health(Boolean, Integer, Integer, Integer)}.
Integration tests for the debug-related operations on the Vault HTTP API's.
@@ -44,12 +46,29 @@ public void testHealth_Plain() throws VaultException { assertEquals(200, response.getRestResponse().getStatus()); } + @Test + public void testHealth_Sealed() throws VaultException { + vault.seal().seal(); + final HealthResponse response = vault.debug().health(); + + assertTrue(response.getInitialized()); + assertTrue(response.getSealed()); + assertTrue(response.getStandby()); + assertNotNull(response.getServerTimeUTC()); + assertEquals(503, response.getRestResponse().getStatus()); + assertFalse(response.getPerformanceStandby()); + assertNotEquals("disabled", response.getReplicationPerformanceMode()); + assertNotEquals("disabled", response.getReplicationDrMode()); + container.getRootVault().seal().unseal(container.getUnsealKey()); + } + @Test public void testHealth_WithParams() throws VaultException { - final HealthResponse response = vault.debug().health(null, 212, null, null); + final HealthResponse response = vault.debug().health(null, 212, null, null, null, null, null, null); assertTrue(response.getInitialized()); assertFalse(response.getSealed()); assertFalse(response.getStandby()); + assertFalse(response.getPerformanceStandby()); assertNotNull(response.getServerTimeUTC()); assertEquals(212, response.getRestResponse().getStatus()); } @@ -66,11 +85,30 @@ public void testHealth_WithParams() throws VaultException { @Test public void testHealth_WonkyActiveCode() throws VaultException { final HealthResponse response = vault.debug().health(null, 204, null, - null); + null, null, null, null, null); assertNull(response.getInitialized()); assertNull(response.getSealed()); assertNull(response.getStandby()); assertNull(response.getServerTimeUTC()); + assertNull(response.getPerformanceStandby()); + assertNull(response.getReplicationDrMode()); + assertNull(response.getReplicationPerformanceMode()); assertEquals(204, response.getRestResponse().getStatus()); } + + @Test + public void testHealth_WonkySealedCode() throws VaultException { + vault.seal().seal(); + final HealthResponse response = vault.debug().health(null, null, null, + 900, null, null, null, null); + assertTrue(response.getInitialized()); + assertTrue(response.getSealed()); + assertTrue(response.getStandby()); + assertNotNull(response.getServerTimeUTC()); + assertFalse(response.getPerformanceStandby()); + assertNotNull(response.getReplicationDrMode()); + assertNotNull(response.getReplicationPerformanceMode()); + assertEquals(900, response.getRestResponse().getStatus()); + container.getRootVault().seal().unseal(container.getUnsealKey()); + } } diff --git a/src/test/java/com/bettercloud/vault/RetryTests.java b/src/test/java/com/bettercloud/vault/RetryTests.java index 8779ed6f..4e7cd0b1 100644 --- a/src/test/java/com/bettercloud/vault/RetryTests.java +++ b/src/test/java/com/bettercloud/vault/RetryTests.java @@ -9,7 +9,6 @@ import java.util.HashMap; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** *Unit tests for the Vault driver, having no dependency on an actual Vault server instance being available. The
diff --git a/src/test/java/com/bettercloud/vault/VaultConfigTests.java b/src/test/java/com/bettercloud/vault/VaultConfigTests.java
index a4cec99e..3e159941 100644
--- a/src/test/java/com/bettercloud/vault/VaultConfigTests.java
+++ b/src/test/java/com/bettercloud/vault/VaultConfigTests.java
@@ -72,7 +72,7 @@ public String loadVariable(final String name) {
try {
final byte[] bytes = Files.readAllBytes(Paths.get(mockHomeDirectory).resolve(".vault-token"));
value = new String(bytes, StandardCharsets.UTF_8).trim();
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
} else {
@@ -154,8 +154,8 @@ public void testConfigBuilder_LoadFromEnv() throws VaultException {
assertEquals("http://127.0.0.1:8200", config.getAddress());
assertEquals("c24e2469-298a-6c64-6a71-5b47c9ba459a", config.getToken());
assertTrue(config.getSslConfig().isVerify());
- assertTrue(30 == config.getOpenTimeout());
- assertTrue(30 == config.getReadTimeout());
+ assertEquals(30, (int) config.getOpenTimeout());
+ assertEquals(30, (int) config.getReadTimeout());
}
@Test
diff --git a/src/test/java/com/bettercloud/vault/api/pki/CredentialTests.java b/src/test/java/com/bettercloud/vault/api/pki/CredentialTests.java
index 4cc2486a..4b947c36 100644
--- a/src/test/java/com/bettercloud/vault/api/pki/CredentialTests.java
+++ b/src/test/java/com/bettercloud/vault/api/pki/CredentialTests.java
@@ -1,6 +1,5 @@
package com.bettercloud.vault.api.pki;
-import com.bettercloud.vault.api.pki.Credential;
import org.junit.Assert;
import org.junit.Test;
diff --git a/src/test/java/com/bettercloud/vault/api/pki/RoleOptionsTests.java b/src/test/java/com/bettercloud/vault/api/pki/RoleOptionsTests.java
index 44560bfb..02ab478a 100644
--- a/src/test/java/com/bettercloud/vault/api/pki/RoleOptionsTests.java
+++ b/src/test/java/com/bettercloud/vault/api/pki/RoleOptionsTests.java
@@ -12,7 +12,7 @@ public void RoleOptionsTests() {
RoleOptions roleOptions = new RoleOptions();
Assert.assertNotNull(roleOptions);
- Assert.assertEquals(roleOptions.getAllowedDomains(), null);
+ Assert.assertNull(roleOptions.getAllowedDomains());
roleOptions.allowAnyName(true);
roleOptions.allowBareDomains(true);
diff --git a/src/test/java/com/bettercloud/vault/json/JsonArray_Test.java b/src/test/java/com/bettercloud/vault/json/JsonArray_Test.java
index f1e51033..e834e08f 100644
--- a/src/test/java/com/bettercloud/vault/json/JsonArray_Test.java
+++ b/src/test/java/com/bettercloud/vault/json/JsonArray_Test.java
@@ -21,13 +21,11 @@
******************************************************************************/
package com.bettercloud.vault.json;
-import static com.bettercloud.vault.json.TestUtil.assertException;
import static org.junit.Assert.*;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import java.io.IOException;
-import java.io.StringReader;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
diff --git a/src/test/java/com/bettercloud/vault/json/JsonNumber_Test.java b/src/test/java/com/bettercloud/vault/json/JsonNumber_Test.java
index 04f578ba..9978fe90 100644
--- a/src/test/java/com/bettercloud/vault/json/JsonNumber_Test.java
+++ b/src/test/java/com/bettercloud/vault/json/JsonNumber_Test.java
@@ -45,11 +45,7 @@ public void setUp() {
@Test
public void constructor_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "string is null", new Runnable() {
- public void run() {
- new JsonNumber(null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "string is null", (Runnable) () -> new JsonNumber(null));
}
@Test
diff --git a/src/test/java/com/bettercloud/vault/json/Json_Test.java b/src/test/java/com/bettercloud/vault/json/Json_Test.java
index d8455f83..67fe3afa 100644
--- a/src/test/java/com/bettercloud/vault/json/Json_Test.java
+++ b/src/test/java/com/bettercloud/vault/json/Json_Test.java
@@ -54,7 +54,7 @@ public void value_int() {
@Test
public void value_long() {
- assertEquals("0", Json.value(0l).toString());
+ assertEquals("0", Json.value(0L).toString());
assertEquals("9223372036854775807", Json.value(Long.MAX_VALUE).toString());
assertEquals("-9223372036854775808", Json.value(Long.MIN_VALUE).toString());
}
@@ -77,21 +77,13 @@ public void value_float_cutsOffPointZero() {
@Test
public void value_float_failsWithInfinity() {
String message = "Infinite and NaN values not permitted in JSON";
- assertException(IllegalArgumentException.class, message, new Runnable() {
- public void run() {
- Json.value(Float.POSITIVE_INFINITY);
- }
- });
+ assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.value(Float.POSITIVE_INFINITY));
}
@Test
public void value_float_failsWithNaN() {
String message = "Infinite and NaN values not permitted in JSON";
- assertException(IllegalArgumentException.class, message, new Runnable() {
- public void run() {
- Json.value(Float.NaN);
- }
- });
+ assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.value(Float.NaN));
}
@Test
@@ -112,21 +104,13 @@ public void value_double_cutsOffPointZero() {
@Test
public void value_double_failsWithInfinity() {
String message = "Infinite and NaN values not permitted in JSON";
- assertException(IllegalArgumentException.class, message, new Runnable() {
- public void run() {
- Json.value(Double.POSITIVE_INFINITY);
- }
- });
+ assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.value(Double.POSITIVE_INFINITY));
}
@Test
public void value_double_failsWithNaN() {
String message = "Infinite and NaN values not permitted in JSON";
- assertException(IllegalArgumentException.class, message, new Runnable() {
- public void run() {
- Json.value(Double.NaN);
- }
- });
+ assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.value(Double.NaN));
}
@Test
@@ -160,26 +144,18 @@ public void array_int() {
@Test
public void array_int_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "values is null", new Runnable() {
- public void run() {
- Json.array((int[]) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "values is null", (Runnable) () -> Json.array((int[]) null));
}
@Test
public void array_long() {
- assertEquals(new JsonArray().add(23l), Json.array(23l));
- assertEquals(new JsonArray().add(23l).add(42l), Json.array(23l, 42l));
+ assertEquals(new JsonArray().add(23L), Json.array(23L));
+ assertEquals(new JsonArray().add(23L).add(42L), Json.array(23L, 42L));
}
@Test
public void array_long_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "values is null", new Runnable() {
- public void run() {
- Json.array((long[]) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "values is null", (Runnable) () -> Json.array((long[]) null));
}
@Test
@@ -190,11 +166,7 @@ public void array_float() {
@Test
public void array_float_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "values is null", new Runnable() {
- public void run() {
- Json.array((float[]) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "values is null", (Runnable) () -> Json.array((float[]) null));
}
@Test
@@ -205,11 +177,7 @@ public void array_double() {
@Test
public void array_double_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "values is null", new Runnable() {
- public void run() {
- Json.array((double[]) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "values is null", (Runnable) () -> Json.array((double[]) null));
}
@Test
@@ -220,11 +188,7 @@ public void array_boolean() {
@Test
public void array_boolean_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "values is null", new Runnable() {
- public void run() {
- Json.array((boolean[]) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "values is null", (Runnable) () -> Json.array((boolean[]) null));
}
@Test
@@ -235,11 +199,7 @@ public void array_string() {
@Test
public void array_string_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "values is null", new Runnable() {
- public void run() {
- Json.array((String[]) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "values is null", (Runnable) () -> Json.array((String[]) null));
}
@Test
@@ -254,11 +214,7 @@ public void parse_string() {
@Test
public void parse_string_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "string is null", new Runnable() {
- public void run() {
- Json.parse((String) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "string is null", (Runnable) () -> Json.parse((String) null));
}
@Test
@@ -270,11 +226,7 @@ public void parse_reader() throws IOException {
@Test
public void parse_reader_failsWithNull() {
- TestUtil.assertException(NullPointerException.class, "reader is null", new RunnableEx() {
- public void run() throws IOException {
- Json.parse((Reader) null);
- }
- });
+ TestUtil.assertException(NullPointerException.class, "reader is null", (RunnableEx) () -> Json.parse((Reader) null));
}
}
diff --git a/src/test/java/com/bettercloud/vault/vault/mock/AuthRequestValidatingMockVault.java b/src/test/java/com/bettercloud/vault/vault/mock/AuthRequestValidatingMockVault.java
index e3d5cb95..2c0b3cfb 100644
--- a/src/test/java/com/bettercloud/vault/vault/mock/AuthRequestValidatingMockVault.java
+++ b/src/test/java/com/bettercloud/vault/vault/mock/AuthRequestValidatingMockVault.java
@@ -10,26 +10,6 @@
public class AuthRequestValidatingMockVault extends MockVault {
private Predicate