2020import java .util .concurrent .ExecutorService ;
2121import java .util .concurrent .TimeUnit ;
2222
23+ import ch .qos .logback .classic .Level ;
2324import ch .qos .logback .classic .blackbox .BlackboxClassicTestConstants ;
2425import ch .qos .logback .classic .net .SMTPAppender ;
2526import ch .qos .logback .classic .util .LogbackMDCAdapter ;
2627import ch .qos .logback .core .util .EnvUtil ;
28+ import com .icegreen .greenmail .util .*;
2729import org .dom4j .DocumentException ;
2830import org .dom4j .io .SAXReader ;
2931import org .junit .jupiter .api .AfterEach ;
3032import org .junit .jupiter .api .BeforeEach ;
3133import org .junit .jupiter .api .Disabled ;
3234import org .junit .jupiter .api .Test ;
35+ import org .slf4j .LoggerFactory ;
3336import org .slf4j .MDC ;
3437
35- import com .icegreen .greenmail .util .DummySSLSocketFactory ;
36- import com .icegreen .greenmail .util .GreenMail ;
37- import com .icegreen .greenmail .util .GreenMailUtil ;
38- import com .icegreen .greenmail .util .ServerSetup ;
39-
4038//import ch.qos.logback.classic.ClassicTestConstants;
4139import ch .qos .logback .classic .Logger ;
4240import ch .qos .logback .classic .LoggerContext ;
@@ -66,6 +64,11 @@ public class SMTPAppender_GreenTest {
6664 static final String FOOTER = "FOOTER\n " ;
6765 static final String DEFAULT_PATTERN = "%-4relative %mdc [%thread] %-5level %class - %msg%n" ;
6866
67+ static final String JAVAX_NET_DEBUG_KEY = "javax.net.debug" ;
68+ static final String SSH_HANDSHAKE_DEBUG_VAL = "ssl:handshake" ;
69+ // for use in authenticated SSL tests only (to avoid SSL handshake failures)
70+ static final String CHECK_SERVER_IDENTITY_KEY = "mail.smtp.ssl.checkserveridentity" ;
71+
6972 static final boolean SYNCHRONOUS = false ;
7073 static final boolean ASYNCHRONOUS = true ;
7174 static int TIMEOUT = 3000 ;
@@ -82,12 +85,27 @@ public class SMTPAppender_GreenTest {
8285 static String REQUIRED_USERNAME = "alice" ;
8386 static String REQUIRED_PASSWORD = "alicepass" ;
8487
88+
8589 @ BeforeEach
8690 public void setUp () throws Exception {
8791 loggerContext .setMDCAdapter (logbackMDCAdapter );
8892 StatusListenerConfigHelper .addOnConsoleListenerInstance (loggerContext , new OnConsoleStatusListener ());
93+ setGlobalLogbackLoggerForGreenmail (Level .INFO );
94+ }
95+
96+
97+ @ AfterEach
98+ public void tearDown () throws Exception {
99+ greenMailServer .stop ();
100+ setGlobalLogbackLoggerForGreenmail (null );
89101 }
90102
103+ private static void setGlobalLogbackLoggerForGreenmail (Level level ) {
104+ Logger logbackLogger = (Logger ) LoggerFactory .getLogger ("com.icegreen.greenmail" );
105+ logbackLogger .setLevel (level );
106+ }
107+
108+
91109 void startSMTPServer (boolean withSSL ) {
92110 ServerSetup serverSetup ;
93111
@@ -107,10 +125,6 @@ void startSMTPServer(boolean withSSL) {
107125 }
108126 }
109127
110- @ AfterEach
111- public void tearDown () throws Exception {
112- greenMailServer .stop ();
113- }
114128
115129 void buildSMTPAppender (String subject , boolean synchronicity ) throws Exception {
116130 smtpAppender = new SMTPAppender ();
@@ -456,9 +470,12 @@ void unsetSystemPropertiesForStartTLS() {
456470
457471 @ Test
458472 public void authenticatedSSL () throws Exception {
473+
459474 try {
475+ // without setting this property, the SSL handshake fails with newer icegreen, angus versions
476+ System .setProperty (CHECK_SERVER_IDENTITY_KEY , "false" );
460477 setSystemPropertiesForStartTLS ();
461-
478+ //System.setProperty("greenmail.smtps.host", "127.0.0.1");
462479 startSMTPServer (WITH_SSL );
463480 buildSMTPAppender ("testMultipleTo" , SYNCHRONOUS );
464481 smtpAppender .setUsername (REQUIRED_USERNAME );
@@ -478,6 +495,7 @@ public void authenticatedSSL() throws Exception {
478495 assertNotNull (mma );
479496 assertTrue (mma .length == 1 , "body should not be empty" );
480497 } finally {
498+ System .clearProperty (CHECK_SERVER_IDENTITY_KEY );
481499 unsetSystemPropertiesForStartTLS ();
482500 }
483501 }
0 commit comments