Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)

73354: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud)
      73241: MNT-11079: Merged DEV to V4.2-BUG-FIX (4.2.3)
         67748: MNT-11079: "Start Workflow" email notification is not sent out if the recipient's User Name contians "@"
            - During defining mail recipients first check email field and only then check if the username is the valid email address. Fix formatting and cleanup for other MailActionExecuterTest tests.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74772 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Will Abson
2014-06-25 15:59:25 +00:00
parent a6cd47c741
commit 0b5a6de25c
2 changed files with 86 additions and 37 deletions

View File

@@ -1169,19 +1169,19 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
{
if (personExists(authority))
{
EmailValidator emailValidator = EmailValidator.getInstance(true);
if (validateAddresses && emailValidator.isValid(authority))
String address = getPersonEmail(authority);
if (address != null && address.length() != 0 && validateAddress(address))
{
Locale locale = getLocaleForUser(authority);
recipients.add(new Pair<String, Locale>(authority, locale));
recipients.add(new Pair<String, Locale>(address, locale));
}
else
{
String address = getPersonEmail(authority);
if (address != null && address.length() != 0 && validateAddress(address))
EmailValidator emailValidator = EmailValidator.getInstance(true);
if (validateAddresses && emailValidator.isValid(authority))
{
Locale locale = getLocaleForUser(authority);
recipients.add(new Pair<String, Locale>(address, locale));
recipients.add(new Pair<String, Locale>(authority, locale));
}
}
}
@@ -1211,22 +1211,22 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
// Check the user name to be a valid email and we don't need to log an error in this case
// ALF-19231
// Validate the email, allowing for local email addresses
EmailValidator emailValidator = EmailValidator.getInstance(true);
if (validateAddresses && emailValidator.isValid(userAuth))
String address = getPersonEmail(userAuth);
if (address != null && address.length() != 0 && validateAddress(address))
{
if (userAuth != null && userAuth.length() != 0)
{
Locale locale = getLocaleForUser(userAuth);
recipients.add(new Pair<String, Locale>(userAuth, locale));
}
Locale locale = getLocaleForUser(userAuth);
recipients.add(new Pair<String, Locale>(address, locale));
}
else
{
String address = getPersonEmail(userAuth);
if (address != null && address.length() != 0 && validateAddress(address))
EmailValidator emailValidator = EmailValidator.getInstance(true);
if (validateAddresses && emailValidator.isValid(userAuth))
{
Locale locale = getLocaleForUser(userAuth);
recipients.add(new Pair<String, Locale>(address, locale));
if (userAuth != null && userAuth.length() != 0)
{
Locale locale = getLocaleForUser(userAuth);
recipients.add(new Pair<String, Locale>(userAuth, locale));
}
}
}
}

View File

@@ -335,10 +335,10 @@ public abstract class AbstractMailActionExecuterTest
public void testPrepareEmailForDisabledUsers() throws MessagingException
{
String groupName = null;
final String USER1 = "test_user1";
final String USER2 = "test_user2";
try
{
final String USER1 = "test_user1";
final String USER2 = "test_user2";
createUser(USER1, null);
NodeRef userNode = createUser(USER2, null);
groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1");
@@ -373,6 +373,8 @@ public abstract class AbstractMailActionExecuterTest
{
AUTHORITY_SERVICE.deleteAuthority(groupName, true);
}
PERSON_SERVICE.deletePerson(USER1);
PERSON_SERVICE.deletePerson(USER2);
}
}
@@ -410,26 +412,35 @@ public abstract class AbstractMailActionExecuterTest
{
final String USER_WITH_NON_EXISTING_TENANT = "test_user_non_tenant@non_existing_tenant.com";
createUser(USER_WITH_NON_EXISTING_TENANT, USER_WITH_NON_EXISTING_TENANT);
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, USER_WITH_NON_EXISTING_TENANT);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "This is a test message.");
// run as non admin and non system
AuthenticationUtil.setFullyAuthenticatedUser(BRITISH_USER.getUsername());
TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
try
{
@Override
public Void execute() throws Throwable
{
ACTION_EXECUTER.executeImpl(mailAction, null);
return null;
}
});
createUser(USER_WITH_NON_EXISTING_TENANT, USER_WITH_NON_EXISTING_TENANT);
AuthenticationUtil.clearCurrentSecurityContext();
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, USER_WITH_NON_EXISTING_TENANT);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "This is a test message.");
// run as non admin and non system
AuthenticationUtil.setFullyAuthenticatedUser(BRITISH_USER.getUsername());
TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
ACTION_EXECUTER.executeImpl(mailAction, null);
return null;
}
});
}
finally
{
// restore system user as current user
AuthenticationUtil.setRunAsUserSystem();
// tidy up
PERSON_SERVICE.deletePerson(USER_WITH_NON_EXISTING_TENANT);
AuthenticationUtil.clearCurrentSecurityContext();
}
}
/**
@@ -478,4 +489,42 @@ public abstract class AbstractMailActionExecuterTest
}
}
/**
* Test for MNT-11079
*/
@Test
public void testSendingToUserWithMailAlikeName() throws IOException, MessagingException
{
final String USER_1 = "user1@namelookslikeemail";
final String USER_1_EMAIL = "user1@trueemail.com";
try
{
createUser(USER_1, USER_1_EMAIL);
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, USER_1);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());
ACTION_SERVICE.executeAction(mailAction, null);
MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Assert.assertEquals("Hello Jan 1, 1970", (String) message.getContent());
Assert.assertEquals(1, message.getAllRecipients().length);
javax.mail.internet.InternetAddress address = (InternetAddress) message.getAllRecipients()[0];
Assert.assertEquals(USER_1_EMAIL, address.getAddress());
}
finally
{
// tidy up
PERSON_SERVICE.deletePerson(USER_1);
}
}
}