Skip to content

Commit 6e4a881

Browse files
Copilotrujche
andcommitted
Fix: Skip App Configuration validation when enabled is false
Co-authored-by: rujche <[email protected]>
1 parent 81a16a4 commit 6e4a881

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

sdk/spring/spring-cloud-azure-appconfiguration-config/src/main/java/com/azure/spring/cloud/appconfiguration/config/implementation/AzureAppConfigDataLocationResolver.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,16 @@ public boolean isResolvable(ConfigDataLocationResolverContext context, ConfigDat
5757
return false;
5858
}
5959

60+
Binder binder = context.getBinder();
61+
62+
// Check if Azure App Configuration is enabled
63+
Boolean enabled = binder.bind(AppConfigurationProperties.CONFIG_PREFIX + ".enabled", Boolean.class).orElse(true);
64+
if (!enabled) {
65+
return false;
66+
}
67+
6068
// Check if the configuration properties for Azure App Configuration are present
61-
return hasValidStoreConfiguration(context.getBinder());
69+
return hasValidStoreConfiguration(binder);
6270
}
6371

6472
/**

sdk/spring/spring-cloud-azure-appconfiguration-config/src/test/java/com/azure/spring/cloud/appconfiguration/config/implementation/AzureAppConfigDataLocationResolverTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class AzureAppConfigDataLocationResolverTest {
4747
@Mock
4848
BindResult<String> validResult;
4949

50+
@Mock
51+
BindResult<Boolean> enabledTrueResult;
52+
53+
@Mock
54+
BindResult<Boolean> enabledFalseResult;
55+
5056
private static final String PREFIX = "azureAppConfiguration:";
5157
private static final String INVALID_PREFIX = "someOtherPrefix:";
5258

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

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

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

123+
@Test
124+
void testIsResolvableWhenAppConfigurationIsDisabled() {
125+
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");
126+
127+
when(mockContext.getBinder()).thenReturn(mockBinder);
128+
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
129+
.thenReturn(enabledFalseResult);
130+
when(enabledFalseResult.orElse(true)).thenReturn(false);
131+
132+
boolean result = resolver.isResolvable(mockContext, location);
133+
134+
assertFalse(result, "Resolver should reject locations when App Configuration is disabled");
135+
}
136+
111137
@Test
112138
void testIsResolvableWithValidEndpointsConfiguration() {
113139
ConfigDataLocation location = ConfigDataLocation.of("azureAppConfiguration:");
114140

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

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

158190
when(mockContext.getBinder()).thenReturn(mockBinder);
191+
when(mockBinder.bind("spring.cloud.azure.appconfiguration.enabled", Boolean.class))
192+
.thenReturn(enabledTrueResult);
193+
when(enabledTrueResult.orElse(true)).thenReturn(true);
159194
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].endpoint", String.class))
160195
.thenReturn(emptyResult);
161196
when(mockBinder.bind("spring.cloud.azure.appconfiguration.stores[0].connection-string", String.class))

0 commit comments

Comments
 (0)