@ -25,7 +25,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet ;
import java.util.concurrent.ConcurrentSkipListSet ;
import org.junit.Test ;
import org.junit.Test ;
import org.mockito.Mockito ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpStatus ;
import org.springframework.http.HttpStatus ;
@ -34,6 +33,7 @@ import org.springframework.web.socket.WebSocketHandler;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException ;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException ;
import static org.mockito.Mockito.mock ;
/ * *
/ * *
* Test fixture for { @link OriginHandshakeInterceptor } .
* Test fixture for { @link OriginHandshakeInterceptor } .
@ -42,16 +42,17 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* /
* /
public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
private final Map < String , Object > attributes = new HashMap < > ( ) ;
private final WebSocketHandler wsHandler = mock ( WebSocketHandler . class ) ;
@Test
@Test
public void invalidInput ( ) {
public void invalidInput ( ) {
assertThatIllegalArgumentException ( ) . isThrownBy ( ( ) - >
assertThatIllegalArgumentException ( ) . isThrownBy ( ( ) - > new OriginHandshakeInterceptor ( null ) ) ;
new OriginHandshakeInterceptor ( null ) ) ;
}
}
@Test
@Test
public void originValueMatch ( ) throws Exception {
public void originValueMatch ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain1.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain1.com" ) ;
List < String > allowed = Collections . singletonList ( "https://mydomain1.com" ) ;
List < String > allowed = Collections . singletonList ( "https://mydomain1.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
@ -61,8 +62,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void originValueNoMatch ( ) throws Exception {
public void originValueNoMatch ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain1.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain1.com" ) ;
List < String > allowed = Collections . singletonList ( "https://mydomain2.com" ) ;
List < String > allowed = Collections . singletonList ( "https://mydomain2.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
@ -72,8 +71,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void originListMatch ( ) throws Exception {
public void originListMatch ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain2.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain2.com" ) ;
List < String > allowed = Arrays . asList ( "https://mydomain1.com" , "https://mydomain2.com" , "http://mydomain3.com" ) ;
List < String > allowed = Arrays . asList ( "https://mydomain1.com" , "https://mydomain2.com" , "http://mydomain3.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
@ -83,8 +80,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void originListNoMatch ( ) throws Exception {
public void originListNoMatch ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://www.mydomain4.com/" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://www.mydomain4.com/" ) ;
List < String > allowed = Arrays . asList ( "https://mydomain1.com" , "https://mydomain2.com" , "http://mydomain3.com" ) ;
List < String > allowed = Arrays . asList ( "https://mydomain1.com" , "https://mydomain2.com" , "http://mydomain3.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( allowed ) ;
@ -94,8 +89,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void originNoMatchWithNullHostileCollection ( ) throws Exception {
public void originNoMatchWithNullHostileCollection ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://www.mydomain4.com/" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://www.mydomain4.com/" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( ) ;
Set < String > allowedOrigins = new ConcurrentSkipListSet < > ( ) ;
Set < String > allowedOrigins = new ConcurrentSkipListSet < > ( ) ;
@ -107,8 +100,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void originMatchAll ( ) throws Exception {
public void originMatchAll ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain1.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "https://mydomain1.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( ) ;
interceptor . setAllowedOrigins ( Collections . singletonList ( "*" ) ) ;
interceptor . setAllowedOrigins ( Collections . singletonList ( "*" ) ) ;
@ -118,8 +109,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void sameOriginMatchWithEmptyAllowedOrigins ( ) throws Exception {
public void sameOriginMatchWithEmptyAllowedOrigins ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://mydomain2.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://mydomain2.com" ) ;
this . servletRequest . setServerName ( "mydomain2.com" ) ;
this . servletRequest . setServerName ( "mydomain2.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( Collections . emptyList ( ) ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( Collections . emptyList ( ) ) ;
@ -129,8 +118,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void sameOriginMatchWithAllowedOrigins ( ) throws Exception {
public void sameOriginMatchWithAllowedOrigins ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://mydomain2.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://mydomain2.com" ) ;
this . servletRequest . setServerName ( "mydomain2.com" ) ;
this . servletRequest . setServerName ( "mydomain2.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( Arrays . asList ( "http://mydomain1.com" ) ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( Arrays . asList ( "http://mydomain1.com" ) ) ;
@ -140,8 +127,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
@Test
@Test
public void sameOriginNoMatch ( ) throws Exception {
public void sameOriginNoMatch ( ) throws Exception {
Map < String , Object > attributes = new HashMap < > ( ) ;
WebSocketHandler wsHandler = Mockito . mock ( WebSocketHandler . class ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://mydomain3.com" ) ;
this . servletRequest . addHeader ( HttpHeaders . ORIGIN , "http://mydomain3.com" ) ;
this . servletRequest . setServerName ( "mydomain2.com" ) ;
this . servletRequest . setServerName ( "mydomain2.com" ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( Collections . emptyList ( ) ) ;
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor ( Collections . emptyList ( ) ) ;