Consider configured meta attributes in VaultTokenRequestBuilder.

Closes gh-80.
This commit is contained in:
Mark Paluch
2017-04-25 15:37:43 +02:00
parent 7dcaeaa100
commit 78a3d07b48
2 changed files with 61 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
/**
* Value object to bind Vault HTTP Token API requests.
*
*
* @author Mark Paluch
*/
public class VaultTokenRequest {
@@ -418,14 +418,14 @@ public class VaultTokenRequest {
this.policies));
}
Map<String, String> meta = null;
Map<String, String> meta;
switch (this.meta.size()) {
case 0:
meta = Collections.emptyMap();
break;
default:
meta = Collections
.unmodifiableMap(new LinkedHashMap<String, String>(meta));
.unmodifiableMap(new LinkedHashMap<String, String>(this.meta));
}
return new VaultTokenRequest(id, policies, meta, noParent, noDefaultPolicy,

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2017 the original author or authors.
*
* 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 org.springframework.vault.support;
import java.util.Collections;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link VaultTokenRequest}.
*
* @author Mark Paluch
*/
public class VaultTokenRequestUnitTests {
@Test
public void shouldBuildEmptyRequest() {
VaultTokenRequest tokenRequest = VaultTokenRequest.builder().build();
assertThat(tokenRequest.getMeta()).isEmpty();
assertThat(tokenRequest.getPolicies()).isEmpty();
}
@Test
public void shouldBuildRequestWithMeta() {
VaultTokenRequest tokenRequest = VaultTokenRequest.builder()
.meta(Collections.singletonMap("key", "value")).build();
assertThat(tokenRequest.getMeta()).containsEntry("key", "value");
}
@Test
public void shouldBuildRequestWithPolicies() {
VaultTokenRequest tokenRequest = VaultTokenRequest.builder().withPolicy("foo")
.build();
assertThat(tokenRequest.getPolicies()).containsOnly("foo");
}
}