Skip to content

Commit acfb158

Browse files
authored
Fix EncryptionIntegrationTests for changes in Boot behavior (#1665)
Due to spring-projects/spring-boot@646db44 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.
1 parent 75eab1d commit acfb158

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

spring-cloud-context/src/test/java/org/springframework/cloud/context/test/TestConfigDataLocationResolver.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,28 @@ public List<TestConfigDataResource> resolve(ConfigDataLocationResolverContext co
6363
.bind("createfailsafedelegate", Bindable.of(Boolean.class))
6464
.orElse(Boolean.FALSE);
6565
if (createFailsafeDelegate) {
66+
KeyProperties keyProperties = context.getBinder()
67+
.bindOrCreate(KeyProperties.PREFIX, Bindable.of(KeyProperties.class));
68+
// Due to
69+
// https://github.com/spring-projects/spring-boot/commit/646db448ae938161279783a2d5d0bcaf297e7389
70+
// in Spring Boo 4.0.3 and beyond the initial call to resolve may not have
71+
// application-failsafe.properties
72+
// loaded so EncryptionIntegrationTests.failsafeShouldHaveDelegate will fail
73+
// when we assert TextEncryptorUtils.keysConfigured(keyProperties)
74+
// is true. application-failsafe.properties will only be available on
75+
// subsequent calls to resolve so we return
76+
// if TextEncryptorUtils.keysConfigured(keyProperties) is false. We need to
77+
// get TextEncryptor from the context
78+
// before we return so FailSafeTextEncryptor is created and used in subsequent
79+
// calls to resolve.
80+
if (!TextEncryptorUtils.keysConfigured(keyProperties)) {
81+
assertThat(context.getBootstrapContext().isRegistered(TextEncryptor.class)).isTrue();
82+
context.getBootstrapContext().get(TextEncryptor.class);
83+
return Collections.emptyList();
84+
}
6685
assertThat(context.getBootstrapContext().isRegistered(TextEncryptor.class)).isTrue();
6786
TextEncryptor textEncryptor = context.getBootstrapContext().get(TextEncryptor.class);
6887
assertThat(textEncryptor).isInstanceOf(TextEncryptorUtils.FailsafeTextEncryptor.class);
69-
KeyProperties keyProperties = context.getBinder()
70-
.bindOrCreate(KeyProperties.PREFIX, Bindable.of(KeyProperties.class));
7188
assertThat(TextEncryptorUtils.keysConfigured(keyProperties)).isTrue();
7289
RsaProperties rsaProperties = context.getBinder()
7390
.bindOrCreate(RsaProperties.PREFIX, Bindable.of(RsaProperties.class));

0 commit comments

Comments
 (0)