test: bundle serialization tests into abstract test case
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
4f3cb4b330
commit
f3cc16f44a
@ -0,0 +1,70 @@
|
||||
package de.stklcode.jvault.connector.model;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Abstract testcase for model classes.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 1.1
|
||||
*/
|
||||
public abstract class AbstractModelTest<T> {
|
||||
protected final Class<?> modelClass;
|
||||
|
||||
/**
|
||||
* Test case constructor.
|
||||
*
|
||||
* @param modelClass Target class to test.
|
||||
*/
|
||||
protected AbstractModelTest(Class<T> modelClass) {
|
||||
this.modelClass = modelClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a "full" model instance.
|
||||
*
|
||||
* @return Model instance.
|
||||
*/
|
||||
protected abstract T createFull();
|
||||
|
||||
/**
|
||||
* Test if {@link Object#equals(Object)} and {@link Object#hashCode()} are implemented, s.t. all fields are covered.
|
||||
*/
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(modelClass).verify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Java serialization of a full model instance.
|
||||
* Serialization and deserialization must not fail and the resulting object should equal the original object.
|
||||
*/
|
||||
@Test
|
||||
void serializationTest() {
|
||||
T original = createFull();
|
||||
byte[] bytes;
|
||||
try (var bos = new ByteArrayOutputStream();
|
||||
var oos = new ObjectOutputStream(bos)) {
|
||||
oos.writeObject(original);
|
||||
bytes = bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
fail("Serialization failed", e);
|
||||
return;
|
||||
}
|
||||
|
||||
try (var bis = new ByteArrayInputStream(bytes);
|
||||
var ois = new ObjectInputStream(bis)) {
|
||||
Object copy = ois.readObject();
|
||||
assertEquals(modelClass, copy.getClass(), "Invalid class after deserialization");
|
||||
assertEquals(original, copy, "Deserialized object should be equal to the original");
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
fail("Deserialization failed", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -34,7 +33,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.5.0
|
||||
*/
|
||||
class AppRoleSecretTest {
|
||||
class AppRoleSecretTest extends AbstractModelTest<AppRoleSecret> {
|
||||
private static final String TEST_ID = "abc123";
|
||||
private static final Map<String, Object> TEST_META = Map.of(
|
||||
"foo", "bar",
|
||||
@ -42,6 +41,15 @@ class AppRoleSecretTest {
|
||||
);
|
||||
private static final List<String> TEST_CIDR = List.of("203.0.113.0/24", "198.51.100.0/24");
|
||||
|
||||
AppRoleSecretTest() {
|
||||
super(AppRoleSecret.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AppRoleSecret createFull() {
|
||||
return new AppRoleSecret(TEST_ID, TEST_META, TEST_CIDR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructors.
|
||||
*/
|
||||
@ -166,11 +174,6 @@ class AppRoleSecretTest {
|
||||
assertEquals(12345, secret2.getTtl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AppRoleSecret.class).verify();
|
||||
}
|
||||
|
||||
private static void setPrivateField(Object object, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||
Field field = object.getClass().getDeclaredField(fieldName);
|
||||
boolean accessible = field.isAccessible();
|
||||
|
@ -18,7 +18,6 @@ package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -33,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.4.0
|
||||
*/
|
||||
class AppRoleTest {
|
||||
class AppRoleTest extends AbstractModelTest<AppRole> {
|
||||
private static final String NAME = "TestRole";
|
||||
private static final String ID = "test-id";
|
||||
private static final Boolean BIND_SECRET_ID = true;
|
||||
@ -57,6 +56,31 @@ class AppRoleTest {
|
||||
private static final String JSON_FULL = String.format("{\"role_name\":\"%s\",\"role_id\":\"%s\",\"bind_secret_id\":%s,\"secret_id_bound_cidrs\":\"%s\",\"secret_id_num_uses\":%d,\"secret_id_ttl\":%d,\"enable_local_secret_ids\":%s,\"token_ttl\":%d,\"token_max_ttl\":%d,\"token_policies\":\"%s\",\"token_bound_cidrs\":\"%s\",\"token_explicit_max_ttl\":%d,\"token_no_default_policy\":%s,\"token_num_uses\":%d,\"token_period\":%d,\"token_type\":\"%s\"}",
|
||||
NAME, ID, BIND_SECRET_ID, CIDR_1, SECRET_ID_NUM_USES, SECRET_ID_TTL, ENABLE_LOCAL_SECRET_IDS, TOKEN_TTL, TOKEN_MAX_TTL, POLICY, CIDR_1, TOKEN_EXPLICIT_MAX_TTL, TOKEN_NO_DEFAULT_POLICY, TOKEN_NUM_USES, TOKEN_PERIOD, TOKEN_TYPE.value());
|
||||
|
||||
AppRoleTest() {
|
||||
super(AppRole.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AppRole createFull() {
|
||||
return AppRole.builder(NAME)
|
||||
.withId(ID)
|
||||
.withBindSecretID(BIND_SECRET_ID)
|
||||
.withSecretIdBoundCidrs(BOUND_CIDR_LIST)
|
||||
.withTokenPolicies(POLICIES)
|
||||
.withSecretIdNumUses(SECRET_ID_NUM_USES)
|
||||
.withSecretIdTtl(SECRET_ID_TTL)
|
||||
.withEnableLocalSecretIds(ENABLE_LOCAL_SECRET_IDS)
|
||||
.withTokenTtl(TOKEN_TTL)
|
||||
.withTokenMaxTtl(TOKEN_MAX_TTL)
|
||||
.withTokenBoundCidrs(BOUND_CIDR_LIST)
|
||||
.withTokenExplicitMaxTtl(TOKEN_EXPLICIT_MAX_TTL)
|
||||
.withTokenNoDefaultPolicy(TOKEN_NO_DEFAULT_POLICY)
|
||||
.withTokenNumUses(TOKEN_NUM_USES)
|
||||
.withTokenPeriod(TOKEN_PERIOD)
|
||||
.withTokenType(TOKEN_TYPE)
|
||||
.build();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
static void init() {
|
||||
BOUND_CIDR_LIST.add(CIDR_1);
|
||||
@ -94,23 +118,7 @@ class AppRoleTest {
|
||||
*/
|
||||
@Test
|
||||
void buildFullTest() throws JsonProcessingException {
|
||||
AppRole role = AppRole.builder(NAME)
|
||||
.withId(ID)
|
||||
.withBindSecretID(BIND_SECRET_ID)
|
||||
.withSecretIdBoundCidrs(BOUND_CIDR_LIST)
|
||||
.withTokenPolicies(POLICIES)
|
||||
.withSecretIdNumUses(SECRET_ID_NUM_USES)
|
||||
.withSecretIdTtl(SECRET_ID_TTL)
|
||||
.withEnableLocalSecretIds(ENABLE_LOCAL_SECRET_IDS)
|
||||
.withTokenTtl(TOKEN_TTL)
|
||||
.withTokenMaxTtl(TOKEN_MAX_TTL)
|
||||
.withTokenBoundCidrs(BOUND_CIDR_LIST)
|
||||
.withTokenExplicitMaxTtl(TOKEN_EXPLICIT_MAX_TTL)
|
||||
.withTokenNoDefaultPolicy(TOKEN_NO_DEFAULT_POLICY)
|
||||
.withTokenNumUses(TOKEN_NUM_USES)
|
||||
.withTokenPeriod(TOKEN_PERIOD)
|
||||
.withTokenType(TOKEN_TYPE)
|
||||
.build();
|
||||
AppRole role = createFull();
|
||||
assertEquals(NAME, role.getName());
|
||||
assertEquals(ID, role.getId());
|
||||
assertEquals(BIND_SECRET_ID, role.getBindSecretId());
|
||||
@ -173,9 +181,4 @@ class AppRoleTest {
|
||||
assertEquals(2, role.getTokenPolicies().size());
|
||||
assertTrue(role.getTokenPolicies().containsAll(List.of(POLICY, POLICY_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AppRole.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -32,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.9
|
||||
*/
|
||||
class TokenRoleTest {
|
||||
class TokenRoleTest extends AbstractModelTest<TokenRole> {
|
||||
private static final String NAME = "test-role";
|
||||
private static final String ALLOWED_POLICY_1 = "apol-1";
|
||||
private static final String ALLOWED_POLICY_2 = "apol-2";
|
||||
@ -74,6 +73,33 @@ class TokenRoleTest {
|
||||
"\"token_period\":" + TOKEN_PERIOD + "," +
|
||||
"\"token_type\":\"" + TOKEN_TYPE.value() + "\"}";
|
||||
|
||||
TokenRoleTest() {
|
||||
super(TokenRole.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TokenRole createFull() {
|
||||
return TokenRole.builder()
|
||||
.forName(NAME)
|
||||
.withAllowedPolicies(ALLOWED_POLICIES)
|
||||
.withAllowedPolicy(ALLOWED_POLICY_3)
|
||||
.withDisallowedPolicy(DISALLOWED_POLICY_1)
|
||||
.withDisallowedPolicies(DISALLOWED_POLICIES)
|
||||
.orphan(ORPHAN)
|
||||
.renewable(RENEWABLE)
|
||||
.withPathSuffix(PATH_SUFFIX)
|
||||
.withAllowedEntityAliases(ALLOWED_ENTITY_ALIASES)
|
||||
.withAllowedEntityAlias(ALLOWED_ENTITY_ALIAS_2)
|
||||
.withTokenBoundCidr(TOKEN_BOUND_CIDR_3)
|
||||
.withTokenBoundCidrs(TOKEN_BOUND_CIDRS)
|
||||
.withTokenExplicitMaxTtl(TOKEN_EXPLICIT_MAX_TTL)
|
||||
.withTokenNoDefaultPolicy(TOKEN_NO_DEFAULT_POLICY)
|
||||
.withTokenNumUses(TOKEN_NUM_USES)
|
||||
.withTokenPeriod(TOKEN_PERIOD)
|
||||
.withTokenType(TOKEN_TYPE)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build token without any parameters.
|
||||
*/
|
||||
@ -145,25 +171,7 @@ class TokenRoleTest {
|
||||
*/
|
||||
@Test
|
||||
void buildFullTest() throws JsonProcessingException {
|
||||
TokenRole role = TokenRole.builder()
|
||||
.forName(NAME)
|
||||
.withAllowedPolicies(ALLOWED_POLICIES)
|
||||
.withAllowedPolicy(ALLOWED_POLICY_3)
|
||||
.withDisallowedPolicy(DISALLOWED_POLICY_1)
|
||||
.withDisallowedPolicies(DISALLOWED_POLICIES)
|
||||
.orphan(ORPHAN)
|
||||
.renewable(RENEWABLE)
|
||||
.withPathSuffix(PATH_SUFFIX)
|
||||
.withAllowedEntityAliases(ALLOWED_ENTITY_ALIASES)
|
||||
.withAllowedEntityAlias(ALLOWED_ENTITY_ALIAS_2)
|
||||
.withTokenBoundCidr(TOKEN_BOUND_CIDR_3)
|
||||
.withTokenBoundCidrs(TOKEN_BOUND_CIDRS)
|
||||
.withTokenExplicitMaxTtl(TOKEN_EXPLICIT_MAX_TTL)
|
||||
.withTokenNoDefaultPolicy(TOKEN_NO_DEFAULT_POLICY)
|
||||
.withTokenNumUses(TOKEN_NUM_USES)
|
||||
.withTokenPeriod(TOKEN_PERIOD)
|
||||
.withTokenType(TOKEN_TYPE)
|
||||
.build();
|
||||
TokenRole role = createFull();
|
||||
assertEquals(NAME, role.getName());
|
||||
assertEquals(ALLOWED_POLICIES.size() + 1, role.getAllowedPolicies().size());
|
||||
assertTrue(role.getAllowedPolicies().containsAll(List.of(ALLOWED_POLICY_1, ALLOWED_POLICY_2, ALLOWED_POLICY_3)));
|
||||
@ -184,9 +192,4 @@ class TokenRoleTest {
|
||||
// Verify that all parameters are included in JSON string.
|
||||
assertEquals(JSON_FULL, new ObjectMapper().writeValueAsString(role));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(TokenRole.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -32,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.4.0
|
||||
*/
|
||||
class TokenTest {
|
||||
class TokenTest extends AbstractModelTest<Token> {
|
||||
private static final String ID = "test-id";
|
||||
private static final String DISPLAY_NAME = "display-name";
|
||||
private static final Boolean NO_PARENT = false;
|
||||
@ -54,6 +53,29 @@ class TokenTest {
|
||||
private static final String ENTITY_ALIAS = "alias-value";
|
||||
private static final String JSON_FULL = "{\"id\":\"test-id\",\"type\":\"service\",\"display_name\":\"display-name\",\"no_parent\":false,\"no_default_policy\":false,\"ttl\":123,\"explicit_max_ttl\":456,\"num_uses\":4,\"policies\":[\"policy\"],\"meta\":{\"key\":\"value\"},\"renewable\":true,\"period\":3600,\"entity_alias\":\"alias-value\"}";
|
||||
|
||||
TokenTest() {
|
||||
super(Token.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Token createFull() {
|
||||
return Token.builder()
|
||||
.withId(ID)
|
||||
.withType(Token.Type.SERVICE)
|
||||
.withDisplayName(DISPLAY_NAME)
|
||||
.withNoParent(NO_PARENT)
|
||||
.withNoDefaultPolicy(NO_DEFAULT_POLICY)
|
||||
.withTtl(TTL)
|
||||
.withExplicitMaxTtl(EXPLICIT_MAX_TTL)
|
||||
.withNumUses(NUM_USES)
|
||||
.withPolicies(POLICIES)
|
||||
.withMeta(META)
|
||||
.withRenewable(RENEWABLE)
|
||||
.withPeriod(PERIOD)
|
||||
.withEntityAlias(ENTITY_ALIAS)
|
||||
.build();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
static void init() {
|
||||
POLICIES.add(POLICY);
|
||||
@ -92,21 +114,7 @@ class TokenTest {
|
||||
*/
|
||||
@Test
|
||||
void buildFullTest() throws JsonProcessingException {
|
||||
Token token = Token.builder()
|
||||
.withId(ID)
|
||||
.withType(Token.Type.SERVICE)
|
||||
.withDisplayName(DISPLAY_NAME)
|
||||
.withNoParent(NO_PARENT)
|
||||
.withNoDefaultPolicy(NO_DEFAULT_POLICY)
|
||||
.withTtl(TTL)
|
||||
.withExplicitMaxTtl(EXPLICIT_MAX_TTL)
|
||||
.withNumUses(NUM_USES)
|
||||
.withPolicies(POLICIES)
|
||||
.withMeta(META)
|
||||
.withRenewable(RENEWABLE)
|
||||
.withPeriod(PERIOD)
|
||||
.withEntityAlias(ENTITY_ALIAS)
|
||||
.build();
|
||||
Token token = createFull();
|
||||
assertEquals(ID, token.getId());
|
||||
assertEquals(Token.Type.SERVICE.value(), token.getType());
|
||||
assertEquals(DISPLAY_NAME, token.getDisplayName());
|
||||
@ -171,9 +179,4 @@ class TokenTest {
|
||||
assertEquals(META_VALUE, token.getMeta().get(META_KEY));
|
||||
assertEquals(META_VALUE_2, token.getMeta().get(META_KEY_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(Token.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,10 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import de.stklcode.jvault.connector.model.AppRole;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@ -31,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class AppRoleResponseTest {
|
||||
class AppRoleResponseTest extends AbstractModelTest<AppRoleResponse> {
|
||||
private static final Integer ROLE_TOKEN_TTL = 1200;
|
||||
private static final Integer ROLE_TOKEN_MAX_TTL = 1800;
|
||||
private static final Integer ROLE_SECRET_TTL = 600;
|
||||
@ -61,6 +62,20 @@ class AppRoleResponseTest {
|
||||
" \"lease_id\": \"\"\n" +
|
||||
"}";
|
||||
|
||||
AppRoleResponseTest() {
|
||||
super(AppRoleResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AppRoleResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(RES_JSON, AppRoleResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
*/
|
||||
@ -94,9 +109,4 @@ class AppRoleResponseTest {
|
||||
assertNull(role.getTokenBoundCidrs(), "Incorrect bound CIDR list");
|
||||
assertEquals("", role.getTokenBoundCidrsString(), "Incorrect bound CIDR list string");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AppRoleResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,13 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import de.stklcode.jvault.connector.model.AuthBackend;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -36,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class AuthMethodsResponseTest {
|
||||
class AuthMethodsResponseTest extends AbstractModelTest<AuthMethodsResponse> {
|
||||
private static final String GH_PATH = "github/";
|
||||
private static final String GH_TYPE = "github";
|
||||
private static final String GH_DESCR = "GitHub auth";
|
||||
@ -63,6 +62,20 @@ class AuthMethodsResponseTest {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
AuthMethodsResponseTest() {
|
||||
super(AuthMethodsResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthMethodsResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(RES_JSON, AuthMethodsResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
*/
|
||||
@ -106,13 +119,4 @@ class AuthMethodsResponseTest {
|
||||
assertEquals(TK_LEASE_TTL.toString(), method.getConfig().get("default_lease_ttl"), "Incorrect lease TTL config");
|
||||
assertEquals(TK_MAX_LEASE_TTL.toString(), method.getConfig().get("max_lease_ttl"), "Incorrect max lease TTL config");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AuthMethodsResponse.class).verify();
|
||||
}
|
||||
|
||||
private static class Dummy implements Serializable {
|
||||
private static final long serialVersionUID = 9075949348402246139L;
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,10 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.AuthData;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
@ -32,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class AuthResponseTest {
|
||||
class AuthResponseTest extends AbstractModelTest<AuthResponse> {
|
||||
private static final String AUTH_ACCESSOR = "2c84f488-2133-4ced-87b0-570f93a76830";
|
||||
private static final String AUTH_CLIENT_TOKEN = "ABCD";
|
||||
private static final String AUTH_POLICY_1 = "web";
|
||||
@ -68,15 +69,18 @@ class AuthResponseTest {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
*/
|
||||
@Test
|
||||
void getDataRoundtrip() {
|
||||
// Create empty Object.
|
||||
AuthResponse res = new AuthResponse();
|
||||
// TODO
|
||||
// assertNull(res.getData(), "Initial data should be empty");
|
||||
AuthResponseTest() {
|
||||
super(AuthResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(RES_JSON, AuthResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,9 +109,4 @@ class AuthResponseTest {
|
||||
assertTrue(data.getTokenPolicies().containsAll(Set.of(AUTH_POLICY_2, AUTH_POLICY_1)), "Incorrect token policies");
|
||||
assertEquals(Map.of(AUTH_META_KEY, AUTH_META_VALUE), data.getMetadata(), "Incorrect auth metadata");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AuthResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,10 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -29,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8
|
||||
*/
|
||||
class CredentialsResponseTest {
|
||||
class CredentialsResponseTest extends AbstractModelTest<CredentialsResponse> {
|
||||
private static final String VAL_USER = "testUserName";
|
||||
private static final String VAL_PASS = "5up3r5ecr3tP455";
|
||||
private static final String JSON = "{\n" +
|
||||
@ -44,6 +45,20 @@ class CredentialsResponseTest {
|
||||
" \"warnings\": null\n" +
|
||||
"}";
|
||||
|
||||
CredentialsResponseTest() {
|
||||
super(CredentialsResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CredentialsResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(JSON, CredentialsResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
*
|
||||
@ -63,9 +78,4 @@ class CredentialsResponseTest {
|
||||
assertEquals(VAL_USER, res.getUsername(), "Incorrect username");
|
||||
assertEquals(VAL_PASS, res.getPassword(), "Incorrect password");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(CredentialsResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@ -29,13 +30,27 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
*/
|
||||
class ErrorResponseTest {
|
||||
class ErrorResponseTest extends AbstractModelTest<ErrorResponse> {
|
||||
private static final String ERROR_1 = "Error #1";
|
||||
private static final String ERROR_2 = "Error #2";
|
||||
|
||||
private static final String JSON = "{\"errors\":[\"" + ERROR_1 + "\",\"" + ERROR_2 + "\"]}";
|
||||
private static final String JSON_EMPTY = "{\"errors\":[]}";
|
||||
|
||||
ErrorResponseTest() {
|
||||
super(ErrorResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ErrorResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(JSON, ErrorResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault.
|
||||
*/
|
||||
@ -72,9 +87,4 @@ class ErrorResponseTest {
|
||||
|
||||
assertEquals("error response", new ErrorResponse().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(ErrorResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -28,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.7.0
|
||||
*/
|
||||
class HealthResponseTest {
|
||||
class HealthResponseTest extends AbstractModelTest<HealthResponse> {
|
||||
private static final String CLUSTER_ID = "c9abceea-4f46-4dab-a688-5ce55f89e228";
|
||||
private static final String CLUSTER_NAME = "vault-cluster-5515c810";
|
||||
private static final String VERSION = "0.9.2";
|
||||
@ -53,6 +54,20 @@ class HealthResponseTest {
|
||||
" \"performance_standby\": " + PERF_STANDBY + "\n" +
|
||||
"}";
|
||||
|
||||
HealthResponseTest() {
|
||||
super(HealthResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HealthResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(RES_JSON, HealthResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
||||
*/
|
||||
@ -74,9 +89,4 @@ class HealthResponseTest {
|
||||
assertEquals(REPL_PERF_MODE, res.getReplicationPerfMode(), "Incorrect replication perf mode");
|
||||
assertEquals(REPL_DR_MODE, res.getReplicationDrMode(), "Incorrect replication DR mode");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(HealthResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -27,11 +28,25 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
*/
|
||||
class HelpResponseTest {
|
||||
class HelpResponseTest extends AbstractModelTest<HelpResponse> {
|
||||
private static final String HELP = "Help Text.";
|
||||
|
||||
private static final String JSON = "{\"help\":\"" + HELP + "\"}";
|
||||
|
||||
HelpResponseTest() {
|
||||
super(HelpResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HelpResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(JSON, HelpResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault.
|
||||
*/
|
||||
@ -50,9 +65,4 @@ class HelpResponseTest {
|
||||
"Unexpected JSON string after serialization"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(HelpResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,12 +26,12 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JUnit Test for {@link SecretResponse} model.
|
||||
* JUnit Test for {@link MetaSecretResponse} model.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class SecretResponseTest {
|
||||
class MetaSecretResponseTest extends AbstractModelTest<MetaSecretResponse> {
|
||||
private static final String SECRET_REQUEST_ID = "68315073-6658-e3ff-2da7-67939fb91bbd";
|
||||
private static final String SECRET_LEASE_ID = "";
|
||||
private static final Integer SECRET_LEASE_DURATION = 2764800;
|
||||
@ -42,17 +43,6 @@ class SecretResponseTest {
|
||||
private static final String SECRET_META_CREATED = "2018-03-22T02:24:06.945319214Z";
|
||||
private static final String SECRET_META_DELETED = "2018-03-23T03:25:07.056420325Z";
|
||||
private static final List<String> SECRET_WARNINGS = null;
|
||||
private static final String SECRET_JSON = "{\n" +
|
||||
" \"request_id\": \"" + SECRET_REQUEST_ID + "\",\n" +
|
||||
" \"lease_id\": \"" + SECRET_LEASE_ID + "\",\n" +
|
||||
" \"lease_duration\": " + SECRET_LEASE_DURATION + ",\n" +
|
||||
" \"renewable\": " + SECRET_RENEWABLE + ",\n" +
|
||||
" \"data\": {\n" +
|
||||
" \"" + SECRET_DATA_K1 + "\": \"" + SECRET_DATA_V1 + "\",\n" +
|
||||
" \"" + SECRET_DATA_K2 + "\": \"" + SECRET_DATA_V2 + "\"\n" +
|
||||
" },\n" +
|
||||
" \"warnings\": " + SECRET_WARNINGS + "\n" +
|
||||
"}";
|
||||
private static final String SECRET_JSON_V2 = "{\n" +
|
||||
" \"request_id\": \"" + SECRET_REQUEST_ID + "\",\n" +
|
||||
" \"lease_id\": \"" + SECRET_LEASE_ID + "\",\n" +
|
||||
@ -92,19 +82,27 @@ class SecretResponseTest {
|
||||
" \"warnings\": " + SECRET_WARNINGS + "\n" +
|
||||
"}";
|
||||
|
||||
MetaSecretResponseTest() {
|
||||
super(MetaSecretResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetaSecretResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(SECRET_JSON_V2, MetaSecretResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
||||
*/
|
||||
@Test
|
||||
void jsonRoundtrip() {
|
||||
SecretResponse res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(SECRET_JSON, PlainSecretResponse.class),
|
||||
"SecretResponse deserialization failed"
|
||||
);
|
||||
assertSecretData(res);
|
||||
|
||||
// KV v2 secret.
|
||||
res = assertDoesNotThrow(
|
||||
MetaSecretResponse res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(SECRET_JSON_V2, MetaSecretResponse.class),
|
||||
"SecretResponse deserialization failed"
|
||||
);
|
||||
@ -132,13 +130,6 @@ class SecretResponseTest {
|
||||
assertEquals(2, res.getMetadata().getVersion(), "Incorrect secret version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SecretResponse.class).verify();
|
||||
EqualsVerifier.simple().forClass(PlainSecretResponse.class).verify();
|
||||
EqualsVerifier.simple().forClass(MetaSecretResponse.class).verify();
|
||||
}
|
||||
|
||||
private void assertSecretData(SecretResponse res) {
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(SECRET_LEASE_ID, res.getLeaseId(), "Incorrect lease ID");
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -28,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8
|
||||
*/
|
||||
class MetadataResponseTest {
|
||||
class MetadataResponseTest extends AbstractModelTest<MetadataResponse> {
|
||||
private static final String V1_TIME = "2018-03-22T02:24:06.945319214Z";
|
||||
private static final String V3_TIME = "2018-03-22T02:36:43.986212308Z";
|
||||
private static final String V2_TIME = "2018-03-22T02:36:33.954880664Z";
|
||||
@ -63,6 +64,20 @@ class MetadataResponseTest {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
MetadataResponseTest() {
|
||||
super(MetadataResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetadataResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(META_JSON, MetadataResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
||||
*/
|
||||
@ -89,9 +104,4 @@ class MetadataResponseTest {
|
||||
assertNotNull(res.getMetadata().getVersions().get(2).getCreatedTime(), "Parsing version created failed");
|
||||
assertFalse(res.getMetadata().getVersions().get(3).isDestroyed(), "Incorrect version 3 destroyed state");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(MetadataResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Stefan Kalscheuer
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JUnit Test for {@link PlainSecretResponse} model.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class PlainSecretResponseTest extends AbstractModelTest<PlainSecretResponse> {
|
||||
private static final String SECRET_REQUEST_ID = "68315073-6658-e3ff-2da7-67939fb91bbd";
|
||||
private static final String SECRET_LEASE_ID = "";
|
||||
private static final Integer SECRET_LEASE_DURATION = 2764800;
|
||||
private static final boolean SECRET_RENEWABLE = false;
|
||||
private static final String SECRET_DATA_K1 = "excited";
|
||||
private static final String SECRET_DATA_V1 = "yes";
|
||||
private static final String SECRET_DATA_K2 = "value";
|
||||
private static final String SECRET_DATA_V2 = "world";
|
||||
private static final List<String> SECRET_WARNINGS = null;
|
||||
private static final String SECRET_JSON = "{\n" +
|
||||
" \"request_id\": \"" + SECRET_REQUEST_ID + "\",\n" +
|
||||
" \"lease_id\": \"" + SECRET_LEASE_ID + "\",\n" +
|
||||
" \"lease_duration\": " + SECRET_LEASE_DURATION + ",\n" +
|
||||
" \"renewable\": " + SECRET_RENEWABLE + ",\n" +
|
||||
" \"data\": {\n" +
|
||||
" \"" + SECRET_DATA_K1 + "\": \"" + SECRET_DATA_V1 + "\",\n" +
|
||||
" \"" + SECRET_DATA_K2 + "\": \"" + SECRET_DATA_V2 + "\"\n" +
|
||||
" },\n" +
|
||||
" \"warnings\": " + SECRET_WARNINGS + "\n" +
|
||||
"}";
|
||||
|
||||
PlainSecretResponseTest() {
|
||||
super(PlainSecretResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlainSecretResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(SECRET_JSON, PlainSecretResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
||||
*/
|
||||
@Test
|
||||
void jsonRoundtrip() {
|
||||
SecretResponse res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(SECRET_JSON, PlainSecretResponse.class),
|
||||
"SecretResponse deserialization failed"
|
||||
);
|
||||
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(SECRET_LEASE_ID, res.getLeaseId(), "Incorrect lease ID");
|
||||
assertEquals(SECRET_LEASE_DURATION, res.getLeaseDuration(), "Incorrect lease duration");
|
||||
assertEquals(SECRET_RENEWABLE, res.isRenewable(), "Incorrect renewable status");
|
||||
assertEquals(SECRET_WARNINGS, res.getWarnings(), "Incorrect warnings");
|
||||
assertEquals(SECRET_DATA_V1, res.get(SECRET_DATA_K1), "Response does not contain correct data");
|
||||
assertEquals(SECRET_DATA_V2, res.get(SECRET_DATA_K2), "Response does not contain correct data");
|
||||
}
|
||||
}
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -28,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8
|
||||
*/
|
||||
class SealResponseTest {
|
||||
class SealResponseTest extends AbstractModelTest<SealResponse> {
|
||||
private static final String TYPE = "shamir";
|
||||
private static final Integer THRESHOLD = 3;
|
||||
private static final Integer SHARES = 5;
|
||||
@ -72,6 +73,20 @@ class SealResponseTest {
|
||||
" \"storage_type\": \"" + STORAGE_TYPE + "\"\n" +
|
||||
"}";
|
||||
|
||||
SealResponseTest() {
|
||||
super(SealResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SealResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(RES_UNSEALED, SealResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault when sealed (JSON example close to Vault documentation).
|
||||
*/
|
||||
@ -119,9 +134,4 @@ class SealResponseTest {
|
||||
assertEquals(RECOVERY_SEAL, res.getRecoverySeal(), "Incorrect recovery seal");
|
||||
assertEquals(STORAGE_TYPE, res.getStorageType(), "Incorrect storage type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SealResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JUnit Test for {@link SecretListResponse} model.
|
||||
@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8
|
||||
*/
|
||||
class SecretListResponseTest {
|
||||
class SecretListResponseTest extends AbstractModelTest<SecretListResponse> {
|
||||
private static final String KEY1 = "key1";
|
||||
private static final String KEY2 = "key-2";
|
||||
private static final String JSON = "{\n" +
|
||||
@ -47,6 +47,20 @@ class SecretListResponseTest {
|
||||
" \"renewable\": false\n" +
|
||||
"}";
|
||||
|
||||
SecretListResponseTest() {
|
||||
super(SecretListResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecretListResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(JSON, SecretListResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test JSON deserialization and key getter.
|
||||
*/
|
||||
@ -59,9 +73,4 @@ class SecretListResponseTest {
|
||||
|
||||
assertEquals(List.of(KEY1, KEY2), res.getKeys(), "Unexpected secret keys");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SecretListResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -28,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8
|
||||
*/
|
||||
class SecretVersionResponseTest {
|
||||
class SecretVersionResponseTest extends AbstractModelTest<SecretVersionResponse> {
|
||||
private static final String CREATION_TIME = "2018-03-22T02:24:06.945319214Z";
|
||||
private static final String DELETION_TIME = "2018-03-22T02:36:43.986212308Z";
|
||||
private static final Integer VERSION = 42;
|
||||
@ -42,6 +43,20 @@ class SecretVersionResponseTest {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
SecretVersionResponseTest() {
|
||||
super(SecretVersionResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecretVersionResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(META_JSON, SecretVersionResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
|
||||
*/
|
||||
@ -58,9 +73,4 @@ class SecretVersionResponseTest {
|
||||
assertFalse(res.getMetadata().isDestroyed(), "Incorrect destroyed state");
|
||||
assertEquals(VERSION, res.getMetadata().getVersion(), "Incorrect version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SecretVersionResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,10 @@
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
@ -33,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class TokenResponseTest {
|
||||
class TokenResponseTest extends AbstractModelTest<TokenResponse> {
|
||||
private static final Integer TOKEN_CREATION_TIME = 1457533232;
|
||||
private static final Integer TOKEN_TTL = 2764800;
|
||||
private static final Integer TOKEN_EXPLICIT_MAX_TTL = 0;
|
||||
@ -88,6 +89,20 @@ class TokenResponseTest {
|
||||
" \"auth\": null\n" +
|
||||
"}";
|
||||
|
||||
TokenResponseTest() {
|
||||
super(TokenResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TokenResponse createFull() {
|
||||
try {
|
||||
return new ObjectMapper().readValue(RES_JSON, TokenResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
fail("Creation of full model instance failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
*/
|
||||
@ -135,9 +150,4 @@ class TokenResponseTest {
|
||||
assertEquals(RES_TTL, data.getTtl(), "Incorrect token TTL");
|
||||
assertEquals(TOKEN_TYPE, data.getType(), "Incorrect token type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(TokenResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user