Skip to content

Commit

Permalink
Close client after each test to avoid intermittent failures on MacOS. (
Browse files Browse the repository at this point in the history
…#5155)

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas authored Oct 11, 2022
1 parent 7c09327 commit f030bf1
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.helidon.common.http.HtmlEncoder;
import io.helidon.common.http.Http;

import io.helidon.common.testing.http.junit5.SocketHttpClient;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand All @@ -42,34 +43,42 @@ static void startServer() throws Exception {

@Test
void testScriptInjection() throws Exception {
String s = socketClient().sendAndReceive("/bar%3cscript%3eevil%3c%2fscript%3e",
Http.Method.GET, null);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
try (SocketHttpClient client = socketClient()) {
String s = client.sendAndReceive("/bar%3cscript%3eevil%3c%2fscript%3e",
Http.Method.GET, null);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
}
}

@Test
void testScriptInjectionIllegalUrlChar() throws Exception {
String s = socketClient().sendAndReceive("/bar<script/>evil</script>",
Http.Method.GET, null);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
try (SocketHttpClient client = socketClient()) {
String s = client.sendAndReceive("/bar<script/>evil</script>",
Http.Method.GET, null);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
}
}

@Test
void testScriptInjectionContentType() throws Exception {
List<String> requestHeaders = Arrays.asList("Content-Type: <script>evil</script>");
String s = socketClient().sendAndReceive("/foo",
Http.Method.GET, null, requestHeaders);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
try (SocketHttpClient client = socketClient()) {
List<String> requestHeaders = Arrays.asList("Content-Type: <script>evil</script>");
String s = client.sendAndReceive("/foo",
Http.Method.GET, null, requestHeaders);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
}
}

@Test
void testResponseEncoding() throws Exception {
String s = socketClient().sendAndReceive("/foo",
Http.Method.GET, null);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
try (SocketHttpClient client = socketClient()) {
String s = client.sendAndReceive("/foo",
Http.Method.GET, null);
assertThat(s, not(containsString("<script>")));
assertThat(s, not(containsString("</script>")));
}
}
}

0 comments on commit f030bf1

Please sign in to comment.