summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorFlorian Zschocke <f.zschocke+git@gmail.com>2020-11-07 19:56:51 +0100
committerFlorian Zschocke <f.zschocke+git@gmail.com>2020-11-09 23:19:53 +0100
commit23943971846437c8bc24504d3bd4b681edea5433 (patch)
tree9229a1ceba224cb769c0b09b850557e7840769d4 /src/test
parentdd56cd85715d0b8f6d9dfaca468f9589868cbded (diff)
downloadgitblit-23943971846437c8bc24504d3bd4b681edea5433.tar.gz
gitblit-23943971846437c8bc24504d3bd4b681edea5433.zip
raw: Fix exceptions when no path info is given to raw servlet
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/gitblit/servlet/RawServletTest.java112
1 files changed, 111 insertions, 1 deletions
diff --git a/src/test/java/com/gitblit/servlet/RawServletTest.java b/src/test/java/com/gitblit/servlet/RawServletTest.java
index 9f2b9e71..1deacf7e 100644
--- a/src/test/java/com/gitblit/servlet/RawServletTest.java
+++ b/src/test/java/com/gitblit/servlet/RawServletTest.java
@@ -3,6 +3,7 @@ package com.gitblit.servlet;
import com.gitblit.Constants;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
+import com.gitblit.manager.IRepositoryManager;
import com.gitblit.tests.mock.MockGitblitContext;
import com.gitblit.tests.mock.MockRuntimeManager;
import org.junit.Before;
@@ -10,20 +11,28 @@ import org.junit.BeforeClass;
import org.junit.Test;
+import javax.servlet.http.HttpServletRequest;
+
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class RawServletTest
{
private final static String FSC = "!";
+ private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager();
private static IStoredSettings settings;
+ private IRepositoryManager repositoryMngr;
+
+ private RawServlet rawServlet;
+
@BeforeClass
public static void init()
{
MockGitblitContext gitblitContext = new MockGitblitContext();
- MockRuntimeManager mockRuntimeManager = new MockRuntimeManager();
gitblitContext.addManager(mockRuntimeManager);
settings = mockRuntimeManager.getSettings();
}
@@ -32,6 +41,9 @@ public class RawServletTest
public void setUp()
{
settings.overrideSetting(Keys.web.forwardSlashCharacter, "/");
+
+ repositoryMngr = mock(IRepositoryManager.class);
+ rawServlet = new RawServlet(mockRuntimeManager, repositoryMngr);
}
@@ -672,4 +684,102 @@ public class RawServletTest
public void getPath()
{
}
+
+ @Test
+ public void getBranch_Repo()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn("/test.git/");
+
+ String branch = rawServlet.getBranch("test.git", request);
+
+ assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
+ }
+
+ @Test
+ public void getBranch_RepoNoTrailingSlash()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn("/test.git");
+
+ String branch = rawServlet.getBranch("test.git", request);
+
+ assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
+ }
+
+ @Test
+ public void getBranch_PiNull()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn(null);
+
+ String branch = rawServlet.getBranch("test.git", request);
+
+ assertEquals("Branch was supposed to be empty as path info is null.", "", branch);
+ }
+
+
+ @Test
+ public void getBranch_PiEmpty()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn("");
+
+ String branch = rawServlet.getBranch("test.git", request);
+
+ assertEquals("Branch was supposed to be empty as no path info exists.", "", branch);
+ }
+
+
+
+
+
+
+
+
+ @Test
+ public void getPath_Repo()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn("/test.git/");
+
+ String path = rawServlet.getPath("test.git", "", request);
+
+ assertEquals("Path was supposed to be empty as no path was given.", "", path);
+ }
+
+ @Test
+ public void getPath_RepoNoTrailingSlash()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn("/test.git");
+
+ String path = rawServlet.getPath("test.git", "", request);
+
+ assertEquals("Path was supposed to be empty as no path was given.", "", path);
+ }
+
+ @Test
+ public void getPath_PiNull()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn(null);
+
+ String path = rawServlet.getPath("test.git", "", request);
+
+ assertEquals("Path was supposed to be empty as path info is null.", "", path);
+ }
+
+
+ @Test
+ public void getPath_PiEmpty()
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getPathInfo()).thenReturn("");
+
+ String path = rawServlet.getPath("test.git", "", request);
+
+ assertEquals("Path was supposed to be empty as no path info exists.", "", path);
+ }
+
}