diff --git a/spring-vault-core/src/main/java/org/springframework/vault/authentication/AzureVmEnvironment.java b/spring-vault-core/src/main/java/org/springframework/vault/authentication/AzureVmEnvironment.java index ee83c74cc..5ecc12e2f 100644 --- a/spring-vault-core/src/main/java/org/springframework/vault/authentication/AzureVmEnvironment.java +++ b/spring-vault-core/src/main/java/org/springframework/vault/authentication/AzureVmEnvironment.java @@ -22,6 +22,7 @@ * resource group name and the VM name. * * @author Mark Paluch + * @author Willi Schönborn * @since 2.1 * @see AzureMsiAuthentication * @see AzureMsiAuthenticationOptions @@ -55,13 +56,14 @@ public AzureVmEnvironment(String subscriptionId, String resourceGroupName, Strin * @param resourceGroupName must not be {@literal null}. * @param vmName must not be {@literal null}. * @param vmScaleSetName must not be {@literal null}. + * @since 2.4 */ public AzureVmEnvironment(String subscriptionId, String resourceGroupName, String vmName, String vmScaleSetName) { Assert.notNull(subscriptionId, "SubscriptionId must not be null"); Assert.notNull(resourceGroupName, "Resource group name must not be null"); Assert.notNull(vmName, "VM name must not be null"); - Assert.notNull(vmScaleSetName, "VMSS name must not be null"); + Assert.notNull(vmScaleSetName, "VM Scale Set name must not be null"); this.subscriptionId = subscriptionId; this.resourceGroupName = resourceGroupName; @@ -81,8 +83,11 @@ public String getVmName() { return this.vmName; } + /** + * @since 2.4 + */ public String getVmScaleSetName() { - return vmScaleSetName; + return this.vmScaleSetName; } } diff --git a/spring-vault-core/src/test/java/org/springframework/vault/authentication/AzureMsiAuthenticationUnitTests.java b/spring-vault-core/src/test/java/org/springframework/vault/authentication/AzureMsiAuthenticationUnitTests.java index cf2cf9248..2b57edd3f 100644 --- a/spring-vault-core/src/test/java/org/springframework/vault/authentication/AzureMsiAuthenticationUnitTests.java +++ b/spring-vault-core/src/test/java/org/springframework/vault/authentication/AzureMsiAuthenticationUnitTests.java @@ -26,17 +26,15 @@ import org.springframework.vault.support.VaultToken; import org.springframework.web.client.RestTemplate; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.header; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +import static org.assertj.core.api.Assertions.*; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; +import static org.springframework.test.web.client.response.MockRestResponseCreators.*; /** * Unit tests for {@link AzureMsiAuthentication}. * * @author Mark Paluch + * @author Willi Schönborn */ class AzureMsiAuthenticationUnitTests { @@ -141,32 +139,25 @@ void loginFromScaleSetShouldObtainToken() { private void expectVmMetadataRequest() { - this.mockRest.expect(requestTo(AzureMsiAuthenticationOptions.DEFAULT_INSTANCE_METADATA_SERVICE_URI)) + this.mockRest + .expect(requestTo(AzureMsiAuthenticationOptions.DEFAULT_INSTANCE_METADATA_SERVICE_URI)) .andExpect(method(HttpMethod.GET)).andExpect(header("Metadata", "true")) .andRespond(withSuccess().contentType(MediaType.APPLICATION_JSON) - .body("{\n" - + " \"compute\": {\n" - + " \"name\": \"vault-client\",\n" - + " \"vmScaleSetName\": \"\",\n" - + " \"resourceGroupName\": \"vault\",\n" - + " \"subscriptionId\": \"foobar-subscription\"\n" + - " }\n" + - "}")); + .body("{\n" + " \"compute\": {\n" + " \"name\": \"vault-client\",\n" + + " \"vmScaleSetName\": \"\",\n" + " \"resourceGroupName\": \"vault\",\n" + + " \"subscriptionId\": \"foobar-subscription\"\n" + " }\n" + "}")); } private void expectVmssMetadataRequest() { - this.mockRest.expect(requestTo(AzureMsiAuthenticationOptions.DEFAULT_INSTANCE_METADATA_SERVICE_URI)) + this.mockRest + .expect(requestTo(AzureMsiAuthenticationOptions.DEFAULT_INSTANCE_METADATA_SERVICE_URI)) .andExpect(method(HttpMethod.GET)).andExpect(header("Metadata", "true")) .andRespond(withSuccess().contentType(MediaType.APPLICATION_JSON) - .body("{\n" - + " \"compute\": {\n" - + " \"name\": \"vault-client-scale-set_0\",\n" + .body("{\n" + " \"compute\": {\n" + " \"name\": \"vault-client-scale-set_0\",\n" + " \"vmScaleSetName\": \"vault-client-scale-set\",\n" + " \"resourceGroupName\": \"vault\",\n" - + " \"subscriptionId\": \"foobar-subscription\"\n" + - " }\n" + - "}")); + + " \"subscriptionId\": \"foobar-subscription\"\n" + " }\n" + "}")); } private void expectIdentityTokenRequest() { @@ -179,8 +170,10 @@ private void expectIdentityTokenRequest() { private void expectVmLoginRequest() { - this.mockRest.expect(requestTo("/auth/azure/login")).andExpect(method(HttpMethod.POST)) - .andExpect(jsonPath("$.role").value("dev-role")).andExpect(jsonPath("$.jwt").value("my-token")) + this.mockRest.expect(requestTo("/auth/azure/login")) + .andExpect(method(HttpMethod.POST)) + .andExpect(jsonPath("$.role").value("dev-role")) + .andExpect(jsonPath("$.jwt").value("my-token")) .andExpect(jsonPath("$.subscription_id").value("foobar-subscription")) .andExpect(jsonPath("$.resource_group_name").value("vault")) .andExpect(jsonPath("$.vm_name").value("vault-client"))