Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
Add author and since tags.

Related ticket: gh-614
Original pull request: gh-615
  • Loading branch information
mp911de committed Jan 15, 2021
1 parent f233f30 commit 873e337
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -81,8 +83,11 @@ public String getVmName() {
return this.vmName;
}

/**
* @since 2.4
*/
public String getVmScaleSetName() {
return vmScaleSetName;
return this.vmScaleSetName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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() {
Expand All @@ -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"))
Expand Down

0 comments on commit 873e337

Please sign in to comment.