Skip to content

Commit f44baa5

Browse files
committed
1.0+ tests fix
1 parent 70d36df commit f44baa5

1 file changed

Lines changed: 36 additions & 32 deletions

File tree

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

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import java.net.HttpURLConnection;
2323
import java.util.function.Consumer;
2424

25-
/** Sets up and exposes utilities for dealing with a Docker-hosted instance of Vault, for integration tests. */
25+
/**
26+
* Sets up and exposes utilities for dealing with a Docker-hosted instance of Vault, for integration tests.
27+
*/
2628
public class VaultContainer implements TestRule, TestConstants {
2729

2830
private static final Logger LOGGER = LoggerFactory.getLogger(VaultContainer.class);
@@ -32,9 +34,11 @@ public class VaultContainer implements TestRule, TestConstants {
3234
private String rootToken;
3335
private String unsealKey;
3436

35-
/** Establishes a running Docker container, hosting a Vault server instance. */
37+
/**
38+
* Establishes a running Docker container, hosting a Vault server instance.
39+
*/
3640
public VaultContainer() {
37-
container = new GenericContainer("vault:0.9.1")
41+
container = new GenericContainer("vault:1.0.1")
3842
.withClasspathResourceMapping("/startup.sh", CONTAINER_STARTUP_SCRIPT, BindMode.READ_ONLY)
3943
.withClasspathResourceMapping("/config.json", CONTAINER_CONFIG_FILE, BindMode.READ_ONLY)
4044
.withClasspathResourceMapping("/libressl.conf", CONTAINER_OPENSSL_CONFIG_FILE, BindMode.READ_ONLY)
@@ -49,23 +53,23 @@ public void accept(final CreateContainerCmd createContainerCmd) {
4953
.withExposedPorts(8200, 8280)
5054
.withCommand("/bin/sh " + CONTAINER_STARTUP_SCRIPT)
5155
.waitingFor(
52-
// All of the tests in this integration test suite use HTTPS connections. However, Vault
53-
// is configured to run a plain HTTP listener on port 8280, purely for purposes of detecting
54-
// when the Docker container is fully ready.
55-
//
56-
// Unfortunately, we can't use HTTPS at this point in the flow. Because that would require
57-
// configuring SSL to trust the self-signed cert that's generated inside of the Docker
58-
// container. A chicken-and-egg problem, as we need to wait for the container to be fully
59-
// ready before we access that cert.
60-
new HttpWaitStrategy() {
61-
@Override
62-
protected Integer getLivenessCheckPort() {
63-
return container.getMappedPort(8280);
64-
}
65-
}
66-
.forPath("/v1/sys/seal-status")
67-
.forStatusCode(HttpURLConnection.HTTP_BAD_REQUEST) // The expected response when "vault init" has not yet run
68-
);
56+
// All of the tests in this integration test suite use HTTPS connections. However, Vault
57+
// is configured to run a plain HTTP listener on port 8280, purely for purposes of detecting
58+
// when the Docker container is fully ready.
59+
//
60+
// Unfortunately, we can't use HTTPS at this point in the flow. Because that would require
61+
// configuring SSL to trust the self-signed cert that's generated inside of the Docker
62+
// container. A chicken-and-egg problem, as we need to wait for the container to be fully
63+
// ready before we access that cert.
64+
new HttpWaitStrategy() {
65+
@Override
66+
protected Integer getLivenessCheckPort() {
67+
return container.getMappedPort(8280);
68+
}
69+
}
70+
.forPath("/v1/sys/seal-status")
71+
.forStatusCode(HttpURLConnection.HTTP_OK) // The expected response when "vault init" has not yet run
72+
);
6973
}
7074

7175
/**
@@ -86,7 +90,7 @@ public Statement apply(final Statement base, final Description description) {
8690
* when placed inside of the constructor or {@link this#apply(Statement, Description)} methods here, presumably
8791
* because the Docker container spawned by TestContainers is not ready to accept commonds until after those
8892
* methods complete.
89-
*
93+
* <p>
9094
* This method initializes the Vault server, capturing the unseal key and root token that are displayed on the
9195
* console. It then uses the key to unseal the Vault instance, and stores the token in a member field so it
9296
* will be available to other methods.
@@ -99,15 +103,15 @@ public void initAndUnsealVault() throws IOException, InterruptedException {
99103
container.followOutput(logConsumer);
100104

101105
// Initialize the Vault server
102-
final Container.ExecResult initResult = runCommand("vault", "init", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-key-shares=1", "-key-threshold=1");
106+
final Container.ExecResult initResult = runCommand("vault", "operator", "init", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-key-shares=1", "-key-threshold=1");
103107
final String[] initLines = initResult.getStdout().split(System.lineSeparator());
104108
this.unsealKey = initLines[0].replace("Unseal Key 1: ", "");
105-
this.rootToken = initLines[1].replace("Initial Root Token: ", "");
109+
this.rootToken = initLines[2].replace("Initial Root Token: ", "");
106110

107111
System.out.println("Root token: " + rootToken.toString());
108112

109113
// Unseal the Vault server
110-
runCommand("vault", "unseal", "-ca-cert=" + CONTAINER_CERT_PEMFILE, unsealKey);
114+
runCommand("vault", "operator", "unseal", "-ca-cert=" + CONTAINER_CERT_PEMFILE, unsealKey);
111115
}
112116

113117
/**
@@ -118,9 +122,9 @@ public void initAndUnsealVault() throws IOException, InterruptedException {
118122
* @throws InterruptedException
119123
*/
120124
public void setupBackendAppId() throws IOException, InterruptedException {
121-
runCommand("vault", "auth", "-ca-cert=" + CONTAINER_CERT_PEMFILE, rootToken);
125+
runCommand("vault", "login", "-ca-cert=" + CONTAINER_CERT_PEMFILE, rootToken);
122126

123-
runCommand("vault", "auth-enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "app-id");
127+
runCommand("vault", "auth", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "app-id");
124128
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "auth/app-id/map/app-id/" + APP_ID, "display_name=" + APP_ID);
125129
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "auth/app-id/map/user-id/" + USER_ID, "value=" + APP_ID);
126130
}
@@ -135,7 +139,7 @@ public void setupBackendAppId() throws IOException, InterruptedException {
135139
public void setupBackendUserPass() throws IOException, InterruptedException {
136140
runCommand("vault", "auth", "-ca-cert=" + CONTAINER_CERT_PEMFILE, rootToken);
137141

138-
runCommand("vault", "auth-enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "userpass");
142+
runCommand("vault", "auth", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "userpass");
139143
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "auth/userpass/users/" + USER_ID, "password=" + PASSWORD);
140144
}
141145

@@ -149,9 +153,9 @@ public void setupBackendUserPass() throws IOException, InterruptedException {
149153
public void setupBackendAppRole() throws IOException, InterruptedException {
150154
runCommand("vault", "auth", "-ca-cert=" + CONTAINER_CERT_PEMFILE, rootToken);
151155

152-
runCommand("vault", "auth-enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "approle");
156+
runCommand("vault", "auth", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "approle");
153157
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "auth/approle/role/testrole",
154-
"secret_id_ttl=10m", "token_ttl=20m", "token_max_ttl=30m", "secret_id_num_uses=40");
158+
"secret_id_ttl=10m", "token_ttl=20m", "token_max_ttl=30m", "secret_id_num_uses=40");
155159
}
156160

157161
/**
@@ -166,7 +170,7 @@ public void setupBackendPki() throws IOException, InterruptedException {
166170
runCommand("vault", "mount", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=pki", "pki");
167171
runCommand("vault", "mount", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "-path=other-pki", "pki");
168172
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "pki/root/generate/internal",
169-
"common_name=myvault.com", "ttl=99h");
173+
"common_name=myvault.com", "ttl=99h");
170174
}
171175

172176
/**
@@ -179,9 +183,9 @@ public void setupBackendPki() throws IOException, InterruptedException {
179183
public void setupBackendCert() throws IOException, InterruptedException {
180184
runCommand("vault", "auth", "-ca-cert=" + CONTAINER_CERT_PEMFILE, rootToken);
181185

182-
runCommand("vault", "auth-enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "cert");
186+
runCommand("vault", "auth", "enable", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "cert");
183187
runCommand("vault", "write", "-ca-cert=" + CONTAINER_CERT_PEMFILE, "auth/cert/certs/web", "display_name=web",
184-
"policies=web,prod", "certificate=@" + CONTAINER_CLIENT_CERT_PEMFILE, "ttl=3600");
188+
"policies=web,prod", "certificate=@" + CONTAINER_CLIENT_CERT_PEMFILE, "ttl=3600");
185189
}
186190

187191
/**

0 commit comments

Comments
 (0)