Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRESOLVER-579] The TODO part #530

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,18 @@ public String getHttpsUrl() {
}

public HttpServer addSslConnector() {
return addSslConnector(true);
return addSslConnector(true, true);
}

public HttpServer addSelfSignedSslConnector() {
return addSslConnector(false);
return addSslConnector(false, true);
}

private HttpServer addSslConnector(boolean needClientAuth) {
public HttpServer addSelfSignedSslConnectorHttp2Only() {
return addSslConnector(false, false);
}

private HttpServer addSslConnector(boolean needClientAuth, boolean needHttp11) {
if (httpsConnector == null) {
SslContextFactory.Server ssl = new SslContextFactory.Server();
ssl.setNeedClientAuth(needClientAuth);
Expand All @@ -179,15 +183,22 @@ private HttpServer addSslConnector(boolean needClientAuth) {
customizer.setSniHostCheck(false);
httpsConfig.addCustomizer(customizer);

HttpConnectionFactory http1 = new HttpConnectionFactory(httpsConfig);
HttpConnectionFactory http1 = null;
if (needHttp11) {
http1 = new HttpConnectionFactory(httpsConfig);
}

HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpsConfig);

ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http1.getProtocol());
alpn.setDefaultProtocol(http1 != null ? http1.getProtocol() : http2.getProtocol());

SslConnectionFactory tls = new SslConnectionFactory(ssl, alpn.getProtocol());
httpsConnector = new ServerConnector(server, tls, alpn, http2, http1);
if (http1 != null) {
httpsConnector = new ServerConnector(server, tls, alpn, http2, http1);
} else {
httpsConnector = new ServerConnector(server, tls, alpn, http2);
}
server.addConnector(httpsConnector);
try {
httpsConnector.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ protected void testGet_HTTPS_Unknown_SecurityMode() throws Exception {

@Test
protected void testGet_HTTPS_Insecure_SecurityMode() throws Exception {
// here we use alternate server-store-selfigned key (as the key set it static initalizer is probably already
// here we use alternate server-store-selfigned key (as the key set it static initializer is probably already
// used to init SSLContext/SSLSocketFactory/etc
session.setConfigProperty(
ConfigurationProperties.HTTPS_SECURITY_MODE, ConfigurationProperties.HTTPS_SECURITY_MODE_INSECURE);
Expand All @@ -529,6 +529,25 @@ protected void testGet_HTTPS_Insecure_SecurityMode() throws Exception {
assertEquals(task.getDataString(), listener.getBaos().toString(StandardCharsets.UTF_8));
}

@Test
protected void testGet_HTTPS_HTTP2Only_Insecure_SecurityMode() throws Exception {
// here we use alternate server-store-selfigned key (as the key set it static initializer is probably already
// used to init SSLContext/SSLSocketFactory/etc
session.setConfigProperty(
ConfigurationProperties.HTTPS_SECURITY_MODE, ConfigurationProperties.HTTPS_SECURITY_MODE_INSECURE);
httpServer.addSelfSignedSslConnectorHttp2Only();
newTransporter(httpServer.getHttpsUrl());
RecordingTransportListener listener = new RecordingTransportListener();
GetTask task = new GetTask(URI.create("repo/file.txt")).setListener(listener);
transporter.get(task);
assertEquals("test", task.getDataString());
assertEquals(0L, listener.getDataOffset());
assertEquals(4L, listener.getDataLength());
assertEquals(1, listener.getStartedCount());
assertTrue(listener.getProgressedCount() > 0, "Count: " + listener.getProgressedCount());
assertEquals(task.getDataString(), listener.getBaos().toString(StandardCharsets.UTF_8));
}

@Test
protected void testGet_Redirect() throws Exception {
httpServer.addSslConnector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.aether.internal.test.util.http.RecordingTransportListener;
import org.eclipse.aether.spi.connector.transport.GetTask;
import org.eclipse.aether.spi.connector.transport.PutTask;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -46,6 +47,11 @@ public ApacheTransporterTest() {
super(() -> new ApacheTransporterFactory(standardChecksumExtractor(), new TestPathProcessor()));
}

@Override
@Disabled
@Test
protected void testGet_HTTPS_HTTP2Only_Insecure_SecurityMode() throws Exception {}

@Test
void testGet_WebDav() throws Exception {
httpServer.setWebDav(true);
Expand Down