Skip to content

Commit fe15c58

Browse files
committed
Update tests for https
1 parent 4531f81 commit fe15c58

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/test/java/io/fusionauth/http/BaseTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package io.fusionauth.http;
1717

18-
import java.io.File;
1918
import java.io.IOException;
2019
import java.io.InputStream;
2120
import java.io.OutputStream;
@@ -144,6 +143,18 @@ public HttpClient makeClient(String scheme, CookieHandler cookieHandler) throws
144143
return builder.connectTimeout(ClientTimeout).build();
145144
}
146145

146+
public Socket makeClientSocket(String scheme) throws GeneralSecurityException, IOException {
147+
Socket socket;
148+
if (scheme.equals("https")) {
149+
var ctx = SecurityTools.clientContext(rootCertificate);
150+
socket = ctx.getSocketFactory().createSocket("127.0.0.1", 4242);
151+
} else {
152+
socket = new Socket("127.0.0.1", 4242);
153+
}
154+
155+
return socket;
156+
}
157+
147158
public HTTPServer makeServer(String scheme, HTTPHandler handler, Instrumenter instrumenter) {
148159
return makeServer(scheme, handler, instrumenter, null);
149160
}

src/test/java/io/fusionauth/http/CoreTest.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ public void unicode(String scheme) throws Exception {
790790
@Test(dataProvider = "schemes")
791791
public void utf8HeaderValues(String scheme) throws Exception {
792792

793-
String city = "São Paulo";
793+
var city = "São Paulo";
794794

795795
HTTPHandler handler = (req, res) -> {
796796
res.setHeader(Headers.ContentType, "text/plain");
@@ -807,28 +807,31 @@ public void utf8HeaderValues(String scheme) throws Exception {
807807
}
808808
};
809809

810-
// Java HTTPClient only supports ASCII header values, so send it directly
811-
try (HTTPServer ignore = makeServer(scheme, handler).start(); Socket sock = new Socket("127.0.0.1", 4242)) {
810+
// Java HttpClient only supports ASCII header values, so send request directly
811+
try (HTTPServer ignore = makeServer(scheme, handler).start();
812+
Socket sock = makeClientSocket(scheme)) {
813+
812814
var os = sock.getOutputStream();
813815
var is = sock.getInputStream();
814-
os.write("""
815-
GET /api/status HTTP/1.1\r
816-
Host: localhost:42\r
817-
X-Request-Header: São Paulo\r
818-
\r
819-
""".getBytes(StandardCharsets.UTF_8));
816+
os.write(String.format("""
817+
GET /api/status HTTP/1.1\r
818+
Host: localhost:42\r
819+
X-Request-Header: %s\r
820+
\r
821+
""", city)
822+
.getBytes(StandardCharsets.UTF_8));
820823
os.flush();
821824

822825
var resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
823826

824-
assertEquals(resp, """
827+
assertEquals(resp, String.format("""
825828
HTTP/1.1 200 \r
826829
content-length: 16\r
827830
content-type: text/plain\r
828831
connection: keep-alive\r
829-
x-response-header: São Paulo\r
832+
x-response-header: %s\r
830833
\r
831-
{"version":"42"}""");
834+
{"version":"42"}""", city));
832835
}
833836
}
834837

0 commit comments

Comments
 (0)