Move common TestPrincipal to spring-core test fixtures
See gh-23550
This commit is contained in:
parent
726b1bb1d0
commit
94f8ef08e2
|
@ -60,18 +60,20 @@ public class TestSourcesPlugin implements Plugin<Project> {
|
|||
* <p>This is used to assist with the migration to Gradle test fixtures.
|
||||
*/
|
||||
private static final List<String> excludedProjects = Arrays.asList(
|
||||
// "integration-tests",
|
||||
"integration-tests",
|
||||
"kotlin-coroutines",
|
||||
// "spring-aop",
|
||||
"spring-beans",
|
||||
"spring-context",
|
||||
"spring-context-indexer",
|
||||
"spring-context-support",
|
||||
"spring-core"
|
||||
// "spring-expression",
|
||||
// "spring-instrument",
|
||||
// "spring-jcl",
|
||||
// "spring-jdbc",
|
||||
// "spring-jms",
|
||||
// "spring-messaging",
|
||||
"spring-core",
|
||||
"spring-expression",
|
||||
"spring-instrument",
|
||||
"spring-jcl",
|
||||
"spring-jdbc",
|
||||
"spring-jms",
|
||||
"spring-messaging"
|
||||
// "spring-orm",
|
||||
// "spring-oxm",
|
||||
// "spring-test",
|
||||
|
|
|
@ -98,6 +98,7 @@ import org.springframework.core.testfixture.Assume;
|
|||
import org.springframework.core.testfixture.EnabledForTestGroups;
|
||||
import org.springframework.core.testfixture.TestGroup;
|
||||
import org.springframework.core.testfixture.io.SerializationTestUtils;
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
@ -3252,38 +3253,6 @@ class DefaultListableBeanFactoryTests {
|
|||
}
|
||||
|
||||
|
||||
private static class TestPrincipal implements Principal {
|
||||
|
||||
private String name;
|
||||
|
||||
public TestPrincipal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof TestPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
TestPrincipal p = (TestPrincipal) obj;
|
||||
return this.name.equals(p.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestSecuredBean {
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
|||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
@ -252,37 +253,6 @@ public class CallbacksSecurityTests {
|
|||
});
|
||||
}
|
||||
|
||||
private static class TestPrincipal implements Principal {
|
||||
|
||||
private String name;
|
||||
|
||||
public TestPrincipal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof TestPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
TestPrincipal p = (TestPrincipal) obj;
|
||||
return this.name.equals(p.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public CallbacksSecurityTests() {
|
||||
// setup security
|
||||
if (System.getSecurityManager() == null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.messaging.simp;
|
||||
package org.springframework.core.testfixture.security;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
|
@ -25,7 +25,7 @@ import java.security.Principal;
|
|||
*/
|
||||
public class TestPrincipal implements Principal {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
public TestPrincipal(String name) {
|
||||
this.name = name;
|
|
@ -22,6 +22,8 @@ import java.util.function.Consumer;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
|
@ -29,13 +29,13 @@ import org.mockito.Captor;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.simp.TestPrincipal;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@ import org.junit.jupiter.api.BeforeEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.StubMessageChannel;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.simp.TestPrincipal;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.messaging.tcp.ReconnectStrategy;
|
||||
|
|
|
@ -21,10 +21,10 @@ import java.security.Principal;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.simp.TestPrincipal;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ import org.junit.jupiter.api.Test;
|
|||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.StubMessageChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.simp.TestPrincipal;
|
||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
|
|
@ -79,6 +79,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
|||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.testfixture.io.SerializationTestUtils;
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
||||
|
@ -2643,7 +2644,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
|||
|
||||
@ModelAttribute
|
||||
public Principal getPrincipal() {
|
||||
return new TestPrincipal();
|
||||
return new TestPrincipal("test");
|
||||
}
|
||||
|
||||
@RequestMapping("/myPath")
|
||||
|
@ -2661,14 +2662,6 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
|||
}
|
||||
}
|
||||
|
||||
static class TestPrincipal implements Principal {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
|
||||
static class OtherPrincipal implements Principal {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.web.socket.handler.TestPrincipal;
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
|
|
@ -24,8 +24,8 @@ import javax.websocket.Session;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.socket.handler.TestPrincipal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
/**
|
||||
* An implementation of {@link Principal} for testing.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class TestPrincipal implements Principal {
|
||||
|
||||
private String name;
|
||||
|
||||
public TestPrincipal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof TestPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
TestPrincipal p = (TestPrincipal) obj;
|
||||
return this.name.equals(p.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.web.socket.messaging;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -24,6 +23,7 @@ import java.util.Set;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
|
@ -191,20 +191,4 @@ public class DefaultSimpUserRegistryTests {
|
|||
return MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
|
||||
}
|
||||
|
||||
|
||||
private static class TestPrincipal implements Principal {
|
||||
|
||||
private String name;
|
||||
|
||||
public TestPrincipal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.mockito.Mockito;
|
|||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.PayloadApplicationEvent;
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
|
@ -41,7 +42,6 @@ import org.springframework.messaging.simp.SimpAttributes;
|
|||
import org.springframework.messaging.simp.SimpAttributesContextHolder;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.simp.TestPrincipal;
|
||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompEncoder;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
|
|
|
@ -27,11 +27,11 @@ import org.mockito.Mock;
|
|||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.core.testfixture.security.TestPrincipal;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.handler.TestPrincipal;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.support.OriginHandshakeInterceptor;
|
||||
import org.springframework.web.socket.sockjs.transport.SockJsSessionFactory;
|
||||
|
|
Loading…
Reference in New Issue