Skip to content

Commit

Permalink
add ut for service properties
Browse files Browse the repository at this point in the history
  • Loading branch information
yiliuTo committed Jul 10, 2021
1 parent 64d3a94 commit a946835
Show file tree
Hide file tree
Showing 52 changed files with 427 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,12 @@
<Bug pattern="NP_NULL_ON_SOME_PATH"/>
</Match>

<Match>
<Class name="com.azure.spring.identity.SpringCredentialBuilderBase"/>
<Field name="environment"/>
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/>
</Match>

<!-- The transient fields are not used if deserialization happens. -->
<Match>
<Class name="com.azure.identity.implementation.MsalAuthenticationAccount"/>
Expand Down
5 changes: 5 additions & 0 deletions sdk/spring/azure-spring-boot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<description>Azure Spring Boot Core Library</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<properties>
<jacoco.min.linecoverage>0.10</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.10</jacoco.min.branchcoverage>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class ApplicationId {
public static final String AZURE_SPRING_STORAGE_FILES = "az-sp-sf/";
public static final String AZURE_SPRING_STORAGE_QUEUE = "az-si-sq/";

public static final String VERSION = Optional.of(SpringPropertyPrefix.class)
//TODO: version should contains each starter library's version
public static final String VERSION = Optional.of(ApplicationId.class)
.map(Class::getPackage)
.map(Package::getImplementationVersion)
.orElse("unknown");
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.spring.core.env;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.azure.spring.core.util;

import com.azure.identity.AzureAuthorityHosts;

/**
* Util class for Azure urls
*/
Expand All @@ -21,4 +23,17 @@ public static String getServiceManagementBaseUrl(String cloudType) {
return cloudType.equals("Global") ? "https://management.azure.com/"
: "https://management.chinacloudapi.cn/";
}

public static String toAuthorityHost(String azureEnvironment) {
switch (azureEnvironment) {
case "AzureChina":
return AzureAuthorityHosts.AZURE_CHINA;
case "AzureGermany":
return AzureAuthorityHosts.AZURE_GERMANY;
case "AzureUSGovernment":
return AzureAuthorityHosts.AZURE_GOVERNMENT;
default:
return AzureAuthorityHosts.AZURE_PUBLIC_CLOUD;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.util.Optional;

import static com.azure.spring.core.Utils.toAuthorityHost;
import static com.azure.spring.core.util.AzureCloudUrls.toAuthorityHost;

/**
*
Expand Down Expand Up @@ -54,7 +54,7 @@ private TokenCredential populateTokenCredential(String prefix, boolean createDef
.build();
}

String certPath = getPropertyValue(prefix + "client-certificate-path", null);
String certPath = getPropertyValue(prefix + "client-certificate-path");

if (tenantId != null && clientId != null && certPath != null) {
return new ClientCertificateCredentialBuilder()
Expand All @@ -77,11 +77,11 @@ protected ManagedIdentityCredential defaultManagedIdentityCredential() {
}

protected String getPropertyValue(String propertyName) {
return getPropertyValue(propertyName, null);
return environment.getProperty(propertyName);
}

protected String getPropertyValue(String propertyName, String defaultValue) {
return environment.getProperty(propertyName, defaultValue);
return environment.getProperty(propertyName, defaultValue);
}

protected String getAuthorityHost(String prefix) {
Expand Down
18 changes: 0 additions & 18 deletions sdk/spring/azure-spring-boot-starter-keyvault-secrets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
# Release History

## 3.7.0-beta.1 (Unreleased)
### New Features
- Support unified properties as below when the associated `azure.keyvault.*` properties are not configured.([#22396](https://github.com/Azure/azure-sdk-for-java/issues/22396))
```
spring:
cloud:
azure:
client-id:
client-secret:
certificate-path:
certificate-password:
tenant-id:
authority-host:
environment:
```
### Breaking Changes
- Deprecate property of `azure.keyvault.client-key`, and provide `azure.keyvault.client-secret` instead.
- Property type of `spring.cloud.azure.environment` are changed from Enum to String. Supported values are "Azure", "AzureChina", "AzureGermany" and "AzureUSGovernment".
- Support alternative configuration of `azure.keyvault.authority-host` from `spring.cloud.azure.authority-host` or `spring.cloud.azure.environment`.

## 3.6.0 (2021-06-23)
### Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class CosmosActuatorIT {
public void testCosmosSpringBootActuatorHealth() {
try (AppRunner app = new AppRunner(DummyApp.class)) {
//set properties
app.property("azure.cosmos.uri", AZURE_COSMOS_ENDPOINT);
app.property("azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY);
app.property("azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME);
app.property("azure.cosmos.populateQueryMetrics", String.valueOf(true));
app.property("spring.cloud.azure.cosmos.uri", AZURE_COSMOS_ENDPOINT);
app.property("spring.cloud.azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY);
app.property("spring.cloud.azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME);
app.property("spring.cloud.azure.cosmos.populateQueryMetrics", String.valueOf(true));
app.property("management.endpoint.health.show-details", "always");
app.property("management.health.azure-cosmos.enabled", "true");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class CosmosIT {
public void testCosmosStarterIsolating() {
try (AppRunner app = new AppRunner(DummyApp.class)) {
//set properties
app.property("azure.cosmos.uri", AZURE_COSMOS_ENDPOINT);
app.property("azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY);
app.property("azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME);
app.property("azure.cosmos.populateQueryMetrics", String.valueOf(true));
app.property("spring.cloud.azure.cosmos.uri", AZURE_COSMOS_ENDPOINT);
app.property("spring.cloud.azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY);
app.property("spring.cloud.azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME);
app.property("spring.cloud.azure.cosmos.populateQueryMetrics", String.valueOf(true));

//start app
app.start();
Expand All @@ -46,10 +46,10 @@ public void testCosmosStarterIsolating() {
public void testCosmosOperation() {
try (AppRunner app = new AppRunner(DummyApp.class)) {
//set properties
app.property("azure.cosmos.uri", AZURE_COSMOS_ENDPOINT);
app.property("azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY);
app.property("azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME);
app.property("azure.cosmos.populateQueryMetrics", String.valueOf(true));
app.property("spring.cloud.azure.cosmos.uri", AZURE_COSMOS_ENDPOINT);
app.property("spring.cloud.azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY);
app.property("spring.cloud.azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME);
app.property("spring.cloud.azure.cosmos.populateQueryMetrics", String.valueOf(true));

//start app
app.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class KeyVaultActuatorIT {
public void testSpringBootActuatorHealth() {
LOGGER.info("testSpringBootActuatorHealth begin.");
try (AppRunner app = new AppRunner(DummyApp.class)) {
app.property("azure.keyvault.enabled", "true");
app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("azure.keyvault.client-id", SPRING_CLIENT_ID);
app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET);
app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID);
app.property("spring.cloud.azure.keyvault.enabled", "true");
app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID);
app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET);
app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID);
app.property("management.endpoint.health.show-details", "always");
app.property("management.endpoints.web.exposure.include", "*");
app.property("management.health.azure-key-vault.enabled", "true");
Expand All @@ -53,11 +53,11 @@ public void testSpringBootActuatorHealth() {
public void testSpringBootActuatorEnv() {
LOGGER.info("testSpringBootActuatorEnv begin.");
try (AppRunner app = new AppRunner(DummyApp.class)) {
app.property("azure.keyvault.enabled", "true");
app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("azure.keyvault.client-id", SPRING_CLIENT_ID);
app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET);
app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID);
app.property("spring.cloud.azure.keyvault.enabled", "true");
app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID);
app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET);
app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID);
app.property("management.endpoint.health.show-details", "always");
app.property("management.endpoints.web.exposure.include", "*");
app.property("management.health.azure-key-vault.enabled", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private static TokenCredential credentials() {
public void keyVaultAsPropertySource() {
LOGGER.info("keyVaultAsPropertySource begin.");
try (AppRunner app = new AppRunner(DummyApp.class)) {
app.property("azure.keyvault.enabled", "true");
app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("azure.keyvault.client-id", SPRING_CLIENT_ID);
app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET);
app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID);
app.property("spring.cloud.azure.keyvault.enabled", "true");
app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID);
app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET);
app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID);

LOGGER.info("app begin to start.");
final ConfigurableApplicationContext dummy = app.start();
Expand All @@ -98,12 +98,12 @@ public void keyVaultAsPropertySource() {
public void keyVaultAsPropertySourceWithSpecificKeys() {
LOGGER.info("keyVaultAsPropertySourceWithSpecificKeys begin.");
try (AppRunner app = new AppRunner(DummyApp.class)) {
app.property("azure.keyvault.enabled", "true");
app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("azure.keyvault.client-id", SPRING_CLIENT_ID);
app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET);
app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID);
app.property("azure.keyvault.secret-keys", KEY_VAULT_SECRET_NAME);
app.property("spring.cloud.azure.keyvault.enabled", "true");
app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI);
app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID);
app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET);
app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID);
app.property("spring.cloud.azure.keyvault.secret-keys", KEY_VAULT_SECRET_NAME);
LOGGER.info("====" + KEY_VAULT_SECRET_NAME);
app.start();
assertEquals(KEY_VAULT_SECRET_VALUE, app.getProperty(KEY_VAULT_SECRET_NAME));
Expand Down
Loading

0 comments on commit a946835

Please sign in to comment.