Веб-почта по HTTPS на том же адресе: https://mail.jambocheck.com (порт 443)
continuous-integration/drone/pr Build is passing
continuous-integration/drone/pr Build is passing
HTTPS_PORT — второй Netty-сервер с тем же HttpHandler и тем же сертификатом, что SMTP/IMAP (Let's Encrypt от acme, перечитывается при продлении). HSTS добавляет Spring Security. docker-compose.public.yml: 443 → 8443. HTTP 8080 остаётся для прокси внутри сети. Тесты: HttpsConfigTest, всего 74; живой запуск: /api/config по HTTPS, HSTS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.mailserver.config;
|
||||
|
||||
import com.mailserver.smtp.SmtpTls;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** https://mail.jambocheck.com: the web client over HTTPS with the mail certificate. */
|
||||
class HttpsConfigTest {
|
||||
|
||||
@Test
|
||||
void servesTheWebAppOverTls(@TempDir Path dir) throws Exception {
|
||||
MailServerConfig.SmtpTlsContext tls = new MailServerConfig.SmtpTlsContext(SmtpTls.serverContext("", "", dir, "localhost"));
|
||||
HttpHandler handler = (request, response) -> {
|
||||
response.setStatusCode(HttpStatus.OK);
|
||||
return response.writeWith(Mono.just(DefaultDataBufferFactory.sharedInstance
|
||||
.wrap(("hello " + request.getURI().getScheme()).getBytes(StandardCharsets.UTF_8))));
|
||||
};
|
||||
io.netty.handler.ssl.SslContext trustAll = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
||||
HttpsConfig.HttpsServer server = new HttpsConfig.HttpsServer(handler, tls, "127.0.0.1", 0);
|
||||
server.start();
|
||||
try {
|
||||
assertThat(server.isRunning()).isTrue();
|
||||
String body = HttpClient.create()
|
||||
.secure(spec -> spec.sslContext(trustAll))
|
||||
.get().uri("https://127.0.0.1:" + server.port() + "/")
|
||||
.responseContent().aggregate().asString().block();
|
||||
assertThat(body).isEqualTo("hello https");
|
||||
} finally {
|
||||
server.stop();
|
||||
}
|
||||
assertThat(server.isRunning()).isFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user