mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added new test for Email Server to check configuration for EVERYONE group works.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31795 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -13,7 +13,8 @@ email.server.domain=alfresco.com
|
|||||||
email.server.allowed.senders=.*
|
email.server.allowed.senders=.*
|
||||||
email.server.blocked.senders=
|
email.server.blocked.senders=
|
||||||
|
|
||||||
# The authority name that users must be a member of in order to add email.
|
# The group authority name that users must be a member of in order to
|
||||||
|
# add email. Normally EMAIL_CONTRIBUTORS but may be changed to EVERYONE
|
||||||
email.inbound.emailContributorsAuthority=EMAIL_CONTRIBUTORS
|
email.inbound.emailContributorsAuthority=EMAIL_CONTRIBUTORS
|
||||||
|
|
||||||
# Set this to true to accept TLS but not announce it when the EHLO is called.
|
# Set this to true to accept TLS but not announce it when the EHLO is called.
|
||||||
|
@@ -548,4 +548,104 @@ public class EmailServiceImplTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* The Email contributors authority controls who can add email.
|
||||||
|
*
|
||||||
|
* This test switches between the EMAIL_CONTRIBUTORS group and EVERYONE
|
||||||
|
*/
|
||||||
|
public void testEmailContributorsAuthority() throws Exception
|
||||||
|
{
|
||||||
|
EmailServiceImpl emailServiceImpl = (EmailServiceImpl)emailService;
|
||||||
|
|
||||||
|
folderEmailMessageHandler.setOverwriteDuplicates(true);
|
||||||
|
|
||||||
|
logger.debug("Start testEmailContributorsAuthority");
|
||||||
|
|
||||||
|
String TEST_EMAIL="buffy@sunnydale.high";
|
||||||
|
|
||||||
|
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
|
||||||
|
NodeRef person = personService.getPerson(TEST_USER);
|
||||||
|
if(person == null)
|
||||||
|
{
|
||||||
|
logger.debug("new person created");
|
||||||
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||||
|
props.put(ContentModel.PROP_USERNAME, TEST_USER);
|
||||||
|
props.put(ContentModel.PROP_EMAIL, TEST_EMAIL);
|
||||||
|
person = personService.createPerson(props);
|
||||||
|
}
|
||||||
|
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
|
||||||
|
|
||||||
|
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
|
||||||
|
if(auths.contains(TEST_USER))
|
||||||
|
{
|
||||||
|
authorityService.removeAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
String companyHomePathInStore = "/app:company_home";
|
||||||
|
String storePath = "workspace://SpacesStore";
|
||||||
|
StoreRef storeRef = new StoreRef(storePath);
|
||||||
|
|
||||||
|
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
|
||||||
|
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
|
||||||
|
NodeRef companyHomeNodeRef = nodeRefs.get(0);
|
||||||
|
assertNotNull("company home is null", companyHomeNodeRef);
|
||||||
|
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
|
||||||
|
String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
|
||||||
|
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
|
||||||
|
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
|
||||||
|
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 1
|
||||||
|
* Set the email contributors authority to EVERYONE
|
||||||
|
*
|
||||||
|
* Test that TEST_USER is allowed to send email - so even though TEST_USER is not
|
||||||
|
* a contributor
|
||||||
|
*/
|
||||||
|
emailServiceImpl.setEmailContributorsAuthority("EVERYONE");
|
||||||
|
|
||||||
|
String from = "admin";
|
||||||
|
String to = testUserHomeDBID;
|
||||||
|
String content = "hello world";
|
||||||
|
|
||||||
|
Session sess = Session.getDefaultInstance(new Properties());
|
||||||
|
assertNotNull("sess is null", sess);
|
||||||
|
SMTPMessage msg = new SMTPMessage(sess);
|
||||||
|
InternetAddress[] toa = { new InternetAddress(to) };
|
||||||
|
|
||||||
|
msg.setFrom(new InternetAddress(TEST_EMAIL));
|
||||||
|
msg.setRecipients(Message.RecipientType.TO, toa);
|
||||||
|
msg.setSubject("JavaMail APIs transport.java Test");
|
||||||
|
msg.setContent(content, "text/plain");
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
msg.writeTo(bos);
|
||||||
|
InputStream is = new StringInputStream(bos.toString());
|
||||||
|
assertNotNull("is is null", is);
|
||||||
|
|
||||||
|
SubethaEmailMessage m = new SubethaEmailMessage(is);
|
||||||
|
|
||||||
|
emailService.importMessage(m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 2
|
||||||
|
* Negative test
|
||||||
|
*
|
||||||
|
* Send From the test user TEST_EMAIL to the test user's home
|
||||||
|
*/
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.debug("Step 2");
|
||||||
|
emailServiceImpl.setEmailContributorsAuthority("EMAIL_CONTRIBUTORS");
|
||||||
|
emailService.importMessage(m);
|
||||||
|
fail("not thrown out");
|
||||||
|
}
|
||||||
|
catch (EmailMessageException e)
|
||||||
|
{
|
||||||
|
// Check the exception is for the anonymous user.
|
||||||
|
// assertTrue(e.getMessage().contains("anonymous"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of EmailServiceImplTest
|
||||||
|
Reference in New Issue
Block a user