From c539537ab90f56fdb38066e7177184b189106015 Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Mon, 9 Nov 2020 14:18:04 -0500 Subject: [PATCH] Add basic tests to assert no whitespace in spring.factories fiels --- .../autoconfigure/SpringFactoriesTest.groovy | 24 +++++++++++++++++++ .../web/WebSpringFactoriesTest.groovy | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/SpringFactoriesTest.groovy create mode 100644 support/spring-boot/spring-boot-web-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/web/WebSpringFactoriesTest.groovy diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/SpringFactoriesTest.groovy b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/SpringFactoriesTest.groovy new file mode 100644 index 0000000000..43dba2730d --- /dev/null +++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/SpringFactoriesTest.groovy @@ -0,0 +1,24 @@ +package org.apache.shiro.spring.boot.autoconfigure + +import org.junit.Test + +import static org.hamcrest.MatcherAssert.assertThat +import static org.hamcrest.Matchers.matchesPattern +import static org.hamcrest.Matchers.not + +class SpringFactoriesTest { + + @Test + void springFactoriesConfigContainsNoWhitespace() { + Properties props = new Properties() + props.load(new FileReader("src/main/resources/META-INF/spring.factories")) + assertNoWhitespaceInEntries(props) + } + + static private assertNoWhitespaceInEntries(Properties props) { + props.each{ key, val -> + assertThat "Property [${key}] contains whitespace", + props.get("org.springframework.boot.autoconfigure.EnableAutoConfiguration"), not(matchesPattern(".*\\s.*")) + } + } +} diff --git a/support/spring-boot/spring-boot-web-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/web/WebSpringFactoriesTest.groovy b/support/spring-boot/spring-boot-web-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/web/WebSpringFactoriesTest.groovy new file mode 100644 index 0000000000..b0892a13ea --- /dev/null +++ b/support/spring-boot/spring-boot-web-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/web/WebSpringFactoriesTest.groovy @@ -0,0 +1,24 @@ +package org.apache.shiro.spring.boot.autoconfigure.web + +import org.junit.Test + +import static org.hamcrest.MatcherAssert.assertThat +import static org.hamcrest.Matchers.matchesPattern +import static org.hamcrest.Matchers.not + +class WebSpringFactoriesTest { + + @Test + void springFactoriesConfigContainsNoWhitespace() { + Properties props = new Properties() + props.load(new FileReader("src/main/resources/META-INF/spring.factories")) + assertNoWhitespaceInEntries(props) + } + + static private assertNoWhitespaceInEntries(Properties props) { + props.each{ key, val -> + assertThat "Property [${key}] contains whitespace", + props.get("org.springframework.boot.autoconfigure.EnableAutoConfiguration"), not(matchesPattern(".*\\s.*")) + } + } +}