aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/helper/WebHelperTest.java
diff options
context:
space:
mode:
authorYuriy Piskarev <yuriy.piskarev@gmail.com>2023-08-24 14:16:17 +0300
committerGitHub <noreply@github.com>2023-08-24 14:16:17 +0300
commitae406c7b49a72de24d81fd74386d9638342c90ee (patch)
tree6fbcf557375b98e926c78af9c757e62c79d72a1b /src/test/java/org/traccar/helper/WebHelperTest.java
parent56ff656c908b19feb2fa3dcffa48cc3bcdfe9b3b (diff)
parent9aeedc90da24848ff97227d6f281eb4d1e1506ef (diff)
downloadtrackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.gz
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.bz2
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.zip
Merge branch 'traccar:master' into master
Diffstat (limited to 'src/test/java/org/traccar/helper/WebHelperTest.java')
-rw-r--r--src/test/java/org/traccar/helper/WebHelperTest.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/java/org/traccar/helper/WebHelperTest.java b/src/test/java/org/traccar/helper/WebHelperTest.java
new file mode 100644
index 000000000..da18be11e
--- /dev/null
+++ b/src/test/java/org/traccar/helper/WebHelperTest.java
@@ -0,0 +1,39 @@
+package org.traccar.helper;
+
+import org.junit.jupiter.api.Test;
+
+import jakarta.servlet.http.HttpServletRequest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class WebHelperTest {
+
+ @Test
+ public void testRetrieveRemoteAddressProxyMultiple() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("147.120.1.5");
+ when(request.getHeader("X-FORWARDED-FOR")).thenReturn("231.23.45.65, 10.20.10.33, 10.20.20.34");
+
+ assertEquals("231.23.45.65", WebHelper.retrieveRemoteAddress(request));
+ }
+
+ @Test
+ public void testRetrieveRemoteAddressProxySingle() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("147.120.1.5");
+ when(request.getHeader("X-FORWARDED-FOR")).thenReturn("231.23.45.65");
+
+ assertEquals("231.23.45.65", WebHelper.retrieveRemoteAddress(request));
+ }
+
+ @Test
+ public void testRetrieveRemoteAddressNoProxy() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("231.23.45.65");
+
+ assertEquals("231.23.45.65", WebHelper.retrieveRemoteAddress(request));
+ }
+
+}