Merge pull request elastic/elasticsearch#2685 from rjernst/uninject_htmlsanitizer

Uninject HtmlSanitizer

Original commit: elastic/x-pack-elasticsearch@4a6c8cdee6
This commit is contained in:
Ryan Ernst 2016-07-01 16:26:57 -07:00 committed by GitHub
commit d6ff6211eb
5 changed files with 9 additions and 15 deletions

View File

@ -41,7 +41,6 @@ public class NotificationModule extends AbstractModule {
@Override
protected void configure() {
// email
bind(HtmlSanitizer.class).asEagerSingleton();
bind(InternalEmailService.class).asEagerSingleton();
bind(EmailService.class).to(InternalEmailService.class).asEagerSingleton();

View File

@ -41,8 +41,7 @@ public class HtmlSanitizer {
private final boolean enabled;
@SuppressForbidden( reason = "PolicyFactory uses guava Function")
private final PolicyFactory policy;
@Inject
public HtmlSanitizer(Settings settings) {
enabled = settings.getAsBoolean("xpack.notification.email.html.sanitization.enabled", true);
String[] allow = settings.getAsArray("xpack.notification.email.html.sanitization.allow", DEFAULT_ALLOWED);

View File

@ -28,12 +28,12 @@ public class EmailActionFactory extends ActionFactory<EmailAction, ExecutableEma
private final EmailAttachmentsParser emailAttachmentsParser;
@Inject
public EmailActionFactory(Settings settings, EmailService emailService, TextTemplateEngine templateEngine, HtmlSanitizer htmlSanitizer,
public EmailActionFactory(Settings settings, EmailService emailService, TextTemplateEngine templateEngine,
EmailAttachmentsParser emailAttachmentsParser) {
super(Loggers.getLogger(ExecutableEmailAction.class, settings));
this.emailService = emailService;
this.templateEngine = templateEngine;
this.htmlSanitizer = htmlSanitizer;
this.htmlSanitizer = new HtmlSanitizer(settings);
this.emailAttachmentsParser = emailAttachmentsParser;
}

View File

@ -197,7 +197,6 @@ public class EmailActionTests extends ESTestCase {
public void testParser() throws Exception {
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
EmailService emailService = mock(EmailService.class);
Profile profile = randomFrom(Profile.values());
Email.Priority priority = randomFrom(Email.Priority.values());
@ -301,7 +300,7 @@ public class EmailActionTests extends ESTestCase {
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
ExecutableEmailAction executable = new EmailActionFactory(Settings.EMPTY, emailService, engine, htmlSanitizer,
ExecutableEmailAction executable = new EmailActionFactory(Settings.EMPTY, emailService, engine,
emailAttachmentParser)
.parseExecutable(randomAsciiOfLength(8), randomAsciiOfLength(3), parser);
@ -396,7 +395,7 @@ public class EmailActionTests extends ESTestCase {
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
ExecutableEmailAction parsed = new EmailActionFactory(Settings.EMPTY, service, engine, htmlSanitizer, emailAttachmentParser)
ExecutableEmailAction parsed = new EmailActionFactory(Settings.EMPTY, service, engine, emailAttachmentParser)
.parseExecutable(randomAsciiOfLength(4), randomAsciiOfLength(10), parser);
if (!hideSecrets) {
@ -420,14 +419,13 @@ public class EmailActionTests extends ESTestCase {
public void testParserInvalid() throws Exception {
EmailService emailService = mock(EmailService.class);
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
EmailAttachmentsParser emailAttachmentsParser = mock(EmailAttachmentsParser.class);
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value").endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
parser.nextToken();
try {
new EmailActionFactory(Settings.EMPTY, emailService, engine, htmlSanitizer, emailAttachmentsParser)
new EmailActionFactory(Settings.EMPTY, emailService, engine, emailAttachmentsParser)
.parseExecutable(randomAsciiOfLength(3), randomAsciiOfLength(7), parser);
} catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), containsString("unexpected string field [unknown_field]"));
@ -518,7 +516,6 @@ public class EmailActionTests extends ESTestCase {
public void testThatOneFailedEmailAttachmentResultsInActionFailure() throws Exception {
EmailService emailService = new AbstractWatcherIntegrationTestCase.NoopEmailService();
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
HttpClient httpClient = mock(HttpClient.class);
// setup mock response, second one is an error
@ -554,7 +551,7 @@ public class EmailActionTests extends ESTestCase {
parser.nextToken();
ExecutableEmailAction executableEmailAction = new EmailActionFactory(Settings.EMPTY, emailService, engine, htmlSanitizer,
ExecutableEmailAction executableEmailAction = new EmailActionFactory(Settings.EMPTY, emailService, engine,
emailAttachmentsParser).parseExecutable(randomAsciiOfLength(3), randomAsciiOfLength(7), parser);
DateTime now = DateTime.now(DateTimeZone.UTC);
@ -577,9 +574,8 @@ public class EmailActionTests extends ESTestCase {
private EmailActionFactory createEmailActionFactory() {
EmailService emailService = new AbstractWatcherIntegrationTestCase.NoopEmailService();
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
return new EmailActionFactory(Settings.EMPTY, emailService, engine, htmlSanitizer, emailAttachmentParser);
return new EmailActionFactory(Settings.EMPTY, emailService, engine, emailAttachmentParser);
}
private WatchExecutionContext createWatchExecutionContext() {

View File

@ -469,7 +469,7 @@ public class WatchTests extends ESTestCase {
for (ActionWrapper action : actions) {
switch (action.action().type()) {
case EmailAction.TYPE:
parsers.put(EmailAction.TYPE, new EmailActionFactory(settings, emailService, templateEngine, htmlSanitizer,
parsers.put(EmailAction.TYPE, new EmailActionFactory(settings, emailService, templateEngine,
new EmailAttachmentsParser(Collections.emptyMap())));
break;
case IndexAction.TYPE: