This is an automated email from the ASF dual-hosted git repository.
snoopdave pushed a commit to branch session-mgmt
in repository https://gitbox.apache.org/repos/asf/roller.git
The following commit(s) were added to refs/heads/session-mgmt by this push:
new 5e5835b51 Test fixes.
5e5835b51 is described below
commit 5e5835b51e874151fae85392b44e617e5d99dfa6
Author: David M. Johnson <[email protected]>
AuthorDate: Mon Jan 20 10:10:21 2025 -0500
Test fixes.
---
.../ui/core/filters/LoadSaltFilterTest.java | 35 +++++++++++-----------
.../ui/core/filters/ValidateSaltFilterTest.java | 14 +++++++--
2 files changed, 29 insertions(+), 20 deletions(-)
diff --git
a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
index 6501e72b3..10079a82b 100644
---
a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
+++
b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
@@ -11,6 +11,8 @@ import org.mockito.MockedStatic;
import org.mockito.MockitoAnnotations;
import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -36,40 +38,39 @@ public class LoadSaltFilterTest {
private SaltCache saltCache;
@BeforeEach
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- filter = new LoadSaltFilter();
+ public void setUp() throws ServletException {
+ MockitoAnnotations.openMocks(this);
+
+ try (MockedStatic<UIBeanFactory> mockedFactory =
mockStatic(UIBeanFactory.class)) {
+ mockedFactory.when(() ->
UIBeanFactory.getBean(RollerSession.class))
+ .thenReturn(rollerSession);
+
+ filter = new LoadSaltFilter();
+ filter.init(mock(FilterConfig.class));
+ }
}
@Test
public void testDoFilterGeneratesSalt() throws Exception {
- try (MockedStatic<UIBeanFactory> mockedUIBeanFactory =
mockStatic(UIBeanFactory.class);
- MockedStatic<SaltCache> mockedSaltCache =
mockStatic(SaltCache.class)) {
-
- mockedUIBeanFactory.when(() ->
UIBeanFactory.getBean(RollerSession.class)).thenReturn(rollerSession);
+ try (MockedStatic<SaltCache> mockedSaltCache =
mockStatic(SaltCache.class)) {
mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache);
- when(rollerSession.getAuthenticatedUser()).thenReturn(new
TestUser("userId"));
-
filter.doFilter(request, response, chain);
-
verify(request).setAttribute(eq("salt"), anyString());
- verify(saltCache).put(anyString(), eq("userId"));
verify(chain).doFilter(request, response);
}
}
+
@Test
public void testDoFilterWithNullRollerSession() throws Exception {
- try (MockedStatic<UIBeanFactory> mockedUIBeanFactory =
mockStatic(UIBeanFactory.class);
- MockedStatic<SaltCache> mockedSaltCache =
mockStatic(SaltCache.class)) {
-
- mockedUIBeanFactory.when(() ->
UIBeanFactory.getBean(RollerSession.class)).thenReturn(null);
- mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache);
+ try (MockedStatic<UIBeanFactory> mockedUIBeanFactory =
mockStatic(UIBeanFactory.class)) {
+ mockedUIBeanFactory.when(() ->
UIBeanFactory.getBean(RollerSession.class))
+ .thenReturn(null);
+ filter.init(mock(FilterConfig.class));
filter.doFilter(request, response, chain);
verify(request, never()).setAttribute(eq("salt"), anyString());
- verify(saltCache, never()).put(anyString(), anyString());
verify(chain).doFilter(request, response);
}
}
diff --git
a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/ValidateSaltFilterTest.java
b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/ValidateSaltFilterTest.java
index f1218f725..d8c04871b 100644
---
a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/ValidateSaltFilterTest.java
+++
b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/ValidateSaltFilterTest.java
@@ -116,8 +116,11 @@ public class ValidateSaltFilterTest {
@Test
public void testDoFilterWithPostMethodAndNullRollerSession() throws
Exception {
- try (MockedStatic<SaltCache> mockedSaltCache =
mockStatic(SaltCache.class)) {
+ try (MockedStatic<SaltCache> mockedSaltCache =
mockStatic(SaltCache.class);
+ MockedStatic<UIBeanFactory> mockedUIBeanFactory =
mockStatic(UIBeanFactory.class)) {
+
mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache);
+ mockedUIBeanFactory.when(() ->
UIBeanFactory.getBean(RollerSession.class)).thenReturn(null);
when(request.getMethod()).thenReturn("POST");
when(request.getParameter("salt")).thenReturn("validSalt");
@@ -125,17 +128,22 @@ public class ValidateSaltFilterTest {
StringBuffer requestURL = new
StringBuffer("https://example.com/app/ignoredurl");
when(request.getRequestURL()).thenReturn(requestURL);
+ filter.init(mock(FilterConfig.class));
filter.doFilter(request, response, chain);
- verify(saltCache, never()).remove("validSalt");
+ verify(chain).doFilter(request, response);
+ verify(saltCache, never()).remove(anyString());
}
}
@Test
public void testDoFilterWithIgnoredURL() throws Exception {
- try (MockedStatic<WebloggerConfig> mockedWebloggerConfig =
mockStatic(WebloggerConfig.class)) {
+ try (MockedStatic<WebloggerConfig> mockedWebloggerConfig =
mockStatic(WebloggerConfig.class);
+ MockedStatic<UIBeanFactory> mockedUIBeanFactory =
mockStatic(UIBeanFactory.class)) {
+
mockedWebloggerConfig.when(() ->
WebloggerConfig.getProperty("salt.ignored.urls"))
.thenReturn("https://example.com/app/ignoredurl?param1=value1&m2=value2");
+ mockedUIBeanFactory.when(() ->
UIBeanFactory.getBean(RollerSession.class)).thenReturn(rollerSession);
when(request.getMethod()).thenReturn("POST");
StringBuffer requestURL = new
StringBuffer("https://example.com/app/ignoredurl");