test: use assertThrows instead of try-catch blocks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2b0f458da3
commit
76a5ea4fe9
@ -30,6 +30,7 @@ import org.apache.http.message.BasicStatusLine;
|
|||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.function.Executable;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -44,7 +45,8 @@ import static org.hamcrest.CoreMatchers.instanceOf;
|
|||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.core.Is.is;
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@ -85,35 +87,32 @@ class HTTPVaultConnectorOfflineTest {
|
|||||||
// Test invalid response code.
|
// Test invalid response code.
|
||||||
final int responseCode = 400;
|
final int responseCode = 400;
|
||||||
mockResponse(responseCode, "", ContentType.APPLICATION_JSON);
|
mockResponse(responseCode, "", ContentType.APPLICATION_JSON);
|
||||||
try {
|
InvalidResponseException e = assertThrows(
|
||||||
connector.getHealth();
|
InvalidResponseException.class,
|
||||||
fail("Querying health status succeeded on invalid instance");
|
connector::getHealth,
|
||||||
} catch (Exception e) {
|
"Querying health status succeeded on invalid instance"
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Invalid response code"));
|
assertThat("Unexpected exception message", e.getMessage(), is("Invalid response code"));
|
||||||
assertThat("Unexpected status code in exception", ((InvalidResponseException) e).getStatusCode(), is(responseCode));
|
assertThat("Unexpected status code in exception", ((InvalidResponseException) e).getStatusCode(), is(responseCode));
|
||||||
assertThat("Response message where none was expected", ((InvalidResponseException) e).getResponse(), is(nullValue()));
|
assertThat("Response message where none was expected", ((InvalidResponseException) e).getResponse(), is(nullValue()));
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate permission denied response.
|
// Simulate permission denied response.
|
||||||
mockResponse(responseCode, "{\"errors\":[\"permission denied\"]}", ContentType.APPLICATION_JSON);
|
mockResponse(responseCode, "{\"errors\":[\"permission denied\"]}", ContentType.APPLICATION_JSON);
|
||||||
try {
|
assertThrows(
|
||||||
connector.getHealth();
|
PermissionDeniedException.class,
|
||||||
fail("Querying health status succeeded on invalid instance");
|
connector::getHealth,
|
||||||
} catch (Exception e) {
|
"Querying health status succeeded on invalid instance"
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(PermissionDeniedException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
// Test exception thrown during request.
|
// Test exception thrown during request.
|
||||||
when(httpMock.execute(any())).thenThrow(new IOException("Test Exception"));
|
when(httpMock.execute(any())).thenThrow(new IOException("Test Exception"));
|
||||||
try {
|
e = assertThrows(
|
||||||
connector.getHealth();
|
InvalidResponseException.class,
|
||||||
fail("Querying health status succeeded on invalid instance");
|
connector::getHealth,
|
||||||
} catch (Exception e) {
|
"Querying health status succeeded on invalid instance"
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Unable to read response"));
|
assertThat("Unexpected exception message", e.getMessage(), is("Unable to read response"));
|
||||||
assertThat("Unexpected cause", e.getCause(), instanceOf(IOException.class));
|
assertThat("Unexpected cause", e.getCause(), instanceOf(IOException.class));
|
||||||
}
|
|
||||||
|
|
||||||
// Now simulate a failing request that succeeds on second try.
|
// Now simulate a failing request that succeeds on second try.
|
||||||
connector = new HTTPVaultConnector("https://127.0.0.1", null, 1, 250);
|
connector = new HTTPVaultConnector("https://127.0.0.1", null, 1, 250);
|
||||||
@ -125,11 +124,7 @@ class HTTPVaultConnectorOfflineTest {
|
|||||||
.when(responseMock).getStatusLine();
|
.when(responseMock).getStatusLine();
|
||||||
when(responseMock.getEntity()).thenReturn(new StringEntity("{}", ContentType.APPLICATION_JSON));
|
when(responseMock.getEntity()).thenReturn(new StringEntity("{}", ContentType.APPLICATION_JSON));
|
||||||
|
|
||||||
try {
|
assertDoesNotThrow(connector::getHealth, "Request failed unexpectedly");
|
||||||
connector.getHealth();
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail("Request failed unexpectedly: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,53 +183,46 @@ class HTTPVaultConnectorOfflineTest {
|
|||||||
* This test is designed to test exceptions caught and thrown by seal-methods if Vault is not reachable.
|
* This test is designed to test exceptions caught and thrown by seal-methods if Vault is not reachable.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void sealExceptionTest() throws IOException {
|
void sealExceptionTest() {
|
||||||
HTTPVaultConnector connector = new HTTPVaultConnector(INVALID_URL);
|
HTTPVaultConnector connector = new HTTPVaultConnector(INVALID_URL);
|
||||||
try {
|
VaultConnectorException e = assertThrows(
|
||||||
connector.sealStatus();
|
InvalidRequestException.class,
|
||||||
fail("Querying seal status succeeded on invalid URL");
|
connector::sealStatus,
|
||||||
} catch (Exception e) {
|
"Querying seal status succeeded on invalid URL"
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidRequestException.class));
|
);
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Invalid URI format"));
|
assertThat("Unexpected exception message", e.getMessage(), is("Invalid URI format"));
|
||||||
}
|
|
||||||
|
|
||||||
connector = new HTTPVaultConnector("https://127.0.0.1", null, 0, 250);
|
|
||||||
|
|
||||||
// Simulate NULL response (mock not supplied with data).
|
// Simulate NULL response (mock not supplied with data).
|
||||||
|
connector = new HTTPVaultConnector("https://127.0.0.1", null, 0, 250);
|
||||||
try {
|
e = assertThrows(
|
||||||
connector.sealStatus();
|
InvalidResponseException.class,
|
||||||
fail("Querying seal status succeeded on invalid instance");
|
connector::sealStatus,
|
||||||
} catch (Exception e) {
|
"Querying seal status succeeded on invalid instance"
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Response unavailable"));
|
assertThat("Unexpected exception message", e.getMessage(), is("Response unavailable"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test is designed to test exceptions caught and thrown by seal-methods if Vault is not reachable.
|
* This test is designed to test exceptions caught and thrown by seal-methods if Vault is not reachable.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void healthExceptionTest() throws IOException {
|
void healthExceptionTest() {
|
||||||
HTTPVaultConnector connector = new HTTPVaultConnector(INVALID_URL);
|
HTTPVaultConnector connector = new HTTPVaultConnector(INVALID_URL);
|
||||||
try {
|
VaultConnectorException e = assertThrows(
|
||||||
connector.getHealth();
|
InvalidRequestException.class,
|
||||||
fail("Querying health status succeeded on invalid URL");
|
connector::getHealth,
|
||||||
} catch (Exception e) {
|
"Querying health status succeeded on invalid URL"
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidRequestException.class));
|
);
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Invalid URI format"));
|
assertThat("Unexpected exception message", e.getMessage(), is("Invalid URI format"));
|
||||||
}
|
|
||||||
|
|
||||||
connector = new HTTPVaultConnector("https://127.0.0.1", null, 0, 250);
|
|
||||||
|
|
||||||
// Simulate NULL response (mock not supplied with data).
|
// Simulate NULL response (mock not supplied with data).
|
||||||
try {
|
connector = new HTTPVaultConnector("https://127.0.0.1", null, 0, 250);
|
||||||
connector.getHealth();
|
e = assertThrows(
|
||||||
fail("Querying health status succeeded on invalid instance");
|
InvalidResponseException.class,
|
||||||
} catch (Exception e) {
|
connector::getHealth,
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidResponseException.class));
|
"Querying health status succeeded on invalid instance"
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Response unavailable"));
|
);
|
||||||
}
|
assertThat("Unexpected exception message", e.getMessage(), is("Response unavailable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,114 +237,25 @@ class HTTPVaultConnectorOfflineTest {
|
|||||||
mockResponse(200, "invalid", ContentType.APPLICATION_JSON);
|
mockResponse(200, "invalid", ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
// Now test the methods.
|
// Now test the methods.
|
||||||
try {
|
assertParseError(connector::sealStatus, "sealStatus() succeeded on invalid instance");
|
||||||
connector.sealStatus();
|
assertParseError(() -> connector.unseal("key"), "unseal() succeeded on invalid instance");
|
||||||
fail("sealStatus() succeeded on invalid instance");
|
assertParseError(connector::getHealth, "getHealth() succeeded on invalid instance");
|
||||||
} catch (Exception e) {
|
assertParseError(connector::getAuthBackends, "getAuthBackends() succeeded on invalid instance");
|
||||||
assertParseError(e);
|
assertParseError(() -> connector.authToken("token"), "authToken() succeeded on invalid instance");
|
||||||
}
|
assertParseError(() -> connector.lookupAppRole("roleName"), "lookupAppRole() succeeded on invalid instance");
|
||||||
|
assertParseError(() -> connector.getAppRoleID("roleName"), "getAppRoleID() succeeded on invalid instance");
|
||||||
try {
|
assertParseError(() -> connector.createAppRoleSecret("roleName"), "createAppRoleSecret() succeeded on invalid instance");
|
||||||
connector.unseal("key");
|
assertParseError(() -> connector.lookupAppRoleSecret("roleName", "secretID"), "lookupAppRoleSecret() succeeded on invalid instance");
|
||||||
fail("unseal() succeeded on invalid instance");
|
assertParseError(connector::listAppRoles, "listAppRoles() succeeded on invalid instance");
|
||||||
} catch (Exception e) {
|
assertParseError(() -> connector.listAppRoleSecrets("roleName"), "listAppRoleSecrets() succeeded on invalid instance");
|
||||||
assertParseError(e);
|
assertParseError(() -> connector.read("key"), "read() succeeded on invalid instance");
|
||||||
}
|
assertParseError(() -> connector.list("path"), "list() succeeded on invalid instance");
|
||||||
|
assertParseError(() -> connector.renew("leaseID"), "renew() succeeded on invalid instance");
|
||||||
try {
|
assertParseError(() -> connector.lookupToken("token"), "lookupToken() succeeded on invalid instance");
|
||||||
connector.getHealth();
|
|
||||||
fail("getHealth() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.getAuthBackends();
|
|
||||||
fail("getAuthBackends() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.authToken("token");
|
|
||||||
fail("authToken() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.lookupAppRole("roleName");
|
|
||||||
fail("lookupAppRole() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.getAppRoleID("roleName");
|
|
||||||
fail("getAppRoleID() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.createAppRoleSecret("roleName");
|
|
||||||
fail("createAppRoleSecret() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.lookupAppRoleSecret("roleName", "secretID");
|
|
||||||
fail("lookupAppRoleSecret() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.listAppRoles();
|
|
||||||
fail("listAppRoles() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.listAppRoleSecrets("roleName");
|
|
||||||
fail("listAppRoleSecrets() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.read("key");
|
|
||||||
fail("read() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.list("path");
|
|
||||||
fail("list() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.renew("leaseID");
|
|
||||||
fail("renew() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connector.lookupToken("token");
|
|
||||||
fail("lookupToken() succeeded on invalid instance");
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertParseError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertParseError(Exception e) {
|
private void assertParseError(Executable executable, String message) {
|
||||||
assertThat("Unexpected type of exception", e, instanceOf(InvalidResponseException.class));
|
InvalidResponseException e = assertThrows(InvalidResponseException.class, executable, message);
|
||||||
assertThat("Unexpected exception message", e.getMessage(), is("Unable to parse response"));
|
assertThat("Unexpected exception message", e.getMessage(), is("Unable to parse response"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,68 +271,59 @@ class HTTPVaultConnectorOfflineTest {
|
|||||||
mockResponse(200, "{}", ContentType.APPLICATION_JSON);
|
mockResponse(200, "{}", ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
// Now test the methods expecting a 204.
|
// Now test the methods expecting a 204.
|
||||||
try {
|
assertThrows(
|
||||||
connector.registerAppId("appID", "policy", "displayName");
|
InvalidResponseException.class,
|
||||||
fail("registerAppId() with 200 response succeeded");
|
() -> connector.registerAppId("appID", "policy", "displayName"),
|
||||||
} catch (VaultConnectorException e) {
|
"registerAppId() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.registerUserId("appID", "userID");
|
InvalidResponseException.class,
|
||||||
fail("registerUserId() with 200 response succeeded");
|
() -> connector.registerUserId("appID", "userID"),
|
||||||
} catch (VaultConnectorException e) {
|
"registerUserId() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.createAppRole("appID", Collections.singletonList("policy"));
|
InvalidResponseException.class,
|
||||||
fail("createAppRole() with 200 response succeeded");
|
() -> connector.createAppRole("appID", Collections.singletonList("policy")),
|
||||||
} catch (VaultConnectorException e) {
|
"createAppRole() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.deleteAppRole("roleName");
|
InvalidResponseException.class,
|
||||||
fail("deleteAppRole() with 200 response succeeded");
|
() -> connector.deleteAppRole("roleName"),
|
||||||
} catch (VaultConnectorException e) {
|
"deleteAppRole() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.setAppRoleID("roleName", "roleID");
|
InvalidResponseException.class,
|
||||||
fail("setAppRoleID() with 200 response succeeded");
|
() -> connector.setAppRoleID("roleName", "roleID"),
|
||||||
} catch (VaultConnectorException e) {
|
"setAppRoleID() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.destroyAppRoleSecret("roleName", "secretID");
|
InvalidResponseException.class,
|
||||||
fail("destroyAppRoleSecret() with 200 response succeeded");
|
() -> connector.destroyAppRoleSecret("roleName", "secretID"),
|
||||||
} catch (VaultConnectorException e) {
|
"destroyAppRoleSecret() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.destroyAppRoleSecret("roleName", "secretUD");
|
InvalidResponseException.class,
|
||||||
fail("destroyAppRoleSecret() with 200 response succeeded");
|
() -> connector.destroyAppRoleSecret("roleName", "secretUD"),
|
||||||
} catch (VaultConnectorException e) {
|
"destroyAppRoleSecret() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.delete("key");
|
InvalidResponseException.class,
|
||||||
fail("delete() with 200 response succeeded");
|
() -> connector.delete("key"),
|
||||||
} catch (VaultConnectorException e) {
|
"delete() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
connector.revoke("leaseID");
|
InvalidResponseException.class,
|
||||||
fail("destroyAppRoleSecret() with 200 response succeeded");
|
() -> connector.revoke("leaseID"),
|
||||||
} catch (VaultConnectorException e) {
|
"destroyAppRoleSecret() with 200 response succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) {
|
private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,6 @@ package de.stklcode.jvault.connector.builder;
|
|||||||
|
|
||||||
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
||||||
import de.stklcode.jvault.connector.exception.TlsException;
|
import de.stklcode.jvault.connector.exception.TlsException;
|
||||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
|
||||||
import de.stklcode.jvault.connector.test.EnvironmentMock;
|
import de.stklcode.jvault.connector.test.EnvironmentMock;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
@ -30,7 +29,8 @@ import java.nio.file.NoSuchFileException;
|
|||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit test for HTTP Vault connector factory
|
* JUnit test for HTTP Vault connector factory
|
||||||
@ -53,15 +53,11 @@ class HTTPVaultConnectorBuilderTest {
|
|||||||
void testFromEnv() throws NoSuchFieldException, IllegalAccessException, IOException {
|
void testFromEnv() throws NoSuchFieldException, IllegalAccessException, IOException {
|
||||||
/* Provide address only should be enough */
|
/* Provide address only should be enough */
|
||||||
setenv(VAULT_ADDR, null, null, null);
|
setenv(VAULT_ADDR, null, null, null);
|
||||||
|
HTTPVaultConnectorBuilder factory = assertDoesNotThrow(
|
||||||
HTTPVaultConnectorBuilder factory = null;
|
() -> VaultConnectorBuilder.http().fromEnv(),
|
||||||
HTTPVaultConnector connector;
|
"Factory creation from minimal environment failed"
|
||||||
try {
|
);
|
||||||
factory = VaultConnectorBuilder.http().fromEnv();
|
HTTPVaultConnector connector = factory.build();
|
||||||
} catch (VaultConnectorException e) {
|
|
||||||
fail("Factory creation from minimal environment failed");
|
|
||||||
}
|
|
||||||
connector = factory.build();
|
|
||||||
|
|
||||||
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
||||||
assertThat("Trusted CA cert set when no cert provided", getRequestHelperPrivate(connector, "trustedCaCert"), is(nullValue()));
|
assertThat("Trusted CA cert set when no cert provided", getRequestHelperPrivate(connector, "trustedCaCert"), is(nullValue()));
|
||||||
@ -70,11 +66,10 @@ class HTTPVaultConnectorBuilderTest {
|
|||||||
/* Provide address and number of retries */
|
/* Provide address and number of retries */
|
||||||
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), null);
|
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), null);
|
||||||
|
|
||||||
try {
|
factory = assertDoesNotThrow(
|
||||||
factory = VaultConnectorBuilder.http().fromEnv();
|
() -> VaultConnectorBuilder.http().fromEnv(),
|
||||||
} catch (VaultConnectorException e) {
|
"Factory creation from environment failed"
|
||||||
fail("Factory creation from environment failed");
|
);
|
||||||
}
|
|
||||||
connector = factory.build();
|
connector = factory.build();
|
||||||
|
|
||||||
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
||||||
@ -85,23 +80,21 @@ class HTTPVaultConnectorBuilderTest {
|
|||||||
String VAULT_CACERT = tempDir.toString() + "/doesnotexist";
|
String VAULT_CACERT = tempDir.toString() + "/doesnotexist";
|
||||||
setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null);
|
setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null);
|
||||||
|
|
||||||
try {
|
TlsException e = assertThrows(
|
||||||
VaultConnectorBuilder.http().fromEnv();
|
TlsException.class,
|
||||||
fail("Creation with unknown cert path failed.");
|
() -> VaultConnectorBuilder.http().fromEnv(),
|
||||||
} catch (VaultConnectorException e) {
|
"Creation with unknown cert path failed."
|
||||||
assertThat(e, is(instanceOf(TlsException.class)));
|
);
|
||||||
assertThat(e.getCause(), is(instanceOf(NoSuchFileException.class)));
|
assertThat(e.getCause(), is(instanceOf(NoSuchFileException.class)));
|
||||||
assertThat(((NoSuchFileException) e.getCause()).getFile(), is(VAULT_CACERT));
|
assertThat(((NoSuchFileException) e.getCause()).getFile(), is(VAULT_CACERT));
|
||||||
}
|
|
||||||
|
|
||||||
/* Automatic authentication */
|
/* Automatic authentication */
|
||||||
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), VAULT_TOKEN);
|
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), VAULT_TOKEN);
|
||||||
|
|
||||||
try {
|
factory = assertDoesNotThrow(
|
||||||
factory = VaultConnectorBuilder.http().fromEnv();
|
() -> VaultConnectorBuilder.http().fromEnv(),
|
||||||
} catch (VaultConnectorException e) {
|
"Factory creation from minimal environment failed"
|
||||||
fail("Factory creation from minimal environment failed");
|
);
|
||||||
}
|
|
||||||
assertThat("Token nor set correctly", getPrivate(factory, "token"), is(equalTo(VAULT_TOKEN)));
|
assertThat("Token nor set correctly", getPrivate(factory, "token"), is(equalTo(VAULT_TOKEN)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package de.stklcode.jvault.connector.factory;
|
|||||||
|
|
||||||
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
||||||
import de.stklcode.jvault.connector.exception.TlsException;
|
import de.stklcode.jvault.connector.exception.TlsException;
|
||||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
|
||||||
import de.stklcode.jvault.connector.test.EnvironmentMock;
|
import de.stklcode.jvault.connector.test.EnvironmentMock;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
@ -30,7 +29,8 @@ import java.nio.file.NoSuchFileException;
|
|||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit test for HTTP Vault connector factory
|
* JUnit test for HTTP Vault connector factory
|
||||||
@ -54,14 +54,11 @@ class HTTPVaultConnectorFactoryTest {
|
|||||||
/* Provide address only should be enough */
|
/* Provide address only should be enough */
|
||||||
setenv(VAULT_ADDR, null, null, null);
|
setenv(VAULT_ADDR, null, null, null);
|
||||||
|
|
||||||
HTTPVaultConnectorFactory factory = null;
|
HTTPVaultConnectorFactory factory = assertDoesNotThrow(
|
||||||
HTTPVaultConnector connector;
|
() -> VaultConnectorFactory.httpFactory().fromEnv(),
|
||||||
try {
|
"Factory creation from minimal environment failed"
|
||||||
factory = VaultConnectorFactory.httpFactory().fromEnv();
|
);
|
||||||
} catch (VaultConnectorException e) {
|
HTTPVaultConnector connector = factory.build();
|
||||||
fail("Factory creation from minimal environment failed");
|
|
||||||
}
|
|
||||||
connector = factory.build();
|
|
||||||
|
|
||||||
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
||||||
assertThat("Trusted CA cert set when no cert provided", getRequestHelperPrivate(connector, "trustedCaCert"), is(nullValue()));
|
assertThat("Trusted CA cert set when no cert provided", getRequestHelperPrivate(connector, "trustedCaCert"), is(nullValue()));
|
||||||
@ -70,11 +67,10 @@ class HTTPVaultConnectorFactoryTest {
|
|||||||
/* Provide address and number of retries */
|
/* Provide address and number of retries */
|
||||||
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), null);
|
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), null);
|
||||||
|
|
||||||
try {
|
factory = assertDoesNotThrow(
|
||||||
factory = VaultConnectorFactory.httpFactory().fromEnv();
|
() -> VaultConnectorFactory.httpFactory().fromEnv(),
|
||||||
} catch (VaultConnectorException e) {
|
"Factory creation from environment failed"
|
||||||
fail("Factory creation from environment failed");
|
);
|
||||||
}
|
|
||||||
connector = factory.build();
|
connector = factory.build();
|
||||||
|
|
||||||
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/")));
|
||||||
@ -85,23 +81,21 @@ class HTTPVaultConnectorFactoryTest {
|
|||||||
String VAULT_CACERT = tempDir.toString() + "/doesnotexist";
|
String VAULT_CACERT = tempDir.toString() + "/doesnotexist";
|
||||||
setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null);
|
setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null);
|
||||||
|
|
||||||
try {
|
TlsException e = assertThrows(
|
||||||
VaultConnectorFactory.httpFactory().fromEnv();
|
TlsException.class,
|
||||||
fail("Creation with unknown cert path failed.");
|
() -> VaultConnectorFactory.httpFactory().fromEnv(),
|
||||||
} catch (VaultConnectorException e) {
|
"Creation with unknown cert path failed."
|
||||||
assertThat(e, is(instanceOf(TlsException.class)));
|
);
|
||||||
assertThat(e.getCause(), is(instanceOf(NoSuchFileException.class)));
|
assertThat(e.getCause(), is(instanceOf(NoSuchFileException.class)));
|
||||||
assertThat(((NoSuchFileException) e.getCause()).getFile(), is(VAULT_CACERT));
|
assertThat(((NoSuchFileException) e.getCause()).getFile(), is(VAULT_CACERT));
|
||||||
}
|
|
||||||
|
|
||||||
/* Automatic authentication */
|
/* Automatic authentication */
|
||||||
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), VAULT_TOKEN);
|
setenv(VAULT_ADDR, null, VAULT_MAX_RETRIES.toString(), VAULT_TOKEN);
|
||||||
|
|
||||||
try {
|
factory = assertDoesNotThrow(
|
||||||
factory = VaultConnectorFactory.httpFactory().fromEnv();
|
() -> VaultConnectorFactory.httpFactory().fromEnv(),
|
||||||
} catch (VaultConnectorException e) {
|
"Factory creation from minimal environment failed"
|
||||||
fail("Factory creation from minimal environment failed");
|
);
|
||||||
}
|
|
||||||
assertThat("Token nor set correctly", getPrivate(getPrivate(factory, "delegate"), "token"), is(equalTo(VAULT_TOKEN)));
|
assertThat("Token nor set correctly", getPrivate(getPrivate(factory, "delegate"), "token"), is(equalTo(VAULT_TOKEN)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -29,7 +27,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||||
|
|
||||||
|
|
||||||
@ -120,26 +118,17 @@ class AppRoleSecretTest {
|
|||||||
|
|
||||||
/* A simple roundtrip first. All set fields should be present afterwards. */
|
/* A simple roundtrip first. All set fields should be present afterwards. */
|
||||||
AppRoleSecret secret = new AppRoleSecret(TEST_ID, TEST_META, TEST_CIDR);
|
AppRoleSecret secret = new AppRoleSecret(TEST_ID, TEST_META, TEST_CIDR);
|
||||||
String secretJson = "";
|
String secretJson = assertDoesNotThrow(() -> mapper.writeValueAsString(secret), "Serialization failed");
|
||||||
try {
|
|
||||||
secretJson = mapper.writeValueAsString(secret);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
fail("Serialization failed");
|
|
||||||
}
|
|
||||||
/* CIDR list is comma-separated when used as input, but List otherwise, hence convert string to list */
|
/* CIDR list is comma-separated when used as input, but List otherwise, hence convert string to list */
|
||||||
secretJson = commaSeparatedToList(secretJson);
|
String secretJson2 = commaSeparatedToList(secretJson);
|
||||||
|
|
||||||
AppRoleSecret secret2;
|
AppRoleSecret secret2 = assertDoesNotThrow(
|
||||||
try {
|
() -> mapper.readValue(secretJson2, AppRoleSecret.class),
|
||||||
secret2 = mapper.readValue(secretJson, AppRoleSecret.class);
|
"Deserialization failed"
|
||||||
assertThat(secret.getId(), is(secret2.getId()));
|
);
|
||||||
assertThat(secret.getMetadata(), is(secret2.getMetadata()));
|
assertThat(secret.getId(), is(secret2.getId()));
|
||||||
assertThat(secret.getCidrList(), is(secret2.getCidrList()));
|
assertThat(secret.getMetadata(), is(secret2.getMetadata()));
|
||||||
} catch (IOException e) {
|
assertThat(secret.getCidrList(), is(secret2.getCidrList()));
|
||||||
e.printStackTrace();
|
|
||||||
fail("Deserialization failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test fields, that should not be written to JSON */
|
/* Test fields, that should not be written to JSON */
|
||||||
setPrivateField(secret, "accessor", "TEST_ACCESSOR");
|
setPrivateField(secret, "accessor", "TEST_ACCESSOR");
|
||||||
@ -154,45 +143,33 @@ class AppRoleSecretTest {
|
|||||||
assumeTrue(secret.getNumUses() == 678);
|
assumeTrue(secret.getNumUses() == 678);
|
||||||
setPrivateField(secret, "ttl", 12345);
|
setPrivateField(secret, "ttl", 12345);
|
||||||
assumeTrue(secret.getTtl() == 12345);
|
assumeTrue(secret.getTtl() == 12345);
|
||||||
try {
|
String secretJson3 = assertDoesNotThrow(() -> mapper.writeValueAsString(secret), "Serialization failed");
|
||||||
secretJson = mapper.writeValueAsString(secret);
|
secret2 = assertDoesNotThrow(
|
||||||
} catch (JsonProcessingException e) {
|
() -> mapper.readValue(commaSeparatedToList(secretJson3), AppRoleSecret.class),
|
||||||
e.printStackTrace();
|
"Deserialization failed"
|
||||||
fail("Serialization failed");
|
);
|
||||||
}
|
assertThat(secret.getId(), is(secret2.getId()));
|
||||||
try {
|
assertThat(secret.getMetadata(), is(secret2.getMetadata()));
|
||||||
secret2 = mapper.readValue(commaSeparatedToList(secretJson), AppRoleSecret.class);
|
assertThat(secret.getCidrList(), is(secret2.getCidrList()));
|
||||||
assertThat(secret.getId(), is(secret2.getId()));
|
assertThat(secret2.getAccessor(), is(nullValue()));
|
||||||
assertThat(secret.getMetadata(), is(secret2.getMetadata()));
|
assertThat(secret2.getCreationTime(), is(nullValue()));
|
||||||
assertThat(secret.getCidrList(), is(secret2.getCidrList()));
|
assertThat(secret2.getExpirationTime(), is(nullValue()));
|
||||||
assertThat(secret2.getAccessor(), is(nullValue()));
|
assertThat(secret2.getLastUpdatedTime(), is(nullValue()));
|
||||||
assertThat(secret2.getCreationTime(), is(nullValue()));
|
assertThat(secret2.getNumUses(), is(nullValue()));
|
||||||
assertThat(secret2.getExpirationTime(), is(nullValue()));
|
assertThat(secret2.getTtl(), is(nullValue()));
|
||||||
assertThat(secret2.getLastUpdatedTime(), is(nullValue()));
|
|
||||||
assertThat(secret2.getNumUses(), is(nullValue()));
|
|
||||||
assertThat(secret2.getTtl(), is(nullValue()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
fail("Deserialization failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Those fields should be deserialized from JSON though */
|
/* Those fields should be deserialized from JSON though */
|
||||||
secretJson = "{\"secret_id\":\"abc123\",\"metadata\":{\"number\":1337,\"foo\":\"bar\"}," +
|
String secretJson4 = "{\"secret_id\":\"abc123\",\"metadata\":{\"number\":1337,\"foo\":\"bar\"}," +
|
||||||
"\"cidr_list\":[\"203.0.113.0/24\",\"198.51.100.0/24\"],\"secret_id_accessor\":\"TEST_ACCESSOR\"," +
|
"\"cidr_list\":[\"203.0.113.0/24\",\"198.51.100.0/24\"],\"secret_id_accessor\":\"TEST_ACCESSOR\"," +
|
||||||
"\"creation_time\":\"TEST_CREATION\",\"expiration_time\":\"TEST_EXPIRATION\"," +
|
"\"creation_time\":\"TEST_CREATION\",\"expiration_time\":\"TEST_EXPIRATION\"," +
|
||||||
"\"last_updated_time\":\"TEST_LASTUPDATE\",\"secret_id_num_uses\":678,\"secret_id_ttl\":12345}";
|
"\"last_updated_time\":\"TEST_LASTUPDATE\",\"secret_id_num_uses\":678,\"secret_id_ttl\":12345}";
|
||||||
try {
|
secret2 = assertDoesNotThrow(() -> mapper.readValue(secretJson4, AppRoleSecret.class), "Deserialization failed");
|
||||||
secret2 = mapper.readValue(secretJson, AppRoleSecret.class);
|
assertThat(secret2.getAccessor(), is("TEST_ACCESSOR"));
|
||||||
assertThat(secret2.getAccessor(), is("TEST_ACCESSOR"));
|
assertThat(secret2.getCreationTime(), is("TEST_CREATION"));
|
||||||
assertThat(secret2.getCreationTime(), is("TEST_CREATION"));
|
assertThat(secret2.getExpirationTime(), is("TEST_EXPIRATION"));
|
||||||
assertThat(secret2.getExpirationTime(), is("TEST_EXPIRATION"));
|
assertThat(secret2.getLastUpdatedTime(), is("TEST_LASTUPDATE"));
|
||||||
assertThat(secret2.getLastUpdatedTime(), is("TEST_LASTUPDATE"));
|
assertThat(secret2.getNumUses(), is(678));
|
||||||
assertThat(secret2.getNumUses(), is(678));
|
assertThat(secret2.getTtl(), is(12345));
|
||||||
assertThat(secret2.getTtl(), is(12345));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
fail("Deserialization failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
|||||||
import de.stklcode.jvault.connector.model.AppRole;
|
import de.stklcode.jvault.connector.model.AppRole;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link AppRoleResponse} model.
|
* JUnit Test for {@link AppRoleResponse} model.
|
||||||
@ -81,12 +81,11 @@ class AppRoleResponseTest {
|
|||||||
assertThat("Initial data should be empty", res.getRole(), is(nullValue()));
|
assertThat("Initial data should be empty", res.getRole(), is(nullValue()));
|
||||||
|
|
||||||
// Parsing invalid auth data map should fail.
|
// Parsing invalid auth data map should fail.
|
||||||
try {
|
assertThrows(
|
||||||
res.setData(INVALID_DATA);
|
InvalidResponseException.class,
|
||||||
fail("Parsing invalid data succeeded");
|
() -> res.setData(INVALID_DATA),
|
||||||
} catch (Exception e) {
|
"Parsing invalid data succeeded"
|
||||||
assertThat(e, is(instanceOf(InvalidResponseException.class)));
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,27 +93,26 @@ class AppRoleResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
AppRoleResponse res = assertDoesNotThrow(
|
||||||
AppRoleResponse res = new ObjectMapper().readValue(RES_JSON, AppRoleResponse.class);
|
() -> new ObjectMapper().readValue(RES_JSON, AppRoleResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"AuthResponse deserialization failed."
|
||||||
// Extract role data.
|
);
|
||||||
AppRole role = res.getRole();
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Role data is NULL", role, is(notNullValue()));
|
// Extract role data.
|
||||||
assertThat("Incorrect token TTL", role.getTokenTtl(), is(ROLE_TOKEN_TTL));
|
AppRole role = res.getRole();
|
||||||
assertThat("Incorrect token max TTL", role.getTokenMaxTtl(), is(ROLE_TOKEN_MAX_TTL));
|
assertThat("Role data is NULL", role, is(notNullValue()));
|
||||||
assertThat("Incorrect secret ID TTL", role.getSecretIdTtl(), is(ROLE_SECRET_TTL));
|
assertThat("Incorrect token TTL", role.getTokenTtl(), is(ROLE_TOKEN_TTL));
|
||||||
assertThat("Incorrect secret ID umber of uses", role.getSecretIdNumUses(), is(ROLE_SECRET_NUM_USES));
|
assertThat("Incorrect token max TTL", role.getTokenMaxTtl(), is(ROLE_TOKEN_MAX_TTL));
|
||||||
assertThat("Incorrect number of policies", role.getTokenPolicies(), hasSize(1));
|
assertThat("Incorrect secret ID TTL", role.getSecretIdTtl(), is(ROLE_SECRET_TTL));
|
||||||
assertThat("Incorrect role policies", role.getTokenPolicies(), contains(ROLE_POLICY));
|
assertThat("Incorrect secret ID umber of uses", role.getSecretIdNumUses(), is(ROLE_SECRET_NUM_USES));
|
||||||
assertThat("Incorrect number of policies", role.getPolicies(), hasSize(1));
|
assertThat("Incorrect number of policies", role.getTokenPolicies(), hasSize(1));
|
||||||
assertThat("Incorrect role policies", role.getPolicies(), contains(ROLE_POLICY));
|
assertThat("Incorrect role policies", role.getTokenPolicies(), contains(ROLE_POLICY));
|
||||||
assertThat("Incorrect role period", role.getTokenPeriod(), is(ROLE_PERIOD));
|
assertThat("Incorrect number of policies", role.getPolicies(), hasSize(1));
|
||||||
assertThat("Incorrect role period", role.getPeriod(), is(ROLE_PERIOD));
|
assertThat("Incorrect role policies", role.getPolicies(), contains(ROLE_POLICY));
|
||||||
assertThat("Incorrect role bind secret ID flag", role.getBindSecretId(), is(ROLE_BIND_SECRET));
|
assertThat("Incorrect role period", role.getTokenPeriod(), is(ROLE_PERIOD));
|
||||||
assertThat("Incorrect bound CIDR list", role.getTokenBoundCidrs(), is(nullValue()));
|
assertThat("Incorrect role period", role.getPeriod(), is(ROLE_PERIOD));
|
||||||
assertThat("Incorrect bound CIDR list string", role.getTokenBoundCidrsString(), is(emptyString()));
|
assertThat("Incorrect role bind secret ID flag", role.getBindSecretId(), is(ROLE_BIND_SECRET));
|
||||||
} catch (IOException e) {
|
assertThat("Incorrect bound CIDR list", role.getTokenBoundCidrs(), is(nullValue()));
|
||||||
fail("AuthResponse deserialization failed: " + e.getMessage());
|
assertThat("Incorrect bound CIDR list string", role.getTokenBoundCidrsString(), is(emptyString()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,13 @@ import de.stklcode.jvault.connector.model.AuthBackend;
|
|||||||
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link AuthMethodsResponse} model.
|
* JUnit Test for {@link AuthMethodsResponse} model.
|
||||||
@ -79,12 +79,11 @@ class AuthMethodsResponseTest {
|
|||||||
assertThat("Initial method map should be empty", res.getSupportedMethods(), is(anEmptyMap()));
|
assertThat("Initial method map should be empty", res.getSupportedMethods(), is(anEmptyMap()));
|
||||||
|
|
||||||
// Parsing invalid data map should fail.
|
// Parsing invalid data map should fail.
|
||||||
try {
|
assertThrows(
|
||||||
res.setData(INVALID_DATA);
|
InvalidResponseException.class,
|
||||||
fail("Parsing invalid data succeeded");
|
() -> res.setData(INVALID_DATA),
|
||||||
} catch (Exception e) {
|
"Parsing invalid data succeeded"
|
||||||
assertThat(e, is(instanceOf(InvalidResponseException.class)));
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,34 +91,33 @@ class AuthMethodsResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
AuthMethodsResponse res = assertDoesNotThrow(
|
||||||
AuthMethodsResponse res = new ObjectMapper().readValue(RES_JSON, AuthMethodsResponse.class);
|
() -> new ObjectMapper().readValue(RES_JSON, AuthMethodsResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"AuthResponse deserialization failed"
|
||||||
// Extract auth data.
|
);
|
||||||
Map<String, AuthMethod> supported = res.getSupportedMethods();
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Auth data is NULL", supported, is(notNullValue()));
|
// Extract auth data.
|
||||||
assertThat("Incorrect number of supported methods", supported.entrySet(), hasSize(2));
|
Map<String, AuthMethod> supported = res.getSupportedMethods();
|
||||||
assertThat("Incorrect method paths", supported.keySet(), containsInAnyOrder(GH_PATH, TK_PATH));
|
assertThat("Auth data is NULL", supported, is(notNullValue()));
|
||||||
|
assertThat("Incorrect number of supported methods", supported.entrySet(), hasSize(2));
|
||||||
|
assertThat("Incorrect method paths", supported.keySet(), containsInAnyOrder(GH_PATH, TK_PATH));
|
||||||
|
|
||||||
// Verify first method.
|
// Verify first method.
|
||||||
AuthMethod method = supported.get(GH_PATH);
|
AuthMethod method = supported.get(GH_PATH);
|
||||||
assertThat("Incorrect raw type for GitHub", method.getRawType(), is(GH_TYPE));
|
assertThat("Incorrect raw type for GitHub", method.getRawType(), is(GH_TYPE));
|
||||||
assertThat("Incorrect parsed type for GitHub", method.getType(), is(AuthBackend.GITHUB));
|
assertThat("Incorrect parsed type for GitHub", method.getType(), is(AuthBackend.GITHUB));
|
||||||
assertThat("Incorrect description for GitHub", method.getDescription(), is(GH_DESCR));
|
assertThat("Incorrect description for GitHub", method.getDescription(), is(GH_DESCR));
|
||||||
assertThat("Unexpected config for GitHub", method.getConfig(), is(nullValue()));
|
assertThat("Unexpected config for GitHub", method.getConfig(), is(nullValue()));
|
||||||
|
|
||||||
// Verify first method.
|
// Verify first method.
|
||||||
method = supported.get(TK_PATH);
|
method = supported.get(TK_PATH);
|
||||||
assertThat("Incorrect raw type for Token", method.getRawType(), is(TK_TYPE));
|
assertThat("Incorrect raw type for Token", method.getRawType(), is(TK_TYPE));
|
||||||
assertThat("Incorrect parsed type for Token", method.getType(), is(AuthBackend.TOKEN));
|
assertThat("Incorrect parsed type for Token", method.getType(), is(AuthBackend.TOKEN));
|
||||||
assertThat("Incorrect description for Token", method.getDescription(), is(TK_DESCR));
|
assertThat("Incorrect description for Token", method.getDescription(), is(TK_DESCR));
|
||||||
assertThat("Missing config for Token", method.getConfig(), is(notNullValue()));
|
assertThat("Missing config for Token", method.getConfig(), is(notNullValue()));
|
||||||
assertThat("Unexpected config size for Token", method.getConfig().keySet(), hasSize(2));
|
assertThat("Unexpected config size for Token", method.getConfig().keySet(), hasSize(2));
|
||||||
assertThat("Incorrect lease TTL config", method.getConfig().get("default_lease_ttl"), is(TK_LEASE_TTL.toString()));
|
assertThat("Incorrect lease TTL config", method.getConfig().get("default_lease_ttl"), is(TK_LEASE_TTL.toString()));
|
||||||
assertThat("Incorrect max lease TTL config", method.getConfig().get("max_lease_ttl"), is(TK_MAX_LEASE_TTL.toString()));
|
assertThat("Incorrect max lease TTL config", method.getConfig().get("max_lease_ttl"), is(TK_MAX_LEASE_TTL.toString()));
|
||||||
} catch (IOException e) {
|
|
||||||
fail("AuthResponse deserialization failed: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Dummy {
|
private static class Dummy {
|
||||||
|
@ -21,13 +21,13 @@ import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
|||||||
import de.stklcode.jvault.connector.model.response.embedded.AuthData;
|
import de.stklcode.jvault.connector.model.response.embedded.AuthData;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link AuthResponse} model.
|
* JUnit Test for {@link AuthResponse} model.
|
||||||
@ -87,12 +87,11 @@ class AuthResponseTest {
|
|||||||
assertThat("Initial data should be empty", res.getData(), is(nullValue()));
|
assertThat("Initial data should be empty", res.getData(), is(nullValue()));
|
||||||
|
|
||||||
// Parsing invalid auth data map should fail.
|
// Parsing invalid auth data map should fail.
|
||||||
try {
|
assertThrows(
|
||||||
res.setAuth(INVALID_AUTH_DATA);
|
InvalidResponseException.class,
|
||||||
fail("Parsing invalid auth data succeeded");
|
() -> res.setAuth(INVALID_AUTH_DATA),
|
||||||
} catch (Exception e) {
|
"Parsing invalid auth data succeeded"
|
||||||
assertThat(e, is(instanceOf(InvalidResponseException.class)));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
// Data method should be agnostic.
|
// Data method should be agnostic.
|
||||||
res.setData(INVALID_AUTH_DATA);
|
res.setData(INVALID_AUTH_DATA);
|
||||||
@ -104,8 +103,10 @@ class AuthResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
AuthResponse res = assertDoesNotThrow(
|
||||||
AuthResponse res = new ObjectMapper().readValue(RES_JSON, AuthResponse.class);
|
() -> new ObjectMapper().readValue(RES_JSON, AuthResponse.class),
|
||||||
|
"AuthResponse deserialization failed."
|
||||||
|
);
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
// Extract auth data.
|
// Extract auth data.
|
||||||
AuthData data = res.getAuth();
|
AuthData data = res.getAuth();
|
||||||
@ -123,9 +124,5 @@ class AuthResponseTest {
|
|||||||
assertThat("Incorrect token policies", data.getTokenPolicies(), containsInRelativeOrder(AUTH_POLICY_2, AUTH_POLICY_1));
|
assertThat("Incorrect token policies", data.getTokenPolicies(), containsInRelativeOrder(AUTH_POLICY_2, AUTH_POLICY_1));
|
||||||
assertThat("Incorrect auth metadata size", data.getMetadata().entrySet(), hasSize(1));
|
assertThat("Incorrect auth metadata size", data.getMetadata().entrySet(), hasSize(1));
|
||||||
assertThat("Incorrect auth metadata", data.getMetadata().get(AUTH_META_KEY), is(AUTH_META_VALUE));
|
assertThat("Incorrect auth metadata", data.getMetadata().get(AUTH_META_KEY), is(AUTH_META_VALUE));
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
fail("AuthResponse deserialization failed: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,10 @@ package de.stklcode.jvault.connector.model.response;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link AuthResponse} model.
|
* JUnit Test for {@link AuthResponse} model.
|
||||||
@ -56,26 +54,26 @@ class HealthResponseTest {
|
|||||||
" \"replication_dr_mode\": \"" + REPL_DR_MODE + "\",\n" +
|
" \"replication_dr_mode\": \"" + REPL_DR_MODE + "\",\n" +
|
||||||
" \"performance_standby\": " + PERF_STANDBY + "\n" +
|
" \"performance_standby\": " + PERF_STANDBY + "\n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
HealthResponse res = assertDoesNotThrow(
|
||||||
HealthResponse res = new ObjectMapper().readValue(RES_JSON, HealthResponse.class);
|
() -> new ObjectMapper().readValue(RES_JSON, HealthResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"Health deserialization failed."
|
||||||
assertThat("Incorrect cluster ID", res.getClusterID(), is(CLUSTER_ID));
|
);
|
||||||
assertThat("Incorrect cluster name", res.getClusterName(), is(CLUSTER_NAME));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Incorrect version", res.getVersion(), is(VERSION));
|
assertThat("Incorrect cluster ID", res.getClusterID(), is(CLUSTER_ID));
|
||||||
assertThat("Incorrect server time", res.getServerTimeUTC(), is(SERVER_TIME_UTC));
|
assertThat("Incorrect cluster name", res.getClusterName(), is(CLUSTER_NAME));
|
||||||
assertThat("Incorrect standby state", res.isStandby(), is(STANDBY));
|
assertThat("Incorrect version", res.getVersion(), is(VERSION));
|
||||||
assertThat("Incorrect seal state", res.isSealed(), is(SEALED));
|
assertThat("Incorrect server time", res.getServerTimeUTC(), is(SERVER_TIME_UTC));
|
||||||
assertThat("Incorrect initialization state", res.isInitialized(), is(INITIALIZED));
|
assertThat("Incorrect standby state", res.isStandby(), is(STANDBY));
|
||||||
assertThat("Incorrect performance standby state", res.isPerformanceStandby(), is(PERF_STANDBY));
|
assertThat("Incorrect seal state", res.isSealed(), is(SEALED));
|
||||||
assertThat("Incorrect replication perf mode", res.getReplicationPerfMode(), is(REPL_PERF_MODE));
|
assertThat("Incorrect initialization state", res.isInitialized(), is(INITIALIZED));
|
||||||
assertThat("Incorrect replication DR mode", res.getReplicationDrMode(), is(REPL_DR_MODE));
|
assertThat("Incorrect performance standby state", res.isPerformanceStandby(), is(PERF_STANDBY));
|
||||||
} catch (IOException e) {
|
assertThat("Incorrect replication perf mode", res.getReplicationPerfMode(), is(REPL_PERF_MODE));
|
||||||
fail("Health deserialization failed: " + e.getMessage());
|
assertThat("Incorrect replication DR mode", res.getReplicationDrMode(), is(REPL_DR_MODE));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,16 +17,12 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link MetadataResponse} model.
|
* JUnit Test for {@link MetadataResponse} model.
|
||||||
@ -74,27 +70,25 @@ class MetadataResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
MetadataResponse res = assertDoesNotThrow(
|
||||||
MetadataResponse res = new ObjectMapper().readValue(META_JSON, MetadataResponse.class);
|
() -> new ObjectMapper().readValue(META_JSON, MetadataResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"MetadataResponse deserialization failed."
|
||||||
assertThat("Parsed metadata is NULL", res.getMetadata(), is(notNullValue()));
|
);
|
||||||
assertThat("Incorrect created time", res.getMetadata().getCreatedTimeString(), is(V1_TIME));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Parting created time failed", res.getMetadata().getCreatedTime(), is(notNullValue()));
|
assertThat("Parsed metadata is NULL", res.getMetadata(), is(notNullValue()));
|
||||||
assertThat("Incorrect current version", res.getMetadata().getCurrentVersion(), is(CURRENT_VERSION));
|
assertThat("Incorrect created time", res.getMetadata().getCreatedTimeString(), is(V1_TIME));
|
||||||
assertThat("Incorrect max versions", res.getMetadata().getMaxVersions(), is(MAX_VERSIONS));
|
assertThat("Parting created time failed", res.getMetadata().getCreatedTime(), is(notNullValue()));
|
||||||
assertThat("Incorrect oldest version", res.getMetadata().getOldestVersion(), is(OLDEST_VERSION));
|
assertThat("Incorrect current version", res.getMetadata().getCurrentVersion(), is(CURRENT_VERSION));
|
||||||
assertThat("Incorrect updated time", res.getMetadata().getUpdatedTimeString(), is(V3_TIME));
|
assertThat("Incorrect max versions", res.getMetadata().getMaxVersions(), is(MAX_VERSIONS));
|
||||||
assertThat("Parting updated time failed", res.getMetadata().getUpdatedTime(), is(notNullValue()));
|
assertThat("Incorrect oldest version", res.getMetadata().getOldestVersion(), is(OLDEST_VERSION));
|
||||||
assertThat("Incorrect number of versions", res.getMetadata().getVersions().size(), is(3));
|
assertThat("Incorrect updated time", res.getMetadata().getUpdatedTimeString(), is(V3_TIME));
|
||||||
assertThat("Incorrect version 1 delete time", res.getMetadata().getVersions().get(1).getDeletionTimeString(), is(V2_TIME));
|
assertThat("Parting updated time failed", res.getMetadata().getUpdatedTime(), is(notNullValue()));
|
||||||
assertThat("Parsing version delete time failed", res.getMetadata().getVersions().get(1).getDeletionTime(), is(notNullValue()));
|
assertThat("Incorrect number of versions", res.getMetadata().getVersions().size(), is(3));
|
||||||
assertThat("Incorrect version 1 destroyed state", res.getMetadata().getVersions().get(1).isDestroyed(), is(true));
|
assertThat("Incorrect version 1 delete time", res.getMetadata().getVersions().get(1).getDeletionTimeString(), is(V2_TIME));
|
||||||
assertThat("Incorrect version 2 created time", res.getMetadata().getVersions().get(2).getCreatedTimeString(), is(V2_TIME));
|
assertThat("Parsing version delete time failed", res.getMetadata().getVersions().get(1).getDeletionTime(), is(notNullValue()));
|
||||||
assertThat("Parsing version created failed", res.getMetadata().getVersions().get(2).getCreatedTime(), is(notNullValue()));
|
assertThat("Incorrect version 1 destroyed state", res.getMetadata().getVersions().get(1).isDestroyed(), is(true));
|
||||||
assertThat("Incorrect version 3 destroyed state", res.getMetadata().getVersions().get(3).isDestroyed(), is(false));
|
assertThat("Incorrect version 2 created time", res.getMetadata().getVersions().get(2).getCreatedTimeString(), is(V2_TIME));
|
||||||
|
assertThat("Parsing version created failed", res.getMetadata().getVersions().get(2).getCreatedTime(), is(notNullValue()));
|
||||||
} catch (IOException e) {
|
assertThat("Incorrect version 3 destroyed state", res.getMetadata().getVersions().get(3).isDestroyed(), is(false));
|
||||||
fail("MetadataResponse deserialization failed: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,9 @@ package de.stklcode.jvault.connector.model.response;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link SealResponse} model.
|
* JUnit Test for {@link SealResponse} model.
|
||||||
@ -72,41 +70,39 @@ class SealResponseTest {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtripSealed() {
|
void jsonRoundtripSealed() {
|
||||||
// First test sealed Vault's response.
|
// First test sealed Vault's response.
|
||||||
try {
|
SealResponse res = assertDoesNotThrow(
|
||||||
SealResponse res = new ObjectMapper().readValue(RES_SEALED, SealResponse.class);
|
() -> new ObjectMapper().readValue(RES_SEALED, SealResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"TokenResponse deserialization failed."
|
||||||
assertThat("Incorrect seal type", res.getType(), is(TYPE));
|
);
|
||||||
assertThat("Incorrect seal status", res.isSealed(), is(true));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Incorrect initialization status", res.isInitialized(), is(true));
|
assertThat("Incorrect seal type", res.getType(), is(TYPE));
|
||||||
assertThat("Incorrect threshold", res.getThreshold(), is(THRESHOLD));
|
assertThat("Incorrect seal status", res.isSealed(), is(true));
|
||||||
assertThat("Incorrect number of shares", res.getNumberOfShares(), is(SHARES));
|
assertThat("Incorrect initialization status", res.isInitialized(), is(true));
|
||||||
assertThat("Incorrect progress", res.getProgress(), is(PROGRESS_SEALED));
|
assertThat("Incorrect threshold", res.getThreshold(), is(THRESHOLD));
|
||||||
assertThat("Nonce not empty", res.getNonce(), is(""));
|
assertThat("Incorrect number of shares", res.getNumberOfShares(), is(SHARES));
|
||||||
assertThat("Incorrect version", res.getVersion(), is(VERSION));
|
assertThat("Incorrect progress", res.getProgress(), is(PROGRESS_SEALED));
|
||||||
// And the fields, that should not be filled.
|
assertThat("Nonce not empty", res.getNonce(), is(""));
|
||||||
assertThat("Cluster name should not be populated", res.getClusterName(), is(nullValue()));
|
assertThat("Incorrect version", res.getVersion(), is(VERSION));
|
||||||
assertThat("Cluster ID should not be populated", res.getClusterId(), is(nullValue()));
|
// And the fields, that should not be filled.
|
||||||
} catch (IOException e) {
|
assertThat("Cluster name should not be populated", res.getClusterName(), is(nullValue()));
|
||||||
fail("TokenResponse deserialization failed: " + e.getMessage());
|
assertThat("Cluster ID should not be populated", res.getClusterId(), is(nullValue()));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Not test unsealed Vault's response.
|
// Not test unsealed Vault's response.
|
||||||
try {
|
res = assertDoesNotThrow(
|
||||||
SealResponse res = new ObjectMapper().readValue(RES_UNSEALED, SealResponse.class);
|
() -> new ObjectMapper().readValue(RES_UNSEALED, SealResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"TokenResponse deserialization failed."
|
||||||
assertThat("Incorrect seal type", res.getType(), is(TYPE));
|
);
|
||||||
assertThat("Incorrect seal status", res.isSealed(), is(false));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Incorrect initialization status", res.isInitialized(), is(true));
|
assertThat("Incorrect seal type", res.getType(), is(TYPE));
|
||||||
assertThat("Incorrect threshold", res.getThreshold(), is(THRESHOLD));
|
assertThat("Incorrect seal status", res.isSealed(), is(false));
|
||||||
assertThat("Incorrect number of shares", res.getNumberOfShares(), is(SHARES));
|
assertThat("Incorrect initialization status", res.isInitialized(), is(true));
|
||||||
assertThat("Incorrect progress", res.getProgress(), is(PROGRESS_UNSEALED));
|
assertThat("Incorrect threshold", res.getThreshold(), is(THRESHOLD));
|
||||||
assertThat("Incorrect nonce", res.getNonce(), is(NONCE));
|
assertThat("Incorrect number of shares", res.getNumberOfShares(), is(SHARES));
|
||||||
assertThat("Incorrect version", res.getVersion(), is(VERSION));
|
assertThat("Incorrect progress", res.getProgress(), is(PROGRESS_UNSEALED));
|
||||||
assertThat("Incorrect cluster name", res.getClusterName(), is(CLUSTER_NAME));
|
assertThat("Incorrect nonce", res.getNonce(), is(NONCE));
|
||||||
assertThat("Incorrect cluster ID", res.getClusterId(), is(CLUSTER_ID));
|
assertThat("Incorrect version", res.getVersion(), is(VERSION));
|
||||||
} catch (IOException e) {
|
assertThat("Incorrect cluster name", res.getClusterName(), is(CLUSTER_NAME));
|
||||||
fail("TokenResponse deserialization failed: " + e.getMessage());
|
assertThat("Incorrect cluster ID", res.getClusterId(), is(CLUSTER_ID));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link SecretListResponse} model.
|
* JUnit Test for {@link SecretListResponse} model.
|
||||||
@ -56,14 +56,13 @@ class SecretListResponseTest {
|
|||||||
assertThat("Keys should be null without initialization", res.getKeys(), is(nullValue()));
|
assertThat("Keys should be null without initialization", res.getKeys(), is(nullValue()));
|
||||||
|
|
||||||
// Provoke internal ClassCastException.
|
// Provoke internal ClassCastException.
|
||||||
try {
|
Map<String, Object> invalidData = new HashMap<>();
|
||||||
Map<String, Object> invalidData = new HashMap<>();
|
invalidData.put("keys", "some string");
|
||||||
invalidData.put("keys", "some string");
|
assertThrows(
|
||||||
res.setData(invalidData);
|
InvalidResponseException.class,
|
||||||
fail("Setting incorrect class succeeded");
|
() -> res.setData(invalidData),
|
||||||
} catch (Exception e) {
|
"Setting incorrect class succeeded"
|
||||||
assertThat("Unexpected exception type", e, instanceOf(InvalidResponseException.class));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
// Fill correct data.
|
// Fill correct data.
|
||||||
res.setData(DATA);
|
res.setData(DATA);
|
||||||
|
@ -20,14 +20,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link SecretResponse} model.
|
* JUnit Test for {@link SecretResponse} model.
|
||||||
@ -137,19 +137,18 @@ class SecretResponseTest {
|
|||||||
assertThat("Non-Null returned on unknown key", res.get(KEY_UNKNOWN), is(nullValue()));
|
assertThat("Non-Null returned on unknown key", res.get(KEY_UNKNOWN), is(nullValue()));
|
||||||
|
|
||||||
// Try explicit JSON conversion.
|
// Try explicit JSON conversion.
|
||||||
final List list = res.get(KEY_LIST, List.class);
|
final List<?> list = res.get(KEY_LIST, List.class);
|
||||||
assertThat("JSON parsing of list failed", list, is(notNullValue()));
|
assertThat("JSON parsing of list failed", list, is(notNullValue()));
|
||||||
assertThat("JSON parsing of list returned incorrect size", list.size(), is(2));
|
assertThat("JSON parsing of list returned incorrect size", list.size(), is(2));
|
||||||
assertThat("JSON parsing of list returned incorrect elements", (List<Object>)list, contains("first", "second"));
|
assertThat("JSON parsing of list returned incorrect elements", list, contains("first", "second"));
|
||||||
assertThat("Non-Null returned on unknown key", res.get(KEY_UNKNOWN, Object.class), is(nullValue()));
|
assertThat("Non-Null returned on unknown key", res.get(KEY_UNKNOWN, Object.class), is(nullValue()));
|
||||||
|
|
||||||
// Requesting invalid class should result in Exception.
|
// Requesting invalid class should result in Exception.
|
||||||
try {
|
assertThrows(
|
||||||
res.get(KEY_LIST, Double.class);
|
InvalidResponseException.class,
|
||||||
fail("JSON parsing to incorrect type succeeded.");
|
() -> res.get(KEY_LIST, Double.class),
|
||||||
} catch (Exception e) {
|
"JSON parsing to incorrect type succeeded."
|
||||||
assertThat(e, is(instanceOf(InvalidResponseException.class)));
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,41 +156,39 @@ class SecretResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
SecretResponse res = assertDoesNotThrow(
|
||||||
assertSecretData(new ObjectMapper().readValue(SECRET_JSON, SecretResponse.class));
|
() -> new ObjectMapper().readValue(SECRET_JSON, SecretResponse.class),
|
||||||
} catch (IOException e) {
|
"SecretResponse deserialization failed."
|
||||||
fail("SecretResponse deserialization failed: " + e.getMessage());
|
);
|
||||||
}
|
assertSecretData(res);
|
||||||
|
|
||||||
// KV v2 secret.
|
// KV v2 secret.
|
||||||
try {
|
res = assertDoesNotThrow(
|
||||||
SecretResponse res = new ObjectMapper().readValue(SECRET_JSON_V2, SecretResponse.class);
|
() -> new ObjectMapper().readValue(SECRET_JSON_V2, SecretResponse.class),
|
||||||
assertSecretData(res);
|
"SecretResponse deserialization failed."
|
||||||
assertThat("SecretResponse does not contain metadata", res.getMetadata(), is(notNullValue()));
|
);
|
||||||
assertThat("Incorrect creation date string", res.getMetadata().getCreatedTimeString(), is(SECRET_META_CREATED));
|
assertSecretData(res);
|
||||||
assertThat("Creation date parsing failed", res.getMetadata().getCreatedTime(), is(notNullValue()));
|
assertThat("SecretResponse does not contain metadata", res.getMetadata(), is(notNullValue()));
|
||||||
assertThat("Incorrect deletion date string", res.getMetadata().getDeletionTimeString(), is(emptyString()));
|
assertThat("Incorrect creation date string", res.getMetadata().getCreatedTimeString(), is(SECRET_META_CREATED));
|
||||||
assertThat("Incorrect deletion date", res.getMetadata().getDeletionTime(), is(nullValue()));
|
assertThat("Creation date parsing failed", res.getMetadata().getCreatedTime(), is(notNullValue()));
|
||||||
assertThat("Secret destroyed when not expected", res.getMetadata().isDestroyed(), is(false));
|
assertThat("Incorrect deletion date string", res.getMetadata().getDeletionTimeString(), is(emptyString()));
|
||||||
assertThat("Incorrect secret version", res.getMetadata().getVersion(), is(1));
|
assertThat("Incorrect deletion date", res.getMetadata().getDeletionTime(), is(nullValue()));
|
||||||
} catch (IOException e) {
|
assertThat("Secret destroyed when not expected", res.getMetadata().isDestroyed(), is(false));
|
||||||
fail("SecretResponse deserialization failed: " + e.getMessage());
|
assertThat("Incorrect secret version", res.getMetadata().getVersion(), is(1));
|
||||||
}
|
|
||||||
|
|
||||||
// Deleted KV v2 secret.
|
// Deleted KV v2 secret.
|
||||||
try {
|
res = assertDoesNotThrow(
|
||||||
SecretResponse res = new ObjectMapper().readValue(SECRET_JSON_V2_2, SecretResponse.class);
|
() -> new ObjectMapper().readValue(SECRET_JSON_V2_2, SecretResponse.class),
|
||||||
assertSecretData(res);
|
"SecretResponse deserialization failed."
|
||||||
assertThat("SecretResponse does not contain metadata", res.getMetadata(), is(notNullValue()));
|
);
|
||||||
assertThat("Incorrect creation date string", res.getMetadata().getCreatedTimeString(), is(SECRET_META_CREATED));
|
assertSecretData(res);
|
||||||
assertThat("Creation date parsing failed", res.getMetadata().getCreatedTime(), is(notNullValue()));
|
assertThat("SecretResponse does not contain metadata", res.getMetadata(), is(notNullValue()));
|
||||||
assertThat("Incorrect deletion date string", res.getMetadata().getDeletionTimeString(), is(SECRET_META_DELETED));
|
assertThat("Incorrect creation date string", res.getMetadata().getCreatedTimeString(), is(SECRET_META_CREATED));
|
||||||
assertThat("Incorrect deletion date", res.getMetadata().getDeletionTime(), is(notNullValue()));
|
assertThat("Creation date parsing failed", res.getMetadata().getCreatedTime(), is(notNullValue()));
|
||||||
assertThat("Secret destroyed when not expected", res.getMetadata().isDestroyed(), is(true));
|
assertThat("Incorrect deletion date string", res.getMetadata().getDeletionTimeString(), is(SECRET_META_DELETED));
|
||||||
assertThat("Incorrect secret version", res.getMetadata().getVersion(), is(2));
|
assertThat("Incorrect deletion date", res.getMetadata().getDeletionTime(), is(notNullValue()));
|
||||||
} catch (IOException e) {
|
assertThat("Secret destroyed when not expected", res.getMetadata().isDestroyed(), is(true));
|
||||||
fail("SecretResponse deserialization failed: " + e.getMessage());
|
assertThat("Incorrect secret version", res.getMetadata().getVersion(), is(2));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertSecretData(SecretResponse res) {
|
private void assertSecretData(SecretResponse res) {
|
||||||
|
@ -19,12 +19,10 @@ package de.stklcode.jvault.connector.model.response;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link SecretVersionResponse} model.
|
* JUnit Test for {@link SecretVersionResponse} model.
|
||||||
@ -51,16 +49,15 @@ class SecretVersionResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
SecretVersionResponse res = assertDoesNotThrow(
|
||||||
SecretVersionResponse res = new ObjectMapper().readValue(META_JSON, SecretVersionResponse.class);
|
() -> new ObjectMapper().readValue(META_JSON, SecretVersionResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"SecretVersionResponse deserialization failed"
|
||||||
assertThat("Parsed metadata is NULL", res.getMetadata(), is(notNullValue()));
|
);
|
||||||
assertThat("Incorrect created time", res.getMetadata().getCreatedTimeString(), is(CREATION_TIME));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Incorrect deletion time", res.getMetadata().getDeletionTimeString(), is(DELETION_TIME));
|
assertThat("Parsed metadata is NULL", res.getMetadata(), is(notNullValue()));
|
||||||
assertThat("Incorrect destroyed state", res.getMetadata().isDestroyed(), is(false));
|
assertThat("Incorrect created time", res.getMetadata().getCreatedTimeString(), is(CREATION_TIME));
|
||||||
assertThat("Incorrect version", res.getMetadata().getVersion(), is(VERSION));
|
assertThat("Incorrect deletion time", res.getMetadata().getDeletionTimeString(), is(DELETION_TIME));
|
||||||
} catch (IOException e) {
|
assertThat("Incorrect destroyed state", res.getMetadata().isDestroyed(), is(false));
|
||||||
fail("SecretVersionResponse deserialization failed: " + e.getMessage());
|
assertThat("Incorrect version", res.getMetadata().getVersion(), is(VERSION));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,14 @@ import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
|||||||
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit Test for {@link TokenResponse} model.
|
* JUnit Test for {@link TokenResponse} model.
|
||||||
@ -107,12 +107,11 @@ class TokenResponseTest {
|
|||||||
assertThat("Initial data should be empty", res.getData(), is(nullValue()));
|
assertThat("Initial data should be empty", res.getData(), is(nullValue()));
|
||||||
|
|
||||||
// Parsing invalid data map should fail.
|
// Parsing invalid data map should fail.
|
||||||
try {
|
assertThrows(
|
||||||
res.setData(INVALID_TOKEN_DATA);
|
InvalidResponseException.class,
|
||||||
fail("Parsing invalid token data succeeded");
|
() -> res.setData(INVALID_TOKEN_DATA),
|
||||||
} catch (Exception e) {
|
"Parsing invalid token data succeeded"
|
||||||
assertThat(e, is(instanceOf(InvalidResponseException.class)));
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,38 +119,37 @@ class TokenResponseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
try {
|
TokenResponse res = assertDoesNotThrow(
|
||||||
TokenResponse res = new ObjectMapper().readValue(RES_JSON, TokenResponse.class);
|
() -> new ObjectMapper().readValue(RES_JSON, TokenResponse.class),
|
||||||
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
"TokenResponse deserialization failed."
|
||||||
assertThat("Incorrect lease duration", res.getLeaseDuration(), is(RES_LEASE_DURATION));
|
);
|
||||||
assertThat("Incorrect response renewable flag", res.isRenewable(), is(RES_RENEWABLE));
|
assertThat("Parsed response is NULL", res, is(notNullValue()));
|
||||||
assertThat("Incorrect response lease duration", res.getLeaseDuration(), is(RES_LEASE_DURATION));
|
assertThat("Incorrect lease duration", res.getLeaseDuration(), is(RES_LEASE_DURATION));
|
||||||
// Extract token data.
|
assertThat("Incorrect response renewable flag", res.isRenewable(), is(RES_RENEWABLE));
|
||||||
TokenData data = res.getData();
|
assertThat("Incorrect response lease duration", res.getLeaseDuration(), is(RES_LEASE_DURATION));
|
||||||
assertThat("Token data is NULL", data, is(notNullValue()));
|
// Extract token data.
|
||||||
assertThat("Incorrect token accessor", data.getAccessor(), is(TOKEN_ACCESSOR));
|
TokenData data = res.getData();
|
||||||
assertThat("Incorrect token creation time", data.getCreationTime(), is(TOKEN_CREATION_TIME));
|
assertThat("Token data is NULL", data, is(notNullValue()));
|
||||||
assertThat("Incorrect token creation TTL", data.getCreationTtl(), is(TOKEN_TTL));
|
assertThat("Incorrect token accessor", data.getAccessor(), is(TOKEN_ACCESSOR));
|
||||||
assertThat("Incorrect token display name", data.getName(), is(TOKEN_DISPLAY_NAME));
|
assertThat("Incorrect token creation time", data.getCreationTime(), is(TOKEN_CREATION_TIME));
|
||||||
assertThat("Incorrect token entity ID", data.getEntityId(), is(TOKEN_ENTITY_ID));
|
assertThat("Incorrect token creation TTL", data.getCreationTtl(), is(TOKEN_TTL));
|
||||||
assertThat("Incorrect token expire time", data.getExpireTimeString(), is(TOKEN_EXPIRE_TIME));
|
assertThat("Incorrect token display name", data.getName(), is(TOKEN_DISPLAY_NAME));
|
||||||
assertThat("Incorrect parsed token expire time", data.getExpireTime(), is(ZonedDateTime.parse(TOKEN_EXPIRE_TIME)));
|
assertThat("Incorrect token entity ID", data.getEntityId(), is(TOKEN_ENTITY_ID));
|
||||||
assertThat("Incorrect token explicit max TTL", data.getExplicitMaxTtl(), is(TOKEN_EXPLICIT_MAX_TTL));
|
assertThat("Incorrect token expire time", data.getExpireTimeString(), is(TOKEN_EXPIRE_TIME));
|
||||||
assertThat("Incorrect token ID", data.getId(), is(TOKEN_ID));
|
assertThat("Incorrect parsed token expire time", data.getExpireTime(), is(ZonedDateTime.parse(TOKEN_EXPIRE_TIME)));
|
||||||
assertThat("Incorrect token issue time", data.getIssueTimeString(), is(TOKEN_ISSUE_TIME));
|
assertThat("Incorrect token explicit max TTL", data.getExplicitMaxTtl(), is(TOKEN_EXPLICIT_MAX_TTL));
|
||||||
assertThat("Incorrect parsed token issue time", data.getIssueTime(), is(ZonedDateTime.parse(TOKEN_ISSUE_TIME)));
|
assertThat("Incorrect token ID", data.getId(), is(TOKEN_ID));
|
||||||
assertThat("Incorrect token metadata size", data.getMeta().entrySet(), hasSize(1));
|
assertThat("Incorrect token issue time", data.getIssueTimeString(), is(TOKEN_ISSUE_TIME));
|
||||||
assertThat("Incorrect token metadata", data.getMeta().get(TOKEN_META_KEY), is(TOKEN_META_VALUE));
|
assertThat("Incorrect parsed token issue time", data.getIssueTime(), is(ZonedDateTime.parse(TOKEN_ISSUE_TIME)));
|
||||||
assertThat("Incorrect token number of uses", data.getNumUses(), is(TOKEN_NUM_USES));
|
assertThat("Incorrect token metadata size", data.getMeta().entrySet(), hasSize(1));
|
||||||
assertThat("Incorrect token orphan flag", data.isOrphan(), is(TOKEN_ORPHAN));
|
assertThat("Incorrect token metadata", data.getMeta().get(TOKEN_META_KEY), is(TOKEN_META_VALUE));
|
||||||
assertThat("Incorrect token path", data.getPath(), is(TOKEN_PATH));
|
assertThat("Incorrect token number of uses", data.getNumUses(), is(TOKEN_NUM_USES));
|
||||||
assertThat("Incorrect number of token policies", data.getPolicies(), hasSize(2));
|
assertThat("Incorrect token orphan flag", data.isOrphan(), is(TOKEN_ORPHAN));
|
||||||
assertThat("Incorrect token policies", data.getPolicies(), contains(TOKEN_POLICY_1, TOKEN_POLICY_2));
|
assertThat("Incorrect token path", data.getPath(), is(TOKEN_PATH));
|
||||||
assertThat("Incorrect token renewable flag", data.isRenewable(), is(TOKEN_RENEWABLE));
|
assertThat("Incorrect number of token policies", data.getPolicies(), hasSize(2));
|
||||||
assertThat("Incorrect token TTL", data.getTtl(), is(RES_TTL));
|
assertThat("Incorrect token policies", data.getPolicies(), contains(TOKEN_POLICY_1, TOKEN_POLICY_2));
|
||||||
assertThat("Incorrect token type", data.getType(), is(TOKEN_TYPE));
|
assertThat("Incorrect token renewable flag", data.isRenewable(), is(TOKEN_RENEWABLE));
|
||||||
} catch (IOException e) {
|
assertThat("Incorrect token TTL", data.getTtl(), is(RES_TTL));
|
||||||
fail("TokenResponse deserialization failed: " + e.getMessage());
|
assertThat("Incorrect token type", data.getType(), is(TOKEN_TYPE));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user