aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authordeveloperKurt <mustafakurt.business@gmail.com>2020-01-01 13:42:05 +0300
committerdeveloperKurt <mustafakurt.business@gmail.com>2020-01-01 13:42:05 +0300
commitfcad646a7c912463c53de946b2586e4a49a6e1ff (patch)
tree665e5f82a531d19ed2f762bb451157326f3a0e9c /src/test
parent1ca6c8561f1aa21d5f73030bcd0ab3e9c578a9f1 (diff)
downloadtrackermap-server-fcad646a7c912463c53de946b2586e4a49a6e1ff.tar.gz
trackermap-server-fcad646a7c912463c53de946b2586e4a49a6e1ff.tar.bz2
trackermap-server-fcad646a7c912463c53de946b2586e4a49a6e1ff.zip
As requested in issue #4393, added logging IP address functionality when login attempts fail.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/traccar/helper/IpRetrieverTest.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/java/org/traccar/helper/IpRetrieverTest.java b/src/test/java/org/traccar/helper/IpRetrieverTest.java
new file mode 100644
index 000000000..628b5dd63
--- /dev/null
+++ b/src/test/java/org/traccar/helper/IpRetrieverTest.java
@@ -0,0 +1,38 @@
+package org.traccar.helper;
+
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import static org.junit.Assert.assertEquals;
+
+public class IpRetrieverTest {
+
+ private static final String NORMAL_IP_ADDRESS = "231.23.45.65";
+ private static final String GATEWAY_IP_ADDRESS = "147.120.1.5";
+ private static final String IP_ADDRESS_BEHIND_REVERSE_PROXY = "231.23.45.65, 10.20.10.33, 10.20.20.34";
+
+ private MockHttpServletRequest mockHttpServletRequest;
+
+ @Before
+ public void init(){
+ mockHttpServletRequest = new MockHttpServletRequest();
+ }
+
+ @Test
+ public void testIpBehindReverseProxy(){
+ mockHttpServletRequest.setRemoteAddr(GATEWAY_IP_ADDRESS);
+ mockHttpServletRequest.addHeader("X-FORWARDED-FOR",IP_ADDRESS_BEHIND_REVERSE_PROXY);
+
+ assertEquals(NORMAL_IP_ADDRESS, IpRetriever.retrieveIP(mockHttpServletRequest));
+ }
+
+ @Test
+ public void testNormalIp(){
+ mockHttpServletRequest.setRemoteAddr(NORMAL_IP_ADDRESS);
+ assertEquals(NORMAL_IP_ADDRESS, IpRetriever.retrieveIP(mockHttpServletRequest));
+
+ }
+
+}