mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 17:22:13 +00:00
Fix tests using root cause for exception messages
Closes gh-11372
This commit is contained in:
parent
d98dab5917
commit
c7df39a3e6
@ -77,7 +77,7 @@ public class EmbeddedLdapServerContextSourceFactoryBeanITests {
|
|||||||
public void contextSourceFactoryBeanWhenManagerDnAndNoPasswordThenException() {
|
public void contextSourceFactoryBeanWhenManagerDnAndNoPasswordThenException() {
|
||||||
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
||||||
.isThrownBy(() -> this.spring.register(CustomManagerDnNoPasswordConfig.class).autowire())
|
.isThrownBy(() -> this.spring.register(CustomManagerDnNoPasswordConfig.class).autowire())
|
||||||
.withRootCauseInstanceOf(IllegalStateException.class)
|
.havingRootCause().isInstanceOf(IllegalStateException.class)
|
||||||
.withMessageContaining("managerPassword is required if managerDn is supplied");
|
.withMessageContaining("managerPassword is required if managerDn is supplied");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public class SecurityNamespaceHandlerTests {
|
|||||||
expectClassUtilsForNameThrowsNoClassDefFoundError(className);
|
expectClassUtilsForNameThrowsNoClassDefFoundError(className);
|
||||||
assertThatExceptionOfType(BeanDefinitionParsingException.class)
|
assertThatExceptionOfType(BeanDefinitionParsingException.class)
|
||||||
.isThrownBy(() -> new InMemoryXmlApplicationContext(XML_AUTHENTICATION_MANAGER + XML_HTTP_BLOCK))
|
.isThrownBy(() -> new InMemoryXmlApplicationContext(XML_AUTHENTICATION_MANAGER + XML_HTTP_BLOCK))
|
||||||
.withMessageContaining("NoClassDefFoundError: " + className);
|
.havingRootCause().isInstanceOf(NoClassDefFoundError.class).withMessage(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -115,7 +115,7 @@ public class SecurityNamespaceHandlerTests {
|
|||||||
expectClassUtilsForNameThrowsClassNotFoundException(className);
|
expectClassUtilsForNameThrowsClassNotFoundException(className);
|
||||||
assertThatExceptionOfType(BeanDefinitionParsingException.class)
|
assertThatExceptionOfType(BeanDefinitionParsingException.class)
|
||||||
.isThrownBy(() -> new InMemoryXmlApplicationContext(XML_AUTHENTICATION_MANAGER + XML_HTTP_BLOCK))
|
.isThrownBy(() -> new InMemoryXmlApplicationContext(XML_AUTHENTICATION_MANAGER + XML_HTTP_BLOCK))
|
||||||
.withMessageContaining("ClassNotFoundException: " + className);
|
.havingRootCause().isInstanceOf(ClassNotFoundException.class).withMessage(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -152,7 +152,7 @@ public class WebSecurityConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void loadConfigWhenWebSecurityConfigurersHaveSameOrderThenThrowBeanCreationException() {
|
public void loadConfigWhenWebSecurityConfigurersHaveSameOrderThenThrowBeanCreationException() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> this.spring.register(DuplicateOrderConfig.class).autowire())
|
.isThrownBy(() -> this.spring.register(DuplicateOrderConfig.class).autowire()).havingRootCause()
|
||||||
.withMessageContaining("@Order on WebSecurityConfigurers must be unique")
|
.withMessageContaining("@Order on WebSecurityConfigurers must be unique")
|
||||||
.withMessageContaining(DuplicateOrderConfig.WebConfigurer1.class.getName())
|
.withMessageContaining(DuplicateOrderConfig.WebConfigurer1.class.getName())
|
||||||
.withMessageContaining(DuplicateOrderConfig.WebConfigurer2.class.getName());
|
.withMessageContaining(DuplicateOrderConfig.WebConfigurer2.class.getName());
|
||||||
|
@ -56,8 +56,14 @@ public class AccessDeniedConfigTests {
|
|||||||
@Test
|
@Test
|
||||||
public void configureWhenAccessDeniedHandlerIsMissingLeadingSlashThenException() {
|
public void configureWhenAccessDeniedHandlerIsMissingLeadingSlashThenException() {
|
||||||
SpringTestContext context = this.spring.configLocations(this.xml("NoLeadingSlash"));
|
SpringTestContext context = this.spring.configLocations(this.xml("NoLeadingSlash"));
|
||||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> context.autowire())
|
/*
|
||||||
.withMessageContaining("errorPage must begin with '/'");
|
* NOTE: Original error message "errorPage must begin with '/'" no longer shows up
|
||||||
|
* in stack trace as of Spring Framework 6.x.
|
||||||
|
*
|
||||||
|
* See https://github.com/spring-projects/spring-framework/issues/25162.
|
||||||
|
*/
|
||||||
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> context.autowire()).havingRootCause()
|
||||||
|
.withMessageContaining("Property 'errorPage' threw exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -61,7 +61,7 @@ public class HttpCorsConfigTests {
|
|||||||
@Test
|
@Test
|
||||||
public void autowireWhenMissingMvcThenGivesInformativeError() {
|
public void autowireWhenMissingMvcThenGivesInformativeError() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> this.spring.configLocations(this.xml("RequiresMvc")).autowire())
|
.isThrownBy(() -> this.spring.configLocations(this.xml("RequiresMvc")).autowire()).havingRootCause()
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext");
|
"Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext");
|
||||||
}
|
}
|
||||||
|
@ -386,10 +386,16 @@ public class HttpHeadersConfigTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configureWhenXssProtectionDisabledAndBlockSetThenAutowireFails() {
|
public void configureWhenXssProtectionDisabledAndBlockSetThenAutowireFails() {
|
||||||
|
/*
|
||||||
|
* NOTE: Original error message "Cannot set block to true with enabled false" no
|
||||||
|
* longer shows up in stack trace as of Spring Framework 6.x.
|
||||||
|
*
|
||||||
|
* See https://github.com/spring-projects/spring-framework/issues/25162.
|
||||||
|
*/
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> this.spring
|
.isThrownBy(() -> this.spring
|
||||||
.configLocations(this.xml("DefaultsDisabledWithXssProtectionDisabledAndBlockSet")).autowire())
|
.configLocations(this.xml("DefaultsDisabledWithXssProtectionDisabledAndBlockSet")).autowire())
|
||||||
.withMessageContaining("Cannot set block to true with enabled false");
|
.havingRootCause().withMessageContaining("Property 'block' threw exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -445,14 +451,14 @@ public class HttpHeadersConfigTests {
|
|||||||
public void configureWhenUsingHpkpWithoutPinsThenAutowireFails() {
|
public void configureWhenUsingHpkpWithoutPinsThenAutowireFails() {
|
||||||
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
|
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
|
||||||
.isThrownBy(() -> this.spring.configLocations(this.xml("DefaultsDisabledWithEmptyHpkp")).autowire())
|
.isThrownBy(() -> this.spring.configLocations(this.xml("DefaultsDisabledWithEmptyHpkp")).autowire())
|
||||||
.withMessageContaining("The content of element 'hpkp' is not complete");
|
.havingRootCause().withMessageContaining("The content of element 'hpkp' is not complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configureWhenUsingHpkpWithEmptyPinsThenAutowireFails() {
|
public void configureWhenUsingHpkpWithEmptyPinsThenAutowireFails() {
|
||||||
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
|
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
|
||||||
.isThrownBy(() -> this.spring.configLocations(this.xml("DefaultsDisabledWithEmptyPins")).autowire())
|
.isThrownBy(() -> this.spring.configLocations(this.xml("DefaultsDisabledWithEmptyPins")).autowire())
|
||||||
.withMessageContaining("The content of element 'pins' is not complete");
|
.havingRootCause().withMessageContaining("The content of element 'pins' is not complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -43,7 +43,7 @@ public class LdapServerBeanDefinitionParserTests {
|
|||||||
public void apacheDirectoryServerIsStartedByDefault() {
|
public void apacheDirectoryServerIsStartedByDefault() {
|
||||||
assertThatExceptionOfType(BeanDefinitionStoreException.class)
|
assertThatExceptionOfType(BeanDefinitionStoreException.class)
|
||||||
.isThrownBy(() -> this.context = new ClassPathXmlApplicationContext("applicationContext-security.xml"))
|
.isThrownBy(() -> this.context = new ClassPathXmlApplicationContext("applicationContext-security.xml"))
|
||||||
.withMessageContaining("Embedded LDAP server is not provided");
|
.havingRootCause().withMessageContaining("Embedded LDAP server is not provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ public class DefaultAuthorizationCodeTokenResponseClientTests {
|
|||||||
.getTokenResponse(authorizationCodeGrantRequest(this.clientRegistration.build())))
|
.getTokenResponse(authorizationCodeGrantRequest(this.clientRegistration.build())))
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -274,7 +274,7 @@ public class DefaultAuthorizationCodeTokenResponseClientTests {
|
|||||||
.getTokenResponse(authorizationCodeGrantRequest(this.clientRegistration.build())))
|
.getTokenResponse(authorizationCodeGrantRequest(this.clientRegistration.build())))
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -269,7 +269,7 @@ public class DefaultClientCredentialsTokenResponseClientTests {
|
|||||||
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(clientCredentialsGrantRequest))
|
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(clientCredentialsGrantRequest))
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -282,7 +282,7 @@ public class DefaultClientCredentialsTokenResponseClientTests {
|
|||||||
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(clientCredentialsGrantRequest))
|
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(clientCredentialsGrantRequest))
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -182,7 +182,7 @@ public class DefaultJwtBearerTokenResponseClientTests {
|
|||||||
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(jwtBearerGrantRequest))
|
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(jwtBearerGrantRequest))
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -245,7 +245,7 @@ public class DefaultPasswordTokenResponseClientTests {
|
|||||||
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(passwordGrantRequest))
|
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(passwordGrantRequest))
|
||||||
.withMessageContaining(
|
.withMessageContaining(
|
||||||
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
"[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -246,7 +246,7 @@ public class DefaultRefreshTokenTokenResponseClientTests {
|
|||||||
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(refreshTokenGrantRequest))
|
.isThrownBy(() -> this.tokenResponseClient.getTokenResponse(refreshTokenGrantRequest))
|
||||||
.withMessageContaining("[invalid_token_response] An error occurred while attempting to "
|
.withMessageContaining("[invalid_token_response] An error occurred while attempting to "
|
||||||
+ "retrieve the OAuth 2.0 Access Token Response")
|
+ "retrieve the OAuth 2.0 Access Token Response")
|
||||||
.withMessageContaining("tokenType cannot be null");
|
.havingRootCause().withMessageContaining("tokenType cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user