use of org.subethamail.smtp.server.SMTPServer in project vertx-examples by vert-x3.
the class LocalSmtpServer method startWithAuth.
public static void startWithAuth(int port) {
SMTPServer server = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener()));
server.setPort(port);
UsernamePasswordValidator validator = (s, s1) -> {
if (!"username".equalsIgnoreCase(s) || !"password".equalsIgnoreCase(s1)) {
throw new LoginFailedException();
}
};
server.setAuthenticationHandlerFactory(new PlainAuthenticationHandlerFactory(validator));
server.start();
}
use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.
the class SmtpServerFactoryImpl method create.
@Override
public SmtpServer create() {
SimpleMessageListenerAdapter simpleMessageListenerAdapter = new SimpleMessageListenerAdapter(emailPersister);
SMTPServer smtpServer = new SMTPServer(simpleMessageListenerAdapter);
configurator.configure(smtpServer);
return new SmtpServerImpl(smtpServer);
}
use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.
the class SmtpServerConfiguratorTest method shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull.
@Test
public void shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull() {
final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(null);
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
final SMTPServer smtpServer = mock(SMTPServer.class);
sut.configure(smtpServer);
verify(smtpServer, never()).setAuthenticationHandlerFactory(any(AuthenticationHandlerFactory.class));
verify(logger).error(startsWith("Username"));
}
use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.
the class SmtpServerConfiguratorTest method shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull.
@Test
public void shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull() {
final String username = "username";
final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(username);
when(authentication.getPassword()).thenReturn(null);
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
final SMTPServer smtpServer = mock(SMTPServer.class);
sut.configure(smtpServer);
verify(smtpServer, never()).setAuthenticationHandlerFactory(any(AuthenticationHandlerFactory.class));
verify(logger).error(startsWith("Password"));
}
use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.
the class SmtpServerConfiguratorTest method shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly.
@Test
public void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly() {
final String username = "username";
final String password = "password";
final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
when(authentication.getUsername()).thenReturn(username);
when(authentication.getPassword()).thenReturn(password);
when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
final SMTPServer smtpServer = mock(SMTPServer.class);
sut.configure(smtpServer);
ArgumentCaptor<AuthenticationHandlerFactory> argumentCaptor = ArgumentCaptor.forClass(AuthenticationHandlerFactory.class);
verify(smtpServer).setAuthenticationHandlerFactory(argumentCaptor.capture());
AuthenticationHandlerFactory authenticationHandlerFactory = argumentCaptor.getValue();
assertNotNull(authenticationHandlerFactory);
assertThat(authenticationHandlerFactory, instanceOf(EasyAuthenticationHandlerFactory.class));
EasyAuthenticationHandlerFactory easyAuthenticationHandlerFactory = (EasyAuthenticationHandlerFactory) authenticationHandlerFactory;
assertSame(basicUsernamePasswordValidator, easyAuthenticationHandlerFactory.getValidator());
}
Aggregations