Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
9710d59821 | |||
30d426303e | |||
ca9da6bd0f | |||
9fedb3f88b | |||
596a097707 | |||
d51421cb14 | |||
ffea9bfbfe | |||
ffdc0f6a27 | |||
9b5c537e55 | |||
a9f1eb63c2 | |||
fd749b19e5 | |||
0cca2de1aa | |||
8b278f67fe | |||
8f3462b22a | |||
a394cb7f0d | |||
50d0b2fe56 | |||
e2bb09d50f | |||
4a2b40a4cf | |||
bed9c868f6 | |||
7a45af8856 | |||
4bafcec012 |
51
.drone.yml
51
.drone.yml
@ -1,33 +1,26 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
clone:
|
||||
disable: true
|
||||
|
||||
steps:
|
||||
- name: clone
|
||||
image: plugins/git
|
||||
settings:
|
||||
depth: 10
|
||||
skip_verify: true
|
||||
- name: test-online
|
||||
image: maven:3-jdk-11-slim
|
||||
commands:
|
||||
- export VAULT_VERSION=1.1.0
|
||||
- wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
- wget -q -O - https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_SHA256SUMS | grep linux_amd64 | sha256sum -c
|
||||
- unzip vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
- rm vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
- mv vault /bin/
|
||||
- mvn clean test
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
- name: test-offline
|
||||
image: maven:3-jdk-11-slim
|
||||
commands:
|
||||
- mvn clean test -Dtest='!HTTPVaultConnectorTest'
|
||||
when:
|
||||
branch:
|
||||
- develop
|
||||
- feature/*
|
||||
- name: test-online
|
||||
image: maven:3-jdk-11
|
||||
environment:
|
||||
VAULT_VERSION: 1.2.3
|
||||
commands:
|
||||
- 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:
|
||||
branch:
|
||||
- master
|
||||
- name: test-offline
|
||||
image: maven:3-jdk-11
|
||||
commands:
|
||||
- mvn clean test -P offline-tests
|
||||
when:
|
||||
branch:
|
||||
- develop
|
||||
- feature/*
|
||||
|
23
.travis.yml
23
.travis.yml
@ -1,6 +1,3 @@
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
language: java
|
||||
jdk:
|
||||
- openjdk11
|
||||
@ -11,18 +8,26 @@ 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.1.0
|
||||
- PATH=$PATH:. VAULT_VERSION=1.2.3
|
||||
before_script:
|
||||
- wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
- wget -q -O - https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_SHA256SUMS | grep linux_amd64 | sha256sum -c
|
||||
- unzip vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
- rm vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
- |
|
||||
if [ "$TRAVIS_BRANCH" = "master" ]; then
|
||||
wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
wget -q -O - https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_SHA256SUMS | grep linux_amd64 | sha256sum -c
|
||||
unzip vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
rm vault_${VAULT_VERSION}_linux_amd64.zip
|
||||
fi
|
||||
cache:
|
||||
directories:
|
||||
- '$HOME/.m2/repository'
|
||||
- '$HOME/.sonar/cache'
|
||||
script:
|
||||
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
|
||||
- |
|
||||
if [ "$TRAVIS_BRANCH" = "master" ]; then
|
||||
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
|
||||
else
|
||||
mvn clean test -P offline-tests
|
||||
fi
|
||||
notifications:
|
||||
slack:
|
||||
secure: "YyE5GePOLkCVTtCy8j507BRmQrtrWhtvmUt4kY0Z2/ptf0LzfuDEJQ4ZbCxO5ri5IDJrrvyPAedjft818+bMzdFfxvi1oviIL+LZNhyev8gfeIBF/U2pvSLGKCRX4g4aZ6NKN3Untjdm8lmiVTltOyZ59JizQVwXzAl3LiOpnJugyBqbhOx4EIqBzwW3gaYAofMqY2LczW5W/M+99HJCst8Mb8H06GstCPEHCizAq7VRaUS68PstlxQMV0Q6bsSYMLFbLWmhuXs96WHqOrT+nNsl07ikr3N8c4HafhFutt2Jyc1+8gXO417+eSvVM0iBpHGwTmfGFfCqx/4Pf62DTJuvh8dR4fLgLDiqEeDrBEcRRDOs9cvXVOO22NN1HuBBJY8VRiFcwNAvuVMXCtnC+1RJRAZB2zubsANiFe+ygk/ywj37cVXY+NpqlBwcSph6jPHo2hD6cIl2rTWn1EnZH519Rh38xTSv6MRzAO9kWNVrAlX+UtvYS8Sk7Owrc0tET9Lc4zj6aI5tsA1wYbN3Jk6EbMhsF6K/XF2npt2qg09pxkj8wmxoUoR6/rGuSv55aSxTdLDmH+en4ahEm3uc4h1lYoVCk0yrZoTAas3zS4WpBCKnl+mweuKNxaejyy0Wv6NR9ZCTaS3yFgibNOjvDpxZxTAPdNBL7hn+k4LwgN4="
|
||||
|
18
CHANGELOG.md
18
CHANGELOG.md
@ -1,3 +1,21 @@
|
||||
## 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 dependencies
|
||||
|
||||
### Test
|
||||
* Tested against Vault 1.2.2
|
||||
|
||||
## 0.8.0 (2019-03-24)
|
||||
### Breaking
|
||||
* Moved Maven artifact to `de.stklcode.jvault:jvault-connector` (#28)
|
||||
|
@ -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.1.0
|
||||
* 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.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
145
pom.xml
145
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>de.stklcode.jvault</groupId>
|
||||
<artifactId>jvault-connector</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@ -71,7 +71,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.1.2</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
@ -88,7 +88,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<version>2.22.2</version>
|
||||
<configuration>
|
||||
<reuseForks>false</reuseForks>
|
||||
</configuration>
|
||||
@ -98,60 +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.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.9.8</version>
|
||||
<version>4.5.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.8</version>
|
||||
<version>2.10.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.4.1</version>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.5.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-migrationsupport</artifactId>
|
||||
<version>5.4.1</version>
|
||||
</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>2.25.1</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>2.25.1</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>
|
||||
@ -174,7 +176,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
@ -198,7 +200,10 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@ -211,5 +216,75 @@
|
||||
</plugins>
|
||||
</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>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludedGroups>online</excludedGroups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,9 @@ package de.stklcode.jvault.connector;
|
||||
import de.stklcode.jvault.connector.builder.HTTPVaultConnectorBuilder;
|
||||
import de.stklcode.jvault.connector.builder.VaultConnectorBuilder;
|
||||
import de.stklcode.jvault.connector.exception.*;
|
||||
import de.stklcode.jvault.connector.model.*;
|
||||
import de.stklcode.jvault.connector.model.AppRole;
|
||||
import de.stklcode.jvault.connector.model.AuthBackend;
|
||||
import de.stklcode.jvault.connector.model.Token;
|
||||
import de.stklcode.jvault.connector.model.response.*;
|
||||
import de.stklcode.jvault.connector.test.Credentials;
|
||||
import de.stklcode.jvault.connector.test.VaultConfiguration;
|
||||
@ -37,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.
|
||||
@ -50,8 +50,9 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.1
|
||||
*/
|
||||
@Tag("online")
|
||||
public class HTTPVaultConnectorTest {
|
||||
private static String VAULT_VERSION = "1.1.0"; // 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";
|
||||
@ -289,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 {
|
||||
@ -330,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 {
|
||||
@ -457,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());
|
||||
}
|
||||
@ -1025,7 +1026,7 @@ public class HTTPVaultConnectorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test revocation of secrets.
|
||||
* Test token creation.
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
@ -1100,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,23 +38,19 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@EnableRuleMigrationSupport
|
||||
public class HTTPVaultConnectorBuilderTest {
|
||||
private static String VAULT_ADDR = "https://localhost:8201";
|
||||
private static Integer VAULT_MAX_RETRIES = 13;
|
||||
private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777";
|
||||
private static final String VAULT_ADDR = "https://localhost:8201";
|
||||
private static final Integer VAULT_MAX_RETRIES = 13;
|
||||
private static final String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777";
|
||||
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
@Rule
|
||||
public final EnvironmentVariables environment = new EnvironmentVariables();
|
||||
|
||||
/**
|
||||
* Test building from environment variables
|
||||
*/
|
||||
@Test
|
||||
public void testFromEnv() throws NoSuchFieldException, IllegalAccessException, IOException {
|
||||
void testFromEnv() throws NoSuchFieldException, IllegalAccessException, IOException {
|
||||
/* Provide address only should be enough */
|
||||
setenv(VAULT_ADDR, null, null, null);
|
||||
|
||||
@ -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