From e932bd942e45ccf5a8fb36cd27faa16f697f124d Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Mon, 7 Nov 2011 12:16:41 +0000 Subject: [PATCH] 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 --- .../email/InboundSMTP/inboundSMTP.properties | 3 +- .../email/server/EmailServiceImplTest.java | 102 +++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties b/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties index b22bcd4607..4e89ec540f 100755 --- a/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties +++ b/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties @@ -13,7 +13,8 @@ email.server.domain=alfresco.com email.server.allowed.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 # Set this to true to accept TLS but not announce it when the EHLO is called. diff --git a/source/java/org/alfresco/email/server/EmailServiceImplTest.java b/source/java/org/alfresco/email/server/EmailServiceImplTest.java index 6b2011da2a..5aba66eaa4 100644 --- a/source/java/org/alfresco/email/server/EmailServiceImplTest.java +++ b/source/java/org/alfresco/email/server/EmailServiceImplTest.java @@ -547,5 +547,105 @@ public class EmailServiceImplTest extends TestCase assertTrue(TEST_SUBJECT+"(1) not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Practical Bee Keeping(1)"))); } + + /** + * 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 props = new HashMap(); + 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 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 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