aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/helper/WebHelperTest.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2023-04-05 14:35:55 -0700
committerGitHub <noreply@github.com>2023-04-05 14:35:55 -0700
commit44d188ece3edfb2e3ff10094465d5a1d1ab03f6a (patch)
treed70460f9284b4e8ff06b264172dc722bc696c849 /src/test/java/org/traccar/helper/WebHelperTest.java
parent17dff9e974ac863d8e37f7b95115218b55269cda (diff)
parent88a56f29fff1ab252a2c415f0d44a22192dd6b66 (diff)
downloadtrackermap-server-44d188ece3edfb2e3ff10094465d5a1d1ab03f6a.tar.gz
trackermap-server-44d188ece3edfb2e3ff10094465d5a1d1ab03f6a.tar.bz2
trackermap-server-44d188ece3edfb2e3ff10094465d5a1d1ab03f6a.zip
Merge pull request #5064 from dan-r/openid-discovery
Updates to OpenID Implementation
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..3a7329cb8
--- /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 javax.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));
+ }
+
+}