From 91832bfc8ead2769e336b55f9bfd030bdbb02972 Mon Sep 17 00:00:00 2001 From: Josh Cummings <3627351+jzheaux@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:21:07 -0700 Subject: [PATCH] Add EnableWebSecurity + EnableWebSocketSecurity Test Issue gh-16011 --- ...etMessageBrokerSecurityConfigurationTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config/src/test/java/org/springframework/security/config/annotation/web/socket/WebSocketMessageBrokerSecurityConfigurationTests.java b/config/src/test/java/org/springframework/security/config/annotation/web/socket/WebSocketMessageBrokerSecurityConfigurationTests.java index 099207d0b5e..cf2d0358069 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/web/socket/WebSocketMessageBrokerSecurityConfigurationTests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/web/socket/WebSocketMessageBrokerSecurityConfigurationTests.java @@ -68,6 +68,7 @@ import org.springframework.security.authorization.AuthorizationDecision; import org.springframework.security.authorization.AuthorizationManager; import org.springframework.security.config.annotation.SecurityContextChangedListenerConfig; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry; import org.springframework.security.config.observation.SecurityObservationSettings; import org.springframework.security.core.Authentication; @@ -438,6 +439,12 @@ public void sendMessageWhenExcludeAuthorizationObservationsThenUnobserved() { verifyNoInteractions(observationHandler); } + // gh-16011 + @Test + public void enableWebSocketSecurityWhenWebSocketSecurityUsedThenAutowires() { + loadConfig(WithWebSecurity.class); + } + private void assertHandshake(HttpServletRequest request) { TestHandshakeHandler handshakeHandler = this.context.getBean(TestHandshakeHandler.class); assertThatCsrfToken(handshakeHandler.attributes.get(CsrfToken.class.getName())).isEqualTo(this.token); @@ -489,6 +496,7 @@ private T clientInboundChannel() { private void loadConfig(Class... configs) { this.context = new AnnotationConfigWebApplicationContext(); + this.context.setAllowBeanDefinitionOverriding(false); this.context.register(configs); this.context.setServletConfig(new MockServletConfig()); this.context.refresh(); @@ -939,6 +947,13 @@ TestHandshakeHandler testHandshakeHandler() { } + @Configuration(proxyBeanMethods = false) + @EnableWebSecurity + @Import(WebSocketSecurityConfig.class) + static class WithWebSecurity { + + } + @Configuration static class SyncExecutorConfig {