Improve test skipping for Consul.
See gh-273.
This commit is contained in:
@@ -37,9 +37,11 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Base64Utils;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.springframework.cloud.vault.config.consul.VaultConfigConsulBootstrapConfiguration.ConsulSecretBackendMetadataFactory.forConsul;
|
||||
|
||||
@@ -94,16 +96,27 @@ public class ConsulSecretIntegrationTests extends IntegrationTestSupport {
|
||||
headers.add("X-Consul-Token", CONSUL_ACL_MASTER_TOKEN);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(
|
||||
"{\"Name\": \"sample\", \"Type\": \"management\"}", headers);
|
||||
ResponseEntity<Map<String, String>> tokenResponse = this.restTemplate.exchange(
|
||||
"http://{host}:{port}/v1/acl/create", HttpMethod.PUT, requestEntity,
|
||||
STRING_MAP, CONSUL_HOST, CONSUL_PORT);
|
||||
|
||||
Map<String, String> consulAccess = new HashMap<>();
|
||||
consulAccess.put("address", CONNECTION_URL);
|
||||
consulAccess.put("token", tokenResponse.getBody().get("ID"));
|
||||
try {
|
||||
ResponseEntity<Map<String, String>> tokenResponse = this.restTemplate
|
||||
.exchange("http://{host}:{port}/v1/acl/create", HttpMethod.PUT,
|
||||
requestEntity, STRING_MAP, CONSUL_HOST, CONSUL_PORT);
|
||||
|
||||
vaultOperations.write(String.format("%s/config/access", this.consul.getBackend()),
|
||||
consulAccess);
|
||||
Map<String, String> consulAccess = new HashMap<>();
|
||||
consulAccess.put("address", CONNECTION_URL);
|
||||
consulAccess.put("token", tokenResponse.getBody().get("ID"));
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/config/access", this.consul.getBackend()),
|
||||
consulAccess);
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
assumeFalse("Skipping because Consul is not configured as we expect it to be",
|
||||
e.getStatusCode().is4xxClientError());
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/roles/%s", this.consul.getBackend(),
|
||||
|
||||
@@ -39,9 +39,11 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
@@ -94,18 +96,28 @@ public class VaultConfigConsulTests {
|
||||
headers.add("X-Consul-Token", CONSUL_ACL_MASTER_TOKEN);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(
|
||||
"{\"Name\": \"sample\", \"Type\": \"management\"}", headers);
|
||||
ResponseEntity<Map<String, String>> tokenResponse = restTemplate.exchange(
|
||||
"http://{host}:{port}/v1/acl/create", HttpMethod.PUT, requestEntity,
|
||||
STRING_MAP, CONSUL_HOST, CONSUL_PORT);
|
||||
|
||||
Map<String, String> consulAccess = new HashMap<>();
|
||||
consulAccess.put("address", CONNECTION_URL);
|
||||
consulAccess.put("token", tokenResponse.getBody().get("ID"));
|
||||
try {
|
||||
ResponseEntity<Map<String, String>> tokenResponse = restTemplate.exchange(
|
||||
"http://{host}:{port}/v1/acl/create", HttpMethod.PUT, requestEntity,
|
||||
STRING_MAP, CONSUL_HOST, CONSUL_PORT);
|
||||
|
||||
vaultOperations.write("consul/config/access", consulAccess);
|
||||
Map<String, String> consulAccess = new HashMap<>();
|
||||
consulAccess.put("address", CONNECTION_URL);
|
||||
consulAccess.put("token", tokenResponse.getBody().get("ID"));
|
||||
|
||||
vaultOperations.write("consul/roles/readonly", Collections.singletonMap("policy",
|
||||
new String(Base64.getEncoder().encode(POLICY.getBytes()))));
|
||||
vaultOperations.write("consul/config/access", consulAccess);
|
||||
|
||||
vaultOperations.write("consul/roles/readonly", Collections.singletonMap(
|
||||
"policy", new String(Base64.getEncoder().encode(POLICY.getBytes()))));
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
assumeFalse("Skipping because Consul is not configured as we expect it to be",
|
||||
e.getStatusCode().is4xxClientError());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${spring.cloud.consul.token}")
|
||||
|
||||
Reference in New Issue
Block a user