Skip to content

Commit

Permalink
Add EnableWebSecurity + EnableWebSocketSecurity Test
Browse files Browse the repository at this point in the history
Issue gh-16011
  • Loading branch information
jzheaux committed Nov 20, 2024
1 parent 30c9860 commit 91832bf
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -489,6 +496,7 @@ private <T extends MessageChannel> 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();
Expand Down Expand Up @@ -939,6 +947,13 @@ TestHandshakeHandler testHandshakeHandler() {

}

@Configuration(proxyBeanMethods = false)
@EnableWebSecurity
@Import(WebSocketSecurityConfig.class)
static class WithWebSecurity {

}

@Configuration
static class SyncExecutorConfig {

Expand Down

0 comments on commit 91832bf

Please sign in to comment.