Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
9710d59821 | |||
30d426303e | |||
ca9da6bd0f | |||
9fedb3f88b | |||
596a097707 | |||
d51421cb14 | |||
ffea9bfbfe | |||
ffdc0f6a27 | |||
9b5c537e55 |
10
.drone.yml
10
.drone.yml
@ -5,12 +5,12 @@ steps:
|
||||
- name: test-online
|
||||
image: maven:3-jdk-11
|
||||
environment:
|
||||
VAULT_VERSION: 1.2.2
|
||||
VAULT_VERSION: 1.2.3
|
||||
commands:
|
||||
- curl -o vault_1.2.2_linux_amd64.zip https://releases.hashicorp.com/vault/1.2.2/vault_1.2.2_linux_amd64.zip
|
||||
- curl -s https://releases.hashicorp.com/vault/1.2.2/vault_1.2.2_SHA256SUMS | grep linux_amd64 | sha256sum -c
|
||||
- unzip vault_1.2.2_linux_amd64.zip
|
||||
- rm vault_1.2.2_linux_amd64.zip
|
||||
- curl -o vault_1.2.3_linux_amd64.zip https://releases.hashicorp.com/vault/1.2.3/vault_1.2.3_linux_amd64.zip
|
||||
- curl -s https://releases.hashicorp.com/vault/1.2.3/vault_1.2.3_SHA256SUMS | grep linux_amd64 | sha256sum -c
|
||||
- unzip vault_1.2.3_linux_amd64.zip
|
||||
- rm vault_1.2.3_linux_amd64.zip
|
||||
- mv vault /bin/
|
||||
- mvn clean test
|
||||
when:
|
||||
|
@ -8,7 +8,7 @@ addons:
|
||||
token:
|
||||
secure: "sM9OfX5jW764pn9cb2LSXArnXucKMws+eGeg5NnZxHRcGYt4hpBKLSregBSsBNzUoWVj0zNzPCpnh+UQvgxQzUerOqwEdjTBpy3SNPaxSn7UpoSg+Wz3aUmL9ugmx01b51/wMG4UCHEwTZt2tpgTPVtw8K6uSO78e0dSICCBHDnRcdQwOjMEQHIJJ/qHVRwuy/MzLCAP3W1JPZlsphZg9QsFyhB4hW97dE90joZezfocQIv2xI/r6k+BLz0pY6MxYCul0RiDumaiaej0CPvEJI/uSu//BAQjUdHw+mQgnKUYIbrn2ONOviwNfwdr94JyoZEN2B6zASUmNLjPf4AbIojDeyS+CrpQpm17EVm/Qk/Ds+Xra4PPPIcsZhiWzV0KoDUz9xLfXuRJ526VT5tDPiaeI7oETf0+8l+JIS1b399FyqHi7smzjpvC6GuKflQrbuHK4MuKzDh7WTHiqokGG4SS0wOQIaaHB3dfdwwQzPh6IM24e8CETxh3DjMeqUTU4DWmv5po55jZ934TtxVQvVN78bTG9O0zS9u+JmRY04OZ+OaXuFam6MfMUFQi0EPZzdGul/oWSibGUu3bNfVEBp60CnJwYNM/dKG6U7pJthLHvSwiQFOdKzHZ+l1jZJ4gPaXaIGqpwqVGr28ntqA/El1rytPixr2driE6bYMt5jw="
|
||||
env:
|
||||
- PATH=$PATH:. VAULT_VERSION=1.2.2
|
||||
- PATH=$PATH:. VAULT_VERSION=1.2.3
|
||||
before_script:
|
||||
- |
|
||||
if [ "$TRAVIS_BRANCH" = "master" ]; then
|
||||
|
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,9 +1,17 @@
|
||||
## 0.8.2 (2019-10-20)
|
||||
|
||||
### Fixes
|
||||
* Fixed token lookup (#31)
|
||||
|
||||
### Improvements
|
||||
* Updated dependencies
|
||||
|
||||
## 0.8.1 (2019-08-16)
|
||||
### Fixes
|
||||
* Removed compile dependency to JUnit library (#30)
|
||||
|
||||
### Improvements
|
||||
* Updated ependencies
|
||||
* Updated dependencies
|
||||
|
||||
### Test
|
||||
* Tested against Vault 1.2.2
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Java Vault Connector
|
||||
|
||||
[](https://travis-ci.org/stklcode/jvaultconnector)
|
||||
[](https://sonarcloud.io/dashboard?id=de.stklcode.jvault%3Aconnector)
|
||||
[](https://sonarcloud.io/dashboard?id=de.stklcode.jvault%3Ajvault-connector)
|
||||
[](https://github.com/stklcode/jvaultconnector/blob/master/LICENSE.txt)
|
||||
[](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22de.stklcode.jvault%22%20AND%20a%3A%22jvault-connector%22)
|
||||
|
||||
@ -32,7 +32,7 @@ Java Vault Connector is a connector library for [Vault](https://www.vaultproject
|
||||
* SQL secret handling
|
||||
* KV v1 and v2 support
|
||||
* Connector Factory with builder pattern
|
||||
* Tested against Vault 1.2.2
|
||||
* Tested against Vault 1.2.3
|
||||
|
||||
|
||||
## Maven Artifact
|
||||
@ -40,7 +40,7 @@ Java Vault Connector is a connector library for [Vault](https://www.vaultproject
|
||||
<dependency>
|
||||
<groupId>de.stklcode.jvault</groupId>
|
||||
<artifactId>jvault-connector</artifactId>
|
||||
<version>0.8.1</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
114
pom.xml
114
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>de.stklcode.jvault</groupId>
|
||||
<artifactId>jvault-connector</artifactId>
|
||||
<version>0.8.1</version>
|
||||
<version>0.8.2</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@ -98,61 +98,62 @@
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.9.9</version>
|
||||
<version>4.5.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.9.3</version>
|
||||
<version>2.10.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-migrationsupport</artifactId>
|
||||
<version>5.5.1</version>
|
||||
<version>5.5.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-junit</artifactId>
|
||||
<version>2.0.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stefanbirkner</groupId>
|
||||
<artifactId>system-rules</artifactId>
|
||||
<version>1.17.2</version>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy-agent</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Updated transient dependency from mockito-core for JDK 13 compatibility -->
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.9.16</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy-agent</artifactId>
|
||||
<version>1.9.16</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -216,6 +217,31 @@
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>sign</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<keyname>${gpg.keyname}</keyname>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>offline-tests</id>
|
||||
<build>
|
||||
@ -232,5 +258,33 @@
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>sonatype</id>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>local</id>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>local</id>
|
||||
<url>${dist.repo.local}</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>local</id>
|
||||
<url>${dist.repo.local.snapshot}</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
@ -696,7 +696,9 @@ public class HTTPVaultConnector implements VaultConnector {
|
||||
requireAuth();
|
||||
|
||||
/* Request HTTP response and parse Secret */
|
||||
return request.get(PATH_TOKEN + "/lookup/" + token, new HashMap<>(), token, TokenResponse.class);
|
||||
Map<String, String> param = new HashMap<>();
|
||||
param.put("token", token);
|
||||
return request.get(PATH_TOKEN + PATH_LOOKUP, param, token, TokenResponse.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,11 +39,9 @@ import static org.apache.commons.io.FileUtils.copyDirectory;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.junit.MatcherAssume.assumeThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
/**
|
||||
* JUnit test for HTTP Vault connector.
|
||||
@ -54,7 +52,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
*/
|
||||
@Tag("online")
|
||||
public class HTTPVaultConnectorTest {
|
||||
private static String VAULT_VERSION = "1.2.2"; // the vault version this test is supposed to run against
|
||||
private static String VAULT_VERSION = "1.2.3"; // the vault version this test is supposed to run against
|
||||
private static final String KEY1 = "E38bkCm0VhUvpdCKGQpcohhD9XmcHJ/2hreOSY019Lho";
|
||||
private static final String KEY2 = "O5OHwDleY3IiPdgw61cgHlhsrEm6tVJkrxhF6QAnILd1";
|
||||
private static final String KEY3 = "mw7Bm3nbt/UWa/juDjjL2EPQ04kiJ0saC5JEXwJvXYsB";
|
||||
@ -292,7 +290,7 @@ public class HTTPVaultConnectorTest {
|
||||
} catch (VaultConnectorException e) {
|
||||
fail("Written secret could not be read.");
|
||||
}
|
||||
assumeThat(res, is(notNullValue()));
|
||||
assumeTrue(res != null);
|
||||
|
||||
/* Delete secret */
|
||||
try {
|
||||
@ -333,7 +331,7 @@ public class HTTPVaultConnectorTest {
|
||||
} catch (VaultConnectorException e) {
|
||||
fail("Written secret could not be read.");
|
||||
}
|
||||
assumeThat(res, is(notNullValue()));
|
||||
assumeTrue(res != null);
|
||||
|
||||
/* Revoke secret */
|
||||
try {
|
||||
@ -460,7 +458,7 @@ public class HTTPVaultConnectorTest {
|
||||
try {
|
||||
MetadataResponse res = connector.readSecretMetadata(MOUNT_KV2, SECRET2_KEY);
|
||||
maxVersions = res.getMetadata().getMaxVersions();
|
||||
assumeThat("Unexpected maximum number of versions", res.getMetadata().getMaxVersions(), is(10));
|
||||
assumeTrue(res.getMetadata().getMaxVersions() == 10, "Unexpected maximum number of versions");
|
||||
} catch (VaultConnectorException e) {
|
||||
fail("Reading secret metadata failed: " + e.getMessage());
|
||||
}
|
||||
@ -1028,7 +1026,7 @@ public class HTTPVaultConnectorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test revocation of secrets.
|
||||
* Test token creation.
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
@ -1103,6 +1101,37 @@ public class HTTPVaultConnectorTest {
|
||||
assertThat(stackTrace(e), not(stringContainsInOrder(token.getId())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test token lookuo.
|
||||
*/
|
||||
@Test
|
||||
@Order(30)
|
||||
@DisplayName("Lookup token")
|
||||
public void lookupTokenTest() {
|
||||
authRoot();
|
||||
assumeTrue(connector.isAuthorized());
|
||||
|
||||
/* Create token with attributes */
|
||||
Token token = Token.builder()
|
||||
.withId("my-token")
|
||||
.build();
|
||||
try {
|
||||
connector.createToken(token);
|
||||
} catch (VaultConnectorException e) {
|
||||
fail("Token creation failed.");
|
||||
}
|
||||
|
||||
authRoot();
|
||||
assumeTrue(connector.isAuthorized());
|
||||
|
||||
try {
|
||||
TokenResponse res = connector.lookupToken("my-token");
|
||||
assertThat("Unexpected token ID", res.getData().getId(), is(token.getId()));
|
||||
} catch (VaultConnectorException e) {
|
||||
fail("Token creation failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
@ -19,11 +19,9 @@ package de.stklcode.jvault.connector.builder;
|
||||
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
||||
import de.stklcode.jvault.connector.exception.TlsException;
|
||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
||||
import org.junit.Rule;
|
||||
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
||||
import de.stklcode.jvault.connector.test.EnvironmentMock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -40,7 +38,6 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@EnableRuleMigrationSupport
|
||||
public class HTTPVaultConnectorBuilderTest {
|
||||
private static final String VAULT_ADDR = "https://localhost:8201";
|
||||
private static final Integer VAULT_MAX_RETRIES = 13;
|
||||
@ -49,9 +46,6 @@ public class HTTPVaultConnectorBuilderTest {
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
@Rule
|
||||
public final EnvironmentVariables environment = new EnvironmentVariables();
|
||||
|
||||
/**
|
||||
* Test building from environment variables
|
||||
*/
|
||||
@ -112,10 +106,10 @@ public class HTTPVaultConnectorBuilderTest {
|
||||
}
|
||||
|
||||
private void setenv(String vault_addr, String vault_cacert, String vault_max_retries, String vault_token) {
|
||||
environment.set("VAULT_ADDR", vault_addr);
|
||||
environment.set("VAULT_CACERT", vault_cacert);
|
||||
environment.set("VAULT_MAX_RETRIES", vault_max_retries);
|
||||
environment.set("VAULT_TOKEN", vault_token);
|
||||
EnvironmentMock.setenv("VAULT_ADDR", vault_addr);
|
||||
EnvironmentMock.setenv("VAULT_CACERT", vault_cacert);
|
||||
EnvironmentMock.setenv("VAULT_MAX_RETRIES", vault_max_retries);
|
||||
EnvironmentMock.setenv("VAULT_TOKEN", vault_token);
|
||||
}
|
||||
|
||||
private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) throws NoSuchFieldException, IllegalAccessException {
|
||||
|
@ -19,11 +19,9 @@ package de.stklcode.jvault.connector.factory;
|
||||
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
||||
import de.stklcode.jvault.connector.exception.TlsException;
|
||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
||||
import org.junit.Rule;
|
||||
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
||||
import de.stklcode.jvault.connector.test.EnvironmentMock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -40,7 +38,6 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.6.0
|
||||
*/
|
||||
@EnableRuleMigrationSupport
|
||||
public class HTTPVaultConnectorFactoryTest {
|
||||
private static String VAULT_ADDR = "https://localhost:8201";
|
||||
private static Integer VAULT_MAX_RETRIES = 13;
|
||||
@ -49,9 +46,6 @@ public class HTTPVaultConnectorFactoryTest {
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
@Rule
|
||||
public final EnvironmentVariables environment = new EnvironmentVariables();
|
||||
|
||||
/**
|
||||
* Test building from environment variables
|
||||
*/
|
||||
@ -112,10 +106,10 @@ public class HTTPVaultConnectorFactoryTest {
|
||||
}
|
||||
|
||||
private void setenv(String vault_addr, String vault_cacert, String vault_max_retries, String vault_token) {
|
||||
environment.set("VAULT_ADDR", vault_addr);
|
||||
environment.set("VAULT_CACERT", vault_cacert);
|
||||
environment.set("VAULT_MAX_RETRIES", vault_max_retries);
|
||||
environment.set("VAULT_TOKEN", vault_token);
|
||||
EnvironmentMock.setenv("VAULT_ADDR", vault_addr);
|
||||
EnvironmentMock.setenv("VAULT_CACERT", vault_cacert);
|
||||
EnvironmentMock.setenv("VAULT_MAX_RETRIES", vault_max_retries);
|
||||
EnvironmentMock.setenv("VAULT_TOKEN", vault_token);
|
||||
}
|
||||
|
||||
private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) throws NoSuchFieldException, IllegalAccessException {
|
||||
|
@ -29,8 +29,8 @@ import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.junit.MatcherAssume.assumeThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
|
||||
/**
|
||||
@ -143,17 +143,17 @@ public class AppRoleSecretTest {
|
||||
|
||||
/* Test fields, that should not be written to JSON */
|
||||
setPrivateField(secret, "accessor", "TEST_ACCESSOR");
|
||||
assumeThat(secret.getAccessor(), is("TEST_ACCESSOR"));
|
||||
assumeTrue("TEST_ACCESSOR".equals(secret.getAccessor()));
|
||||
setPrivateField(secret, "creationTime", "TEST_CREATION");
|
||||
assumeThat(secret.getCreationTime(), is("TEST_CREATION"));
|
||||
assumeTrue("TEST_CREATION".equals(secret.getCreationTime()));
|
||||
setPrivateField(secret, "expirationTime", "TEST_EXPIRATION");
|
||||
assumeThat(secret.getExpirationTime(), is("TEST_EXPIRATION"));
|
||||
assumeTrue("TEST_EXPIRATION".equals(secret.getExpirationTime()));
|
||||
setPrivateField(secret, "lastUpdatedTime", "TEST_UPDATETIME");
|
||||
assumeThat(secret.getLastUpdatedTime(), is("TEST_UPDATETIME"));
|
||||
assumeTrue("TEST_UPDATETIME".equals(secret.getLastUpdatedTime()));
|
||||
setPrivateField(secret, "numUses", 678);
|
||||
assumeThat(secret.getNumUses(), is(678));
|
||||
assumeTrue(secret.getNumUses() == 678);
|
||||
setPrivateField(secret, "ttl", 12345);
|
||||
assumeThat(secret.getTtl(), is(12345));
|
||||
assumeTrue(secret.getTtl() == 12345);
|
||||
try {
|
||||
secretJson = mapper.writeValueAsString(secret);
|
||||
} catch (JsonProcessingException e) {
|
||||
|
@ -26,7 +26,7 @@ import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* JUnit Test for {@link SecretListResponse} model.
|
||||
@ -50,7 +50,6 @@ public class SecretListResponseTest {
|
||||
* @throws InvalidResponseException Should not occur
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getKeysTest() throws InvalidResponseException {
|
||||
// Create empty Object.
|
||||
SecretListResponse res = new SecretListResponse();
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2016-2019 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.test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Test helper to modify system environment.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EnvironmentMock {
|
||||
private static Map<String, String> environment;
|
||||
|
||||
static {
|
||||
try {
|
||||
Map<String, String> originalEnv = System.getenv();
|
||||
Field mapField = originalEnv.getClass().getDeclaredField("m");
|
||||
mapField.setAccessible(true);
|
||||
environment = (Map<String, String>) mapField.get(originalEnv);
|
||||
} catch (NoSuchFieldException | IllegalAccessException | ClassCastException e) {
|
||||
fail("Failed to intercept unmodifiable system environment");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setenv(String key, String value) {
|
||||
if (value != null) {
|
||||
environment.put(key, value);
|
||||
} else {
|
||||
environment.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user