@Test public void testFormatEmailLoggedInOnly() throws Exception { final ApplicationProperties applicationProperties = getMock(ApplicationProperties.class); expect(applicationProperties.getString(APKeys.JIRA_OPTION_EMAIL_VISIBLE)) .andReturn("user") .times(2); final EmailFormatterImpl formatter = instantiate(EmailFormatterImpl.class); assertEquals(USER_EXAMPLE_ORG, formatter.formatEmail(USER_EXAMPLE_ORG, true)); assertNull(formatter.formatEmail(USER_EXAMPLE_ORG, false)); }
@Test public void testFormatEmailAsLinkEncoding() { MockControl mockApplicationPropertiesControl = MockControl.createControl(ApplicationProperties.class); ApplicationProperties mockApplicationProperties = (ApplicationProperties) mockApplicationPropertiesControl.getMock(); mockApplicationProperties.getString("jira.option.emailvisible"); mockApplicationPropertiesControl.setDefaultReturnValue("show"); mockApplicationPropertiesControl.replay(); EmailFormatterImpl emailFormatter = new EmailFormatterImpl(mockApplicationProperties); String email = emailFormatter.formatEmailAsLink("*****@*****.**", null); assertEquals("<a href=\"mailto:[email protected]\">[email protected]</a>", email); email = emailFormatter.formatEmailAsLink("\"<script>alert('owned')</script>\"@localhost", null); assertEquals( "<a href=\"mailto:"<script>alert('owned')</script>"@localhost\">"<script>alert('owned')</script>"@localhost</a>", email); mockApplicationPropertiesControl.verify(); }