Skip to content

Fix azure.scopes defaulting to Azure Global when cloud-type=azure_china/azure_us_government#48683

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-azure-scopes-for-china-again
Draft

Fix azure.scopes defaulting to Azure Global when cloud-type=azure_china/azure_us_government#48683
Copilot wants to merge 3 commits intomainfrom
copilot/fix-azure-scopes-for-china-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

  • Fix AzureJdbcPasswordlessProperties.getScopes() to return this.scopes (null when not explicitly set)
  • Add getEffectiveScopes() that returns cloud-type-aware default when scopes is not explicitly set
  • Override toPasswordlessProperties() in AzureJdbcPasswordlessProperties to use getEffectiveScopes()
  • Fix AzurePasswordlessPropertiesUtils.copyAzureCommonPropertiesIgnoreNull to only copy scopes if non-null
  • Fix shouldGetCloudTypeFromAzureUsGov test to expect the correct US Government scope
  • Add shouldGetCorrectScopeFromAzureChina test for Azure China scope fix
  • Add testJdbcPropertiesGetCorrectScopeFromGlobalCloudType and testJdbcPropertiesExplicitScopesOverridesDefault tests
  • Update CHANGELOG.md with correct issue number [BUG] azure.scopes is wrong when set spring.cloud.azure.profile.cloud-type=azure_china #47096

Copilot AI changed the title [WIP] Fix azure.scopes configuration for Azure China profile Fix azure.scopes defaulting to Azure Global when cloud-type=azure_china/azure_us_government Apr 3, 2026
Copilot AI requested a review from rujche April 3, 2026 07:41

### Bugs Fixed

- Fixed `azure.scopes` using wrong default value for Azure China and Azure US Government when `spring.cloud.azure.profile.cloud-type` is set to `azure_china` or `azure_us_government`. The scopes are now correctly derived from the merged cloud type. ([#44945](https://github.com/Azure/azure-sdk-for-java/issues/44945))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The correct issue id should be 47096

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f56b6ba.

Copilot AI requested a review from rujche April 3, 2026 08:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes passwordless JDBC azure.scopes resolution so that when spring.cloud.azure.profile.cloud-type is set (e.g., azure_china / azure_us_government) and JDBC-specific scopes aren’t explicitly configured, the effective default scope is derived from the merged cloud type (instead of incorrectly defaulting to Azure Global).

Changes:

  • Update JDBC passwordless properties so getScopes() returns the raw (possibly null) configured value, and add getEffectiveScopes() for cloud-aware defaults; ensure JDBC URL generation uses the effective scopes.
  • Adjust copyAzureCommonPropertiesIgnoreNull to avoid overwriting target scopes when the source scopes are null.
  • Update/add tests for China/US Gov scope behavior and update changelogs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/util/AzurePasswordlessPropertiesUtils.java Adds null-guard around copying scopes during passwordless property merge.
sdk/spring/spring-cloud-azure-core/CHANGELOG.md Notes the change in scopes merge behavior.
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/passwordless/properties/AzureJdbcPasswordlessProperties.java Separates raw vs effective scopes and ensures toPasswordlessProperties() uses cloud-aware default scopes.
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/passwordless/MergeAzureCommonPropertiesTest.java Adds merge tests validating JDBC effective scopes behavior.
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jdbc/JdbcPropertiesBeanPostProcessorTest.java Fixes US Gov expected scope and adds Azure China scenario coverage.
sdk/spring/spring-cloud-azure-autoconfigure/CHANGELOG.md Adds a bug-fix entry for the cloud-type-specific default scopes behavior.

Comment on lines +54 to +55
if (source.getScopes() != null) {
target.setScopes(source.getScopes());
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyAzureCommonPropertiesIgnoreNull calls source.getScopes() twice (once in the null-check and again when setting). If getScopes() is computed (as it is for some implementations), this can be redundant and can even produce inconsistent results if the computation is not purely deterministic. Consider caching the value in a local variable and reusing it for the null-check and assignment.

Suggested change
if (source.getScopes() != null) {
target.setScopes(source.getScopes());
String[] scopes = source.getScopes();
if (scopes != null) {
target.setScopes(scopes);

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +12
- Fixed `azure.scopes` using wrong default value for Azure China and Azure US Government when `spring.cloud.azure.profile.cloud-type` is set to `azure_china` or `azure_us_government`. The scopes are now correctly derived from the merged cloud type. ([#47096](https://github.com/Azure/azure-sdk-for-java/issues/47096))

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue link in this new changelog entry points to #44945, but the PR description indicates this change is intended to fix issue #47096. Please update the changelog link/issue number so it references the correct issue.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +140
assertEquals("https://ossrdbms-aad.database.chinacloudapi.cn/.default", result.getEffectiveScopes());
// toPasswordlessProperties should include the correct cloud-type-aware scope
assertEquals("https://ossrdbms-aad.database.chinacloudapi.cn/.default",
result.toPasswordlessProperties().getProperty("azure.scopes"));
assertEquals(AzureProfileOptionsProvider.CloudType.AZURE_CHINA, result.getProfile().getCloudType());
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses the hard-coded property key string "azure.scopes". To reduce brittleness if the underlying key changes, prefer using the canonical constant (e.g., AuthProperty.SCOPES.getPropertyKey()) when reading from the Properties produced by toPasswordlessProperties().

Copilot uses AI. Check for mistakes.
}

@Test
void testJdbcPropertiesGetCorrectScopeFromGlobalCloudType() {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name testJdbcPropertiesGetCorrectScopeFromGlobalCloudType is misleading: it sets the cloud type to AZURE_CHINA and asserts the China-specific scope. Renaming the test to reflect the scenario (e.g., China/global properties cloud type) would make the intent clearer.

Suggested change
void testJdbcPropertiesGetCorrectScopeFromGlobalCloudType() {
void testJdbcPropertiesGetCorrectScopeFromChinaCloudTypeInGlobalProperties() {

Copilot uses AI. Check for mistakes.
Comment on lines +54 to 57
if (source.getScopes() != null) {
target.setScopes(source.getScopes());
}
target.setPasswordlessEnabled(source.isPasswordlessEnabled());
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new null-guard relies on source.getScopes() returning null when scopes were not explicitly configured. Some PasswordlessProperties implementations compute a non-null default in getScopes() when the backing field is null (e.g., AzureRedisPasswordlessProperties#getScopes), so merging can still overwrite the target’s cloud-type-aware default with an Azure-global scope when the per-service profile.cloudType isn’t set. Consider using a way to distinguish “explicitly set scopes” vs “computed default” (or aligning other implementations with the raw/effective scopes split used for JDBC).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] azure.scopes is wrong when set spring.cloud.azure.profile.cloud-type=azure_china

3 participants