public void testAuth() throws Exception { final AtomicReference<String> usernameRef = new AtomicReference<String>(); final AtomicReference<String> passwordRef = new AtomicReference<String>(); Support support = new Support() { @Override protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle lifeCycle = super.createLifeCycle(); lifeCycle.setProperty(MailPlugin.SMTP_USERNAME, "foo"); lifeCycle.setProperty(MailPlugin.SMTP_PASSWORD, "bar"); return lifeCycle; } @Override protected SMTPServer createServer(MessageHandlerFactory mhf) { SMTPServer smtpServer = super.createServer(mhf); smtpServer.setAuthenticationHandlerFactory(new LoginAuthenticationHandlerFactory(new UsernamePasswordValidator() { public void login(String username, String password) throws LoginFailedException { usernameRef.set(username); passwordRef.set(password); } })); return smtpServer; } }; support.doTest(); assertEquals("foo", usernameRef.get()); assertEquals("bar", passwordRef.get()); }
public void testAuthFailed() throws Exception { final AtomicBoolean done = new AtomicBoolean(); Support support = new Support() { @Override protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle lifeCycle = super.createLifeCycle(); lifeCycle.setProperty(MailPlugin.SMTP_USERNAME, "foo"); lifeCycle.setProperty(MailPlugin.SMTP_PASSWORD, "bar"); return lifeCycle; } @Override protected SMTPServer createServer(MessageHandlerFactory mhf) { SMTPServer smtpServer = super.createServer(mhf); smtpServer.setAuthenticationHandlerFactory(new LoginAuthenticationHandlerFactory(new UsernamePasswordValidator() { public void login(String username, String password) throws LoginFailedException { done.set(true); throw new LoginFailedException(); } })); return smtpServer; } @Override protected void assertResponse(Wiser wiser, Future<Boolean> response) throws MessagingException, ExecutionException, InterruptedException { assertFalse(response.get()); } }; support.doTest(); assertEquals(true, done.get()); }