@Override public MailHost mailHost() { return serverConfig.mailHost(); }
public MailHost getMailHost() { return serverConfig().mailHost(); }
@Override public String adminEmail() { return server().mailHost().getAdminMail(); }
public GoMailSender getMailSender() { return GoSmtpMailSender.createSender(serverConfig().mailHost()); }
@Override public boolean isSmtpEnabled() { MailHost mailHost = server().mailHost(); return mailHost != null && !mailHost.equals(new MailHost(new GoCipher())); }
@Test public void shouldNotUpdatePasswordForMailHostIfNotChangedOrNull() throws IOException { File cipherFile = new SystemEnvironment().getDESCipherFile(); FileUtils.deleteQuietly(cipherFile); FileUtils.writeStringToFile(cipherFile, "269298bc31c44620", UTF_8); GoCipher goCipher = new GoCipher(); MailHost mailHost = new MailHost("abc", 12, "admin", "p", null, true, true, "anc@mail.com", "anc@mail.com", goCipher); ServerConfig serverConfig = new ServerConfig(null, mailHost, null, null); assertThat(serverConfig.mailHost().getPassword(), is("p")); String encryptedPassword = serverConfig.mailHost().getEncryptedPassword(); serverConfig.updateMailHost(new MailHost("abc", 12, "admin", "p", encryptedPassword, false /* Password Not Changed */, true, "anc@mail.com", "anc@mail.com", goCipher)); assertThat(serverConfig.mailHost().getPassword(), is("p")); assertThat(serverConfig.mailHost().getEncryptedPassword(), is(encryptedPassword)); serverConfig.updateMailHost(new MailHost("abc", 12, "admin", null, "", true, true, "anc@mail.com", "anc@mail.com")); assertThat(serverConfig.mailHost().getPassword(), is(nullValue())); assertThat(serverConfig.mailHost().getEncryptedPassword(), is(nullValue())); }
@Test public void shouldMigrateServerMailhostEncryptedPasswordWithNewlineAndSpaces_XslMigrationFrom88To90() throws Exception { resetCipher.setupDESCipherFile(); String plainText = "user-password!"; // "user-password!" encrypted using the above key String encryptedValue = "mvcX9yrQsM4iPgm1tDxN1A=="; String encryptedValueWithWhitespaceAndNewline = new StringBuilder(encryptedValue).insert(2, "\r\n" + " ").toString(); String content = config( "<server artifactsdir='artifacts'>\n" + " <mailhost hostname='host' port='25' username='user' encryptedPassword='" + encryptedValueWithWhitespaceAndNewline + "' tls='false' from='user@domain.com' admin='admin@domain.com' />\n" + " </server>", 88); CruiseConfig config = ConfigMigrator.loadWithMigration(content).config; assertThat(config.server().mailHost().getPassword(), is(plainText)); assertThat(config.server().mailHost().getEncryptedPassword(), startsWith("AES:")); assertThat(config.server().mailHost().getHostName(), is("host")); }
@Test public void shouldMigrateDESServerMailhostEncryptedPassword_XslMigrationFrom108To109() throws Exception { resetCipher.setupDESCipherFile(); String clearText = "user-password!"; // "user-password!" encrypted using the above key String desEncryptedPassword = "mvcX9yrQsM4iPgm1tDxN1A=="; String content = config( "<server artifactsdir='artifacts'>" + " <mailhost hostname='host' port='25' username='user' encryptedPassword='" + desEncryptedPassword + "' tls='false' from='user@domain.com' admin='admin@domain.com' />" + " </server>", 108); CruiseConfig config = ConfigMigrator.loadWithMigration(content).config; assertThat(config.server().mailHost().getPassword(), is(clearText)); assertThat(config.server().mailHost().getEncryptedPassword(), startsWith("AES:")); assertThat(config.server().mailHost().getHostName(), is("host")); }
@Test public void shouldParseServerConfigWithMailhost() throws Exception { String xml = "<mailhost hostname=\"smtp.company.com\" port=\"25\" " + "username=\"smtpuser\" password=\"password\" tls=\"true\" " + "from=\"cruise@me.com\" admin=\"jez@me.com\"/>"; ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins(); CruiseConfig config = new MagicalGoConfigXmlLoader(new ConfigCache(), registry).loadConfigHolder(withServerConfig(xml)).config; MailHost mailHost = config.server().mailHost(); assertThat(mailHost, is(new MailHost("smtp.company.com", 25, "smtpuser", "password", true, true, "cruise@me.com", "jez@me.com"))); } }