From ee91e5cfda51061903806e056baddff0a6141c11 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Fri, 13 Mar 2026 10:41:11 -0400 Subject: [PATCH] Fix EncryptionIntegrationTests for changes in Boot behavior Due to https://github.com/spring-projects/spring-boot/commit/646db448ae938161279783a2d5d0bcaf297e7389 in Spring Boo 4.0.3 and beyond the initial call to resolve may not have application-failsafe.properties loaded so EncryptionIntegrationTests.failsafeShouldHaveDelegate will fail when we assert TextEncryptorUtils.keysConfigured(keyProperties) is true. application-failsafe.properties will only be available on subsequent calls to resolve so we return if TextEncryptorUtils.keysConfigured(keyProperties) is false. We need to get TextEncryptor from the context before we return so FailSafeTextEncryptor is created and used in subsequent calls to resolve. --- .../test/TestConfigDataLocationResolver.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/test/TestConfigDataLocationResolver.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/test/TestConfigDataLocationResolver.java index e2226dc86..609ae9fdd 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/test/TestConfigDataLocationResolver.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/test/TestConfigDataLocationResolver.java @@ -63,11 +63,28 @@ public List resolve(ConfigDataLocationResolverContext co .bind("createfailsafedelegate", Bindable.of(Boolean.class)) .orElse(Boolean.FALSE); if (createFailsafeDelegate) { + KeyProperties keyProperties = context.getBinder() + .bindOrCreate(KeyProperties.PREFIX, Bindable.of(KeyProperties.class)); + // Due to + // https://github.com/spring-projects/spring-boot/commit/646db448ae938161279783a2d5d0bcaf297e7389 + // in Spring Boo 4.0.3 and beyond the initial call to resolve may not have + // application-failsafe.properties + // loaded so EncryptionIntegrationTests.failsafeShouldHaveDelegate will fail + // when we assert TextEncryptorUtils.keysConfigured(keyProperties) + // is true. application-failsafe.properties will only be available on + // subsequent calls to resolve so we return + // if TextEncryptorUtils.keysConfigured(keyProperties) is false. We need to + // get TextEncryptor from the context + // before we return so FailSafeTextEncryptor is created and used in subsequent + // calls to resolve. + if (!TextEncryptorUtils.keysConfigured(keyProperties)) { + assertThat(context.getBootstrapContext().isRegistered(TextEncryptor.class)).isTrue(); + context.getBootstrapContext().get(TextEncryptor.class); + return Collections.emptyList(); + } assertThat(context.getBootstrapContext().isRegistered(TextEncryptor.class)).isTrue(); TextEncryptor textEncryptor = context.getBootstrapContext().get(TextEncryptor.class); assertThat(textEncryptor).isInstanceOf(TextEncryptorUtils.FailsafeTextEncryptor.class); - KeyProperties keyProperties = context.getBinder() - .bindOrCreate(KeyProperties.PREFIX, Bindable.of(KeyProperties.class)); assertThat(TextEncryptorUtils.keysConfigured(keyProperties)).isTrue(); RsaProperties rsaProperties = context.getBinder() .bindOrCreate(RsaProperties.PREFIX, Bindable.of(RsaProperties.class));