Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/spring/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This section includes changes in `spring-cloud-azure-appconfiguration-config` mo
#### Bugs Fixed

- Fixed bug where `spring.cloud.azure.appconfiguration.enabled=false` was ignored in the new major version. [#47029](https://github.com/Azure/azure-sdk-for-java/pull/47029)
- Fixed bug where connection string validation occurred even when `spring.cloud.azure.appconfiguration.enabled` is `false`.

### Azure Spring Data Cosmos
This section includes changes in `azure-spring-data-cosmos` module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ public boolean isResolvable(ConfigDataLocationResolverContext context, ConfigDat
return false;
}

Binder binder = context.getBinder();

// Check if Azure App Configuration is enabled
Boolean enabled = binder.bind(AppConfigurationProperties.CONFIG_PREFIX + ".enabled", Boolean.class).orElse(true);
if (!enabled) {
return false;
}

// Check if the configuration properties for Azure App Configuration are present
return hasValidStoreConfiguration(context.getBinder());
return hasValidStoreConfiguration(binder);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class AzureAppConfigDataLocationResolverTest {
@Mock
BindResult<String> validResult;

@Mock
BindResult<Boolean> enabledTrueResult;

@Mock
BindResult<Boolean> enabledFalseResult;

private static final String PREFIX = "azureAppConfiguration:";
private static final String INVALID_PREFIX = "someOtherPrefix:";

Expand Down Expand Up @@ -80,6 +86,9 @@ void testIsResolvableWithCorrectPrefix() {
ConfigDataLocation location = ConfigDataLocation.of(PREFIX);

when(mockContext.getBinder()).thenReturn(mockBinder);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
.thenReturn(enabledTrueResult);
when(enabledTrueResult.orElse(true)).thenReturn(true);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].endpoint", String.class))
.thenReturn(validResult);
when(validResult.orElse("")).thenReturn("https://test.config.io");
Expand All @@ -95,6 +104,9 @@ void testIsResolvableWithValidConnectionStringConfiguration() {
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");

when(mockContext.getBinder()).thenReturn(mockBinder);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
.thenReturn(enabledTrueResult);
when(enabledTrueResult.orElse(true)).thenReturn(true);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].endpoint", String.class))
.thenReturn(emptyResult);
when(emptyResult.orElse("")).thenReturn("");
Expand All @@ -108,11 +120,28 @@ void testIsResolvableWithValidConnectionStringConfiguration() {
assertTrue(result, "Resolver should accept locations with valid connection-string configuration");
}

@Test
void testIsResolvableWhenAppConfigurationIsDisabled() {
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");

when(mockContext.getBinder()).thenReturn(mockBinder);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
.thenReturn(enabledFalseResult);
when(enabledFalseResult.orElse(true)).thenReturn(false);

boolean result = resolver.isResolvable(mockContext, location);

assertFalse(result, "Resolver should reject locations when App Configuration is disabled");
}

@Test
void testIsResolvableWithValidEndpointsConfiguration() {
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");

when(mockContext.getBinder()).thenReturn(mockBinder);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
.thenReturn(enabledTrueResult);
when(enabledTrueResult.orElse(true)).thenReturn(true);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].endpoint", String.class))
.thenReturn(emptyResult);
when(emptyResult.orElse("")).thenReturn("");
Expand All @@ -134,6 +163,9 @@ void testIsResolvableWithValidConnectionStringsConfiguration() {
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");

when(mockContext.getBinder()).thenReturn(mockBinder);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
.thenReturn(enabledTrueResult);
when(enabledTrueResult.orElse(true)).thenReturn(true);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].endpoint", String.class))
.thenReturn(emptyResult);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].connection-string", String.class))
Expand All @@ -156,6 +188,9 @@ void testIsResolvableWithNoValidConfiguration() {
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");

when(mockContext.getBinder()).thenReturn(mockBinder);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
.thenReturn(enabledTrueResult);
when(enabledTrueResult.orElse(true)).thenReturn(true);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].endpoint", String.class))
.thenReturn(emptyResult);
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].connection-string", String.class))
Expand Down
Loading