Use AuthenticationSteps factory methods in tests.
See gh-107.
This commit is contained in:
@@ -175,5 +175,4 @@ public class AuthenticationStepsExecutor implements ClientAuthentication {
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.vault.util.Settings;
|
||||
import org.springframework.vault.util.TestWebClientFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
@@ -42,11 +41,8 @@ public class AppIdAuthenticationOperatorIntegrationTests extends
|
||||
.userIdMechanism(new StaticUserId("static-userid-value")) //
|
||||
.build();
|
||||
|
||||
AppIdAuthentication authentication = new AppIdAuthentication(options,
|
||||
new RestTemplate());
|
||||
|
||||
AuthenticationStepsOperator supplier = new AuthenticationStepsOperator(
|
||||
authentication.getAuthenticationSteps(), webClient);
|
||||
AppIdAuthentication.createAuthenticationSteps(options), webClient);
|
||||
|
||||
StepVerifier.create(supplier.getVaultToken()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
@@ -59,11 +55,8 @@ public class AppIdAuthenticationOperatorIntegrationTests extends
|
||||
.userIdMechanism(new StaticUserId("wrong")) //
|
||||
.build();
|
||||
|
||||
AppIdAuthentication authentication = new AppIdAuthentication(options,
|
||||
new RestTemplate());
|
||||
|
||||
AuthenticationStepsOperator supplier = new AuthenticationStepsOperator(
|
||||
authentication.getAuthenticationSteps(), webClient);
|
||||
AppIdAuthentication.createAuthenticationSteps(options), webClient);
|
||||
|
||||
StepVerifier.create(supplier.getVaultToken()).expectError().verify();
|
||||
}
|
||||
|
||||
@@ -45,11 +45,8 @@ public class AppIdAuthenticationStepsIntegrationTests extends
|
||||
RestTemplate restTemplate = TestRestTemplateFactory.create(Settings
|
||||
.createSslConfiguration());
|
||||
|
||||
AppIdAuthentication authentication = new AppIdAuthentication(options,
|
||||
restTemplate);
|
||||
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authentication.getAuthenticationSteps(), restTemplate);
|
||||
AppIdAuthentication.createAuthenticationSteps(options), restTemplate);
|
||||
|
||||
VaultToken login = executor.login();
|
||||
|
||||
@@ -67,10 +64,8 @@ public class AppIdAuthenticationStepsIntegrationTests extends
|
||||
RestTemplate restTemplate = TestRestTemplateFactory.create(Settings
|
||||
.createSslConfiguration());
|
||||
|
||||
AuthenticationSteps authenticationChain = new AppIdAuthentication(options,
|
||||
restTemplate).getAuthenticationSteps();
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authenticationChain, restTemplate);
|
||||
AppIdAuthentication.createAuthenticationSteps(options), restTemplate);
|
||||
|
||||
executor.login();
|
||||
}
|
||||
|
||||
@@ -159,11 +159,10 @@ public class AppRoleAuthenticationIntegrationTests extends IntegrationTestSuppor
|
||||
|
||||
AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
|
||||
.roleId(roleId).secretId("this-is-a-wrong-secret-id").build();
|
||||
AppRoleAuthentication authentication = new AppRoleAuthentication(options,
|
||||
prepare().getRestTemplate());
|
||||
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authentication.getAuthenticationSteps(), prepare().getRestTemplate());
|
||||
AppRoleAuthentication.createAuthenticationSteps(options), prepare()
|
||||
.getRestTemplate());
|
||||
|
||||
assertThat(executor.login()).isNotNull();
|
||||
}
|
||||
@@ -180,11 +179,10 @@ public class AppRoleAuthenticationIntegrationTests extends IntegrationTestSuppor
|
||||
|
||||
AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
|
||||
.roleId(roleId).secretId(secretId).build();
|
||||
AppRoleAuthentication authentication = new AppRoleAuthentication(options,
|
||||
prepare().getRestTemplate());
|
||||
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authentication.getAuthenticationSteps(), prepare().getRestTemplate());
|
||||
AppRoleAuthentication.createAuthenticationSteps(options), prepare()
|
||||
.getRestTemplate());
|
||||
|
||||
assertThat(executor.login()).isNotNull();
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AppRoleAuthenticationUnitTests {
|
||||
private MockRestServiceServer mockRest;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
public void before() {
|
||||
|
||||
RestTemplate restTemplate = VaultClients.createRestTemplate();
|
||||
restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());
|
||||
@@ -57,7 +57,7 @@ public class AppRoleAuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginShouldObtainToken() throws Exception {
|
||||
public void loginShouldObtainToken() {
|
||||
|
||||
AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
|
||||
.roleId("hello") //
|
||||
@@ -81,7 +81,7 @@ public class AppRoleAuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginShouldObtainTokenWithoutSecretId() throws Exception {
|
||||
public void loginShouldObtainTokenWithoutSecretId() {
|
||||
|
||||
AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
|
||||
.roleId("hello") //
|
||||
@@ -110,7 +110,7 @@ public class AppRoleAuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test(expected = VaultException.class)
|
||||
public void loginShouldFail() throws Exception {
|
||||
public void loginShouldFail() {
|
||||
|
||||
AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
|
||||
.roleId("hello") //
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
private MockRestServiceServer mockRest;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
public void before() {
|
||||
|
||||
RestTemplate restTemplate = VaultClients.createRestTemplate();
|
||||
restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());
|
||||
@@ -60,7 +60,7 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldObtainIdentityDocument() throws Exception {
|
||||
public void shouldObtainIdentityDocument() {
|
||||
|
||||
mockRest.expect(
|
||||
requestTo("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7")) //
|
||||
@@ -74,7 +74,7 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldContainRole() throws Exception {
|
||||
public void shouldContainRole() {
|
||||
|
||||
AwsEc2AuthenticationOptions options = AwsEc2AuthenticationOptions.builder()
|
||||
.role("ami").build();
|
||||
@@ -94,7 +94,7 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogin() throws Exception {
|
||||
public void shouldLogin() {
|
||||
|
||||
Nonce nonce = Nonce.provided("foo".toCharArray());
|
||||
|
||||
@@ -130,12 +130,12 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticationChainShouldLogin() throws Exception {
|
||||
public void authenticationChainShouldLogin() {
|
||||
|
||||
Nonce nonce = Nonce.provided("foo".toCharArray());
|
||||
|
||||
AwsEc2AuthenticationOptions authenticationOptions = AwsEc2AuthenticationOptions
|
||||
.builder().nonce(nonce).build();
|
||||
AwsEc2AuthenticationOptions options = AwsEc2AuthenticationOptions.builder()
|
||||
.nonce(nonce).build();
|
||||
|
||||
mockRest.expect(
|
||||
requestTo("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7")) //
|
||||
@@ -153,11 +153,8 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
+ "\"auth\":{\"client_token\":\"my-token\", \"lease_duration\":20}"
|
||||
+ "}"));
|
||||
|
||||
AwsEc2Authentication authentication = new AwsEc2Authentication(
|
||||
authenticationOptions, restTemplate, restTemplate);
|
||||
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authentication.getAuthenticationSteps(), restTemplate);
|
||||
AwsEc2Authentication.createAuthenticationSteps(options), restTemplate);
|
||||
VaultToken login = executor.login();
|
||||
|
||||
assertThat(login).isInstanceOf(LoginToken.class);
|
||||
@@ -168,7 +165,7 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test(expected = VaultException.class)
|
||||
public void loginShouldFailWhileObtainingIdentityDocument() throws Exception {
|
||||
public void loginShouldFailWhileObtainingIdentityDocument() {
|
||||
|
||||
mockRest.expect(
|
||||
requestTo("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7")) //
|
||||
@@ -178,7 +175,7 @@ public class AwsEc2AuthenticationUnitTests {
|
||||
}
|
||||
|
||||
@Test(expected = VaultException.class)
|
||||
public void loginShouldFail() throws Exception {
|
||||
public void loginShouldFail() {
|
||||
|
||||
mockRest.expect(requestTo("/auth/aws-ec2/login")) //
|
||||
.andRespond(withServerError());
|
||||
|
||||
@@ -18,13 +18,7 @@ package org.springframework.vault.authentication;
|
||||
import org.junit.Test;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.vault.client.VaultClients;
|
||||
import org.springframework.vault.config.ClientHttpRequestFactoryFactory;
|
||||
import org.springframework.vault.support.ClientOptions;
|
||||
import org.springframework.vault.util.TestRestTemplateFactory;
|
||||
import org.springframework.vault.util.TestWebClientFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
@@ -42,16 +36,8 @@ public class ClientCertificateAuthenticationOperatorIntegrationTests extends
|
||||
WebClient webClient = TestWebClientFactory
|
||||
.create(prepareCertAuthenticationMethod());
|
||||
|
||||
ClientHttpRequestFactory clientHttpRequestFactory = ClientHttpRequestFactoryFactory
|
||||
.create(new ClientOptions(), prepareCertAuthenticationMethod());
|
||||
|
||||
RestTemplate restTemplate = VaultClients.createRestTemplate(
|
||||
TestRestTemplateFactory.TEST_VAULT_ENDPOINT, clientHttpRequestFactory);
|
||||
ClientCertificateAuthentication authentication = new ClientCertificateAuthentication(
|
||||
restTemplate);
|
||||
|
||||
AuthenticationStepsOperator operator = new AuthenticationStepsOperator(
|
||||
authentication.getAuthenticationSteps(), webClient);
|
||||
ClientCertificateAuthentication.createAuthenticationSteps(), webClient);
|
||||
|
||||
StepVerifier.create(operator.getVaultToken()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -46,11 +46,9 @@ public class ClientCertificateAuthenticationStepsIntegrationTests extends
|
||||
|
||||
RestTemplate restTemplate = VaultClients.createRestTemplate(
|
||||
TestRestTemplateFactory.TEST_VAULT_ENDPOINT, clientHttpRequestFactory);
|
||||
ClientCertificateAuthentication authentication = new ClientCertificateAuthentication(
|
||||
restTemplate);
|
||||
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authentication.getAuthenticationSteps(), restTemplate);
|
||||
ClientCertificateAuthentication.createAuthenticationSteps(), restTemplate);
|
||||
|
||||
VaultToken login = executor.login();
|
||||
|
||||
@@ -67,9 +65,8 @@ public class ClientCertificateAuthenticationStepsIntegrationTests extends
|
||||
RestTemplate restTemplate = VaultClients.createRestTemplate(
|
||||
TestRestTemplateFactory.TEST_VAULT_ENDPOINT, clientHttpRequestFactory);
|
||||
|
||||
AuthenticationSteps steps = new ClientCertificateAuthentication(restTemplate)
|
||||
.getAuthenticationSteps();
|
||||
|
||||
new AuthenticationStepsExecutor(steps, restTemplate).login();
|
||||
new AuthenticationStepsExecutor(
|
||||
ClientCertificateAuthentication.createAuthenticationSteps(), restTemplate)
|
||||
.login();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.vault.support.VaultToken;
|
||||
import org.springframework.vault.util.Settings;
|
||||
import org.springframework.vault.util.TestRestTemplateFactory;
|
||||
import org.springframework.vault.util.TestWebClientFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -49,14 +47,9 @@ public class CubbyholeAuthenticationOperatorIntegrationTests extends
|
||||
|
||||
CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions.builder()
|
||||
.initialToken(VaultToken.of(initialToken)).wrapped().build();
|
||||
RestTemplate restTemplate = TestRestTemplateFactory.create(Settings
|
||||
.createSslConfiguration());
|
||||
|
||||
CubbyholeAuthentication authentication = new CubbyholeAuthentication(options,
|
||||
restTemplate);
|
||||
|
||||
AuthenticationStepsOperator operator = new AuthenticationStepsOperator(
|
||||
authentication.getAuthenticationSteps(), webClient);
|
||||
CubbyholeAuthentication.createAuthenticationSteps(options), webClient);
|
||||
|
||||
StepVerifier.create(operator.getVaultToken()).consumeNextWith(actual -> {
|
||||
|
||||
|
||||
@@ -47,11 +47,8 @@ public class CubbyholeAuthenticationStepsIntegrationTests extends
|
||||
RestTemplate restTemplate = TestRestTemplateFactory.create(Settings
|
||||
.createSslConfiguration());
|
||||
|
||||
CubbyholeAuthentication authentication = new CubbyholeAuthentication(options,
|
||||
restTemplate);
|
||||
|
||||
AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
|
||||
authentication.getAuthenticationSteps(), restTemplate);
|
||||
CubbyholeAuthentication.createAuthenticationSteps(options), restTemplate);
|
||||
|
||||
VaultToken login = executor.login();
|
||||
assertThat(login.getToken()).doesNotContain(Settings.token().getToken());
|
||||
|
||||
Reference in New Issue
Block a user