|
|
@@ -18,20 +18,26 @@ import static org.mockito.Mockito.when; |
|
|
|
public class GlobalResourceHandlerTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void globalResourceHandlerShouldWorkWithEncodedFilename() throws IOException { |
|
|
|
public void globalResourceHandlerShouldWorkWithEncodedFilename() |
|
|
|
throws IOException { |
|
|
|
assertEncodedFilenameIsHandled("simple.txt", "simple.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with spaces.txt", "with+spaces.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with # hash.txt", "with+%23+hash.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with ; semicolon.txt", "with+%3B+semicolon.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with , comma.txt", "with+%2C+comma.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with ; semicolon.txt", |
|
|
|
"with+%3B+semicolon.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with , comma.txt", |
|
|
|
"with+%2C+comma.txt"); |
|
|
|
|
|
|
|
// ResourceReference.encodeFileName does not encode slashes and backslashes |
|
|
|
// ResourceReference.encodeFileName does not encode slashes and |
|
|
|
// backslashes |
|
|
|
// See comment inside2 method for more details |
|
|
|
assertEncodedFilenameIsHandled("with \\ backslash.txt", "with+\\+backslash.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with \\ backslash.txt", |
|
|
|
"with+\\+backslash.txt"); |
|
|
|
assertEncodedFilenameIsHandled("with / slash.txt", "with+/+slash.txt"); |
|
|
|
} |
|
|
|
|
|
|
|
private void assertEncodedFilenameIsHandled(String filename, String expectedFilename) throws IOException { |
|
|
|
private void assertEncodedFilenameIsHandled(String filename, |
|
|
|
String expectedFilename) throws IOException { |
|
|
|
DownloadStream stream = mock(DownloadStream.class); |
|
|
|
ConnectorResource resource = mock(ConnectorResource.class); |
|
|
|
when(resource.getFilename()).thenReturn(filename); |
|
|
@@ -58,11 +64,13 @@ public class GlobalResourceHandlerTest { |
|
|
|
VaadinResponse response = mock(VaadinResponse.class); |
|
|
|
|
|
|
|
// getPathInfo return path decoded but without decoding plus as spaces |
|
|
|
when(request.getPathInfo()).thenReturn("APP/global/0/legacy/0/"+ filename.replace(" ", "+")); |
|
|
|
when(request.getPathInfo()).thenReturn( |
|
|
|
"APP/global/0/legacy/0/" + filename.replace(" ", "+")); |
|
|
|
when(session.getUIById(anyInt())).thenReturn(ui); |
|
|
|
|
|
|
|
// Verify that decoded path info is correctly handled |
|
|
|
assertTrue("Request not handled", handler.handleRequest(session, request, response)); |
|
|
|
assertTrue("Request not handled", |
|
|
|
handler.handleRequest(session, request, response)); |
|
|
|
verify(stream).writeResponse(request, response); |
|
|
|
} |
|
|
|
} |