Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for test property source in ExcludeAutoConfigurationsEnvironmentPostProcessor #2102

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ class ExcludeAutoConfigurationsEnvironmentPostProcessor : EnvironmentPostProcess
)
}

private fun extractAllExcludes(propertySources: MutablePropertySources): String =
propertySources
private fun extractAllExcludes(propertySources: MutablePropertySources): String {
if (propertySources.any { it.name == INLINED_TEST_PROPERTIES }) {
val testExclude = propertySources.find { it.name == INLINED_TEST_PROPERTIES }?.getProperty(EXCLUDE)
if (testExclude is String && testExclude.isNotBlank()) {
return testExclude
}
}

return propertySources
.stream()
.filter { src -> !ConfigurationPropertySources.isAttachedConfigurationPropertySource(src) }
.map { src ->
Expand All @@ -71,6 +78,7 @@ class ExcludeAutoConfigurationsEnvironmentPostProcessor : EnvironmentPostProcess
}.orElse(emptyList())
}.flatMap { it.stream() }
.collect(Collectors.joining(","))
}

companion object {
private val DISABLE_AUTOCONFIG_PROPERTIES =
Expand All @@ -86,5 +94,6 @@ class ExcludeAutoConfigurationsEnvironmentPostProcessor : EnvironmentPostProcess
)

private const val EXCLUDE = "spring.autoconfigure.exclude"
private const val INLINED_TEST_PROPERTIES = "Inlined Test Properties"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@ class ExcludeAutoConfigurationsEnvironmentPostProcessorTest {
"org.springframework.boot.autoconfigure.graphql.security.GraphQlWebMvcSecurityAutoConfiguration",
)
}

@Test
fun `does not reintroduce overridden excludes in test properties`() {
val env = StandardEnvironment()
env.propertySources.addLast(MapPropertySource("application-props", mapOf(Pair("spring.autoconfigure.exclude", "someexclude"))))
env.propertySources.addLast(
MapPropertySource("Inlined Test Properties", mapOf(Pair("spring.autoconfigure.exclude", "someotherexclude"))),
)

ExcludeAutoConfigurationsEnvironmentPostProcessor().postProcessEnvironment(env, SpringApplication())
assertThat(env.getProperty("spring.autoconfigure.exclude"))
.contains(
"someotherexclude",
"org.springframework.boot.actuate.autoconfigure.observation.graphql.GraphQlObservationAutoConfiguration",
"org.springframework.boot.autoconfigure.graphql.security.GraphQlWebMvcSecurityAutoConfiguration",
)

assertThat(env.getProperty("spring.autoconfigure.exclude"))
.doesNotContain("someexclude")
}
}
Loading