DevModeHandlerTest.java (vaadin-flow-4.0.5) | : | DevModeHandlerTest.java (vaadin-flow-4.0.6) | ||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | * License for the specific language governing permissions and limitations under | |||
* the License. | * the License. | |||
*/ | */ | |||
package com.vaadin.flow.server; | package com.vaadin.flow.server; | |||
import static com.vaadin.flow.server.DevModeHandler.WEBPACK_SERVER; | import static com.vaadin.flow.server.DevModeHandler.WEBPACK_SERVER; | |||
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_WE BPACK_TIMEOUT; | import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_WE BPACK_TIMEOUT; | |||
import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.WEBPACK_TEST_OU T_FILE; | import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.WEBPACK_TEST_OU T_FILE; | |||
import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.createStubWebpa ckServer; | import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.createStubWebpa ckServer; | |||
import static java.net.HttpURLConnection.HTTP_FORBIDDEN; | ||||
import static java.net.HttpURLConnection.HTTP_NOT_FOUND; | import static java.net.HttpURLConnection.HTTP_NOT_FOUND; | |||
import static java.net.HttpURLConnection.HTTP_NOT_MODIFIED; | import static java.net.HttpURLConnection.HTTP_NOT_MODIFIED; | |||
import static java.net.HttpURLConnection.HTTP_OK; | import static java.net.HttpURLConnection.HTTP_OK; | |||
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; | import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; | |||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | |||
import static org.mockito.Mockito.mock; | import static org.mockito.Mockito.mock; | |||
skipping to change at line 458 | skipping to change at line 459 | |||
} | } | |||
} | } | |||
@Test(expected = CustomRuntimeException.class) | @Test(expected = CustomRuntimeException.class) | |||
public void startDevModeHandler_prepareTasksThrows_handleThrows() | public void startDevModeHandler_prepareTasksThrows_handleThrows() | |||
throws IOException { | throws IOException { | |||
CompletableFuture<Void> throwFuture = new CompletableFuture<>(); | CompletableFuture<Void> throwFuture = new CompletableFuture<>(); | |||
throwFuture.completeExceptionally(new CustomRuntimeException()); | throwFuture.completeExceptionally(new CustomRuntimeException()); | |||
DevModeHandler handler = DevModeHandler.start(0, configuration, | DevModeHandler handler = DevModeHandler.start(0, configuration, | |||
npmFolder, throwFuture); | npmFolder, throwFuture); | |||
try { | ||||
handler.join(); | ||||
} catch (CompletionException ignore) { | ||||
// this is an expected exception thrown on join for the handler | ||||
} | ||||
handler.handleRequest(Mockito.mock(VaadinSession.class), | handler.handleRequest(Mockito.mock(VaadinSession.class), | |||
Mockito.mock(VaadinRequest.class), | Mockito.mock(VaadinRequest.class), | |||
Mockito.mock(VaadinResponse.class)); | Mockito.mock(VaadinResponse.class)); | |||
} | } | |||
@Test | @Test | |||
public void serveDevModeRequest_prepareTasksThrows_serveDevModeReturnsFalseA ndDoesNotThrow() | public void serveDevModeRequest_prepareTasksThrows_serveDevModeReturnsFalseA ndDoesNotThrow() | |||
throws IOException { | throws IOException { | |||
CompletableFuture<Void> throwFuture = new CompletableFuture<>(); | CompletableFuture<Void> throwFuture = new CompletableFuture<>(); | |||
throwFuture.completeExceptionally(new CustomRuntimeException()); | throwFuture.completeExceptionally(new CustomRuntimeException()); | |||
skipping to change at line 561 | skipping to change at line 568 | |||
public void start_serverPortDoesNotWork_throws() throws Exception { | public void start_serverPortDoesNotWork_throws() throws Exception { | |||
exception.expect(CompletionException.class); | exception.expect(CompletionException.class); | |||
exception.expectCause(Matchers.instanceOf(IllegalStateException.class)); | exception.expectCause(Matchers.instanceOf(IllegalStateException.class)); | |||
int port = DevModeHandler.getFreePort(); | int port = DevModeHandler.getFreePort(); | |||
DevModeHandler handler = DevModeHandler.start(port, configuration, | DevModeHandler handler = DevModeHandler.start(port, configuration, | |||
npmFolder, CompletableFuture.completedFuture(null)); | npmFolder, CompletableFuture.completedFuture(null)); | |||
handler.join(); | handler.join(); | |||
} | } | |||
@Test | @Test | |||
public void serveDevModeRequest_uriWithDirectoryChangeWithSlash_returnsImmed | ||||
iatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/../vaadin-bundle-1234.cache.js"); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeWithBackslash_returnsI | ||||
mmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/something\\..\\vaadin-bundle-1234.cache.js"); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeWithEncodedBackslashUp | ||||
perCase_returnsImmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/something%5C..%5Cvaadin-bundle-1234.cache.js"); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeWithEncodedBackslashLo | ||||
werCase_returnsImmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/something%5c..%5cvaadin-bundle-1234.cache.js"); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeInTheEndWithSlash_retu | ||||
rnsImmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/.."); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeInTheEndWithBackslash_ | ||||
returnsImmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/something\\.."); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeInTheEndWithEncodedBac | ||||
kslashUpperCase_returnsImmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/something%5C.."); | ||||
} | ||||
@Test | ||||
public void serveDevModeRequest_uriWithDirectoryChangeInTheEndWithEncodedBac | ||||
kslashLowerCase_returnsImmediatelyAndSetsForbiddenStatus() | ||||
throws IOException { | ||||
verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
"/VAADIN/build/something%5c.."); | ||||
} | ||||
private void verifyServeDevModeRequestReturnsTrueAndSetsProperStatusCode( | ||||
String uri) throws IOException { | ||||
HttpServletRequest request = prepareRequest(uri); | ||||
HttpServletResponse response = prepareResponse(); | ||||
DevModeHandler handler = DevModeHandler.start(configuration, npmFolder, | ||||
CompletableFuture.completedFuture(null)); | ||||
handler.join(); | ||||
assertTrue(handler.serveDevModeRequest(request, response)); | ||||
Assert.assertEquals(HTTP_FORBIDDEN, responseStatus); | ||||
} | ||||
@Test | ||||
public void devModeNotReady_handleRequest_returnsHtml() throws Exception { | public void devModeNotReady_handleRequest_returnsHtml() throws Exception { | |||
DevModeHandler handler = DevModeHandler.start(configuration, npmFolder, | DevModeHandler handler = DevModeHandler.start(configuration, npmFolder, | |||
CompletableFuture.completedFuture(null)); | CompletableFuture.completedFuture(null)); | |||
VaadinResponse response = Mockito.mock(VaadinResponse.class); | VaadinResponse response = Mockito.mock(VaadinResponse.class); | |||
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |||
Mockito.when(response.getOutputStream()).thenReturn(stream); | Mockito.when(response.getOutputStream()).thenReturn(stream); | |||
handler.handleRequest(Mockito.mock(VaadinSession.class), | handler.handleRequest(Mockito.mock(VaadinSession.class), | |||
Mockito.mock(VaadinRequest.class), response); | Mockito.mock(VaadinRequest.class), response); | |||
String devModeNotReadyContents = stream.toString("UTF-8"); | String devModeNotReadyContents = stream.toString("UTF-8"); | |||
Document document = Jsoup.parse(devModeNotReadyContents); | Document document = Jsoup.parse(devModeNotReadyContents); | |||
End of changes. 3 change blocks. | ||||
0 lines changed or deleted | 83 lines changed or added |