Skip to content

Commit 7603d59

Browse files
Fixes integration tests
1 parent 6e55c0f commit 7603d59

File tree

4 files changed

+33
-40
lines changed

4 files changed

+33
-40
lines changed

src/main/java/com/bettercloud/vault/SslConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ private SSLContext buildSslContextFromPem() throws VaultException {
571571
// Convert the client private key into a PrivateKey
572572
final String strippedKey = clientKeyPemUTF8.replace("-----BEGIN PRIVATE KEY-----", "")
573573
.replace("-----END PRIVATE KEY-----", "");
574-
final byte[] keyBytes = Base64.getDecoder().decode(strippedKey);
574+
final byte[] keyBytes = Base64.getMimeDecoder().decode(strippedKey);
575575
final PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyBytes);
576576
final KeyFactory factory = KeyFactory.getInstance("RSA");
577577
final PrivateKey privateKey = factory.generatePrivate(pkcs8EncodedKeySpec);

src/test-integration/java/com/bettercloud/vault/api/MountsTests.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class MountsTests {
3535
@BeforeClass
3636
public static void setupClass() throws IOException, InterruptedException {
3737
container.initAndUnsealVault();
38-
container.setupBackendMounts();
38+
container.setupBackendPki();
3939
}
4040

4141
@Test
@@ -45,9 +45,9 @@ public void testList() throws VaultException {
4545
final MountResponse response = vault.mounts().list();
4646
final Map<String, Mount> mounts = response.getMounts();
4747

48-
assertTrue(mounts.containsKey("pki/custom-path-1/"));
49-
assertTrue(mounts.containsKey("pki/custom-path-2/"));
50-
assertTrue(mounts.containsKey("pki/custom-path-3/"));
48+
assertTrue(mounts.containsKey("pki-custom-path-1/"));
49+
assertTrue(mounts.containsKey("pki-custom-path-2/"));
50+
assertTrue(mounts.containsKey("pki-custom-path-3/"));
5151
}
5252

5353
@Test
@@ -59,15 +59,15 @@ public void testEnable() throws VaultException {
5959
.maxLeaseTtl(TimeToLive.of(12, TimeUnit.HOURS))
6060
.description("description for pki engine");
6161

62-
final MountResponse response = vault.mounts().enable("pki/itest-path-1", MountType.PKI, payload);
62+
final MountResponse response = vault.mounts().enable("pki-itest-path-1", MountType.PKI, payload);
6363

6464
assertEquals(204, response.getRestResponse().getStatus());
6565
}
6666

6767
@Test
6868
public void testEnableExceptionAlreadyExist() throws VaultException {
6969
expectedEx.expect(VaultException.class);
70-
expectedEx.expectMessage("existing mount at");
70+
expectedEx.expectMessage("path is already in use");
7171

7272
final Vault vault = container.getRootVault();
7373

@@ -76,7 +76,7 @@ public void testEnableExceptionAlreadyExist() throws VaultException {
7676
.maxLeaseTtl(TimeToLive.of(168, TimeUnit.HOURS))
7777
.description("description for pki engine");
7878

79-
vault.mounts().enable("pki/custom-path-1", MountType.PKI, payload);
79+
vault.mounts().enable("pki-custom-path-1", MountType.PKI, payload);
8080
}
8181

8282
@Test
@@ -91,7 +91,7 @@ public void testEnableExceptionNullType() throws VaultException {
9191
.maxLeaseTtl(TimeToLive.of(30, TimeUnit.MINUTES))
9292
.description("description for pki engine");
9393

94-
vault.mounts().enable("pki/itest-path-2", null, payload);
94+
vault.mounts().enable("pki-itest-path-2", null, payload);
9595
}
9696

9797
@Test
@@ -103,7 +103,7 @@ public void testEnableExceptionNullTimeUnit() throws VaultException {
103103
final MountPayload payload = new MountPayload()
104104
.defaultLeaseTtl(TimeToLive.of(7, null));
105105

106-
vault.mounts().enable("pki/itest-path-3", MountType.PKI, payload);
106+
vault.mounts().enable("pki-itest-path-3", MountType.PKI, payload);
107107
}
108108

109109
@Test
@@ -116,14 +116,14 @@ public void testEnableExceptionInvalidTimeUnit() throws VaultException {
116116
final MountPayload payload = new MountPayload()
117117
.defaultLeaseTtl(TimeToLive.of(7, TimeUnit.DAYS));
118118

119-
vault.mounts().enable("pki/itest-path-4", MountType.PKI, payload);
119+
vault.mounts().enable("pki-itest-path-4", MountType.PKI, payload);
120120
}
121121

122122
@Test
123123
public void testDisable() throws VaultException {
124124
final Vault vault = container.getRootVault();
125125

126-
final MountResponse response = vault.mounts().disable("pki/custom-path-3");
126+
final MountResponse response = vault.mounts().disable("pki-custom-path-3");
127127

128128
assertEquals(204, response.getRestResponse().getStatus());
129129
}
@@ -136,9 +136,9 @@ public void testRead() throws VaultException {
136136
.defaultLeaseTtl(TimeToLive.of(360, TimeUnit.MINUTES))
137137
.maxLeaseTtl(TimeToLive.of(360, TimeUnit.MINUTES));
138138

139-
vault.mounts().enable("pki/predefined-path-1", MountType.PKI, payload);
139+
vault.mounts().enable("pki-predefined-path-1", MountType.PKI, payload);
140140

141-
final MountResponse response = vault.mounts().read("pki/predefined-path-1");
141+
final MountResponse response = vault.mounts().read("pki-predefined-path-1");
142142
final Mount mount = response.getMount();
143143
final MountConfig config = mount.getConfig();
144144

@@ -155,7 +155,7 @@ public void testReadExceptionNotFound() throws VaultException {
155155

156156
final Vault vault = container.getRootVault();
157157

158-
vault.mounts().read("pki/non-existing-path");
158+
vault.mounts().read("pki-non-existing-path");
159159
}
160160

161161
@Test
@@ -166,17 +166,17 @@ public void testTune() throws VaultException {
166166
.defaultLeaseTtl(TimeToLive.of(6, TimeUnit.HOURS))
167167
.maxLeaseTtl(TimeToLive.of(6, TimeUnit.HOURS));
168168

169-
vault.mounts().enable("pki/predefined-path-2", MountType.PKI, enablePayload);
169+
vault.mounts().enable("pki-predefined-path-2", MountType.PKI, enablePayload);
170170

171171
final MountPayload tunePayload = new MountPayload()
172172
.defaultLeaseTtl(TimeToLive.of(12, TimeUnit.HOURS))
173173
.maxLeaseTtl(TimeToLive.of(12, TimeUnit.HOURS));
174174

175-
final MountResponse tuneResponse = vault.mounts().tune("pki/predefined-path-2", tunePayload);
175+
final MountResponse tuneResponse = vault.mounts().tune("pki-predefined-path-2", tunePayload);
176176

177177
assertEquals(204, tuneResponse.getRestResponse().getStatus());
178178

179-
final MountResponse response = vault.mounts().read("pki/predefined-path-2");
179+
final MountResponse response = vault.mounts().read("pki-predefined-path-2");
180180
final Mount mount = response.getMount();
181181
final MountConfig config = mount.getConfig();
182182

@@ -195,6 +195,6 @@ public void testTuneExceptionNotFound() throws VaultException {
195195
.defaultLeaseTtl(TimeToLive.of(24, TimeUnit.HOURS))
196196
.maxLeaseTtl(TimeToLive.of(24, TimeUnit.HOURS));
197197

198-
vault.mounts().tune("pki/non-existing-path", tunePayload);
198+
vault.mounts().tune("pki-non-existing-path", tunePayload);
199199
}
200200
}

src/test-integration/java/com/bettercloud/vault/util/SSLUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private static X509Certificate generateCert(final KeyPair keyPair, final String
179179
*/
180180
private static void writeCertToPem(final X509Certificate certificate, final String filename)
181181
throws CertificateEncodingException, FileNotFoundException {
182-
final Base64.Encoder encoder = Base64.getEncoder();
182+
final Base64.Encoder encoder = Base64.getMimeEncoder();
183183

184184
final String certHeader = "-----BEGIN CERTIFICATE-----\n";
185185
final String certFooter = "\n-----END CERTIFICATE-----";
@@ -199,7 +199,7 @@ private static void writeCertToPem(final X509Certificate certificate, final Stri
199199
* @throws FileNotFoundException
200200
*/
201201
private static void writePrivateKeyToPem(final PrivateKey key, final String filename) throws FileNotFoundException {
202-
final Base64.Encoder encoder = Base64.getEncoder();
202+
final Base64.Encoder encoder = Base64.getMimeEncoder();
203203

204204
final String keyHeader = "-----BEGIN PRIVATE KEY-----\n";
205205
final String keyFooter = "\n-----END PRIVATE KEY-----";

src/test-integration/java/com/bettercloud/vault/util/VaultContainer.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ public void initAndUnsealVault() throws IOException, InterruptedException {
105105
// Initialize the Vault server
106106
final Container.ExecResult initResult = runCommand("vault", "operator", "init", "-ca-cert=" +
107107
CONTAINER_CERT_PEMFILE, "-key-shares=1", "-key-threshold=1");
108-
final String[] initLines = initResult.getStdout().split(System.lineSeparator());
109-
this.unsealKey = initLines[0].replace("Unseal Key 1: ", "");
110-
this.rootToken = initLines[2].replace("Initial Root Token: ", "");
108+
final String stdout = initResult.getStdout().replaceAll(System.lineSeparator(), "").split("Vault initialized")[0];
109+
final String[] tokens = stdout.split("Initial Root Token: ");
110+
this.unsealKey = tokens[0].replace("Unseal Key 1: ", "");
111+
this.rootToken = tokens[1];
111112

112-
System.out.println("Root token: " + rootToken.toString());
113+
System.out.println("Root token: " + rootToken);
113114

114115
// Unseal the Vault server
115116
runCommand("vault", "operator", "unseal", "-ca-cert=" + CONTAINER_CERT_PEMFILE, unsealKey);
@@ -173,6 +174,11 @@ public void setupBackendPki() throws IOException, InterruptedException {
173174

174175
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki", "pki");
175176
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=other-pki", "pki");
177+
178+
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki-custom-path-1", "pki");
179+
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki-custom-path-2", "pki");
180+
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki-custom-path-3", "pki");
181+
176182
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "pki/root/generate/internal",
177183
"common_name=myvault.com", "ttl=99h");
178184
}
@@ -193,26 +199,13 @@ public void setupBackendCert() throws IOException, InterruptedException {
193199
}
194200

195201
public void setEngineVersions() throws IOException, InterruptedException {
196-
//Upgrade default secrets/ Engine to V2, set a new V1 secrets path at "kv-v1/"
202+
// Upgrade default secrets/ Engine to V2, set a new V1 secrets path at "kv-v1/"
197203
runCommand("vault", "kv", "enable-versioning", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "secret/");
204+
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=secret", "-version=2", "kv");
198205
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=kv-v1", "-version=1", "kv");
199206
runCommand("vault", "secrets", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=kv-v1-Upgrade-Test", "-version=1", "kv");
200207
}
201208

202-
/**
203-
* Prepares the Vault server for testing of the Mounts backend (i.e. mounts the backend and enable test secret engines).
204-
*
205-
* @throws IOException
206-
* @throws InterruptedException
207-
*/
208-
public void setupBackendMounts() throws IOException, InterruptedException {
209-
runCommand("vault", "auth", "-ca-cert=" + CONTAINER_CERT_PEMFILE, rootToken);
210-
211-
runCommand("vault", "mount", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki/custom-path-1", "pki");
212-
runCommand("vault", "mount", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki/custom-path-2", "pki");
213-
runCommand("vault", "mount", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki/custom-path-3", "pki");
214-
}
215-
216209
/**
217210
* <p>Constructs an instance of the Vault driver, providing maximum flexibility to control all options
218211
* explicitly.</p>

0 commit comments

Comments
 (0)