-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZCS-16489 Created LDAP attribute zimbraFeatureExternalEmailWarningEna…
…bled and modified condition to check for feature enabled Unit tests added for EEW Refactored code to store the flag and accounts to avoid multiple LDAP calls
- Loading branch information
Showing
8 changed files
with
368 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
store/src/java-test/com/zimbra/cs/service/mail/ExternalEmailWarningTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* | ||
* * ***** BEGIN LICENSE BLOCK ***** | ||
* * Zimbra Collaboration Suite, Network Edition. | ||
* * Copyright (C) 2025 Synacor, Inc. All Rights Reserved. | ||
* * ***** END LICENSE BLOCK ***** | ||
* | ||
*/ | ||
|
||
package com.zimbra.cs.service.mail; | ||
|
||
import com.zimbra.common.account.Key; | ||
import com.zimbra.common.service.ServiceException; | ||
import com.zimbra.cs.account.Account; | ||
import com.zimbra.cs.account.Provisioning; | ||
import com.zimbra.cs.lmtpserver.ExternalEmailWarning; | ||
import com.zimbra.cs.lmtpserver.LmtpAddress; | ||
import com.zimbra.cs.mailbox.MailboxTestUtil; | ||
import junit.framework.TestCase; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PowerMockIgnore("javax.management.*") | ||
public class ExternalEmailWarningTest extends TestCase{ | ||
|
||
Provisioning prov = Provisioning.getInstance(); | ||
List<LmtpAddress> recipients = new ArrayList<>(); | ||
ExternalEmailWarning externalEmailWarning = ExternalEmailWarning.getInstance(); | ||
String rcptEmail1; | ||
String rcptEmail2; | ||
|
||
@BeforeClass | ||
public static void init() throws Exception { | ||
MailboxTestUtil.initServer(); | ||
|
||
} | ||
|
||
protected void setUp() throws Exception { | ||
String recipient1 = "<\"test1.\"@domain.com>"; | ||
String recipient2 = "<\"test2.\"@domain.com>"; | ||
recipients.add(new LmtpAddress(recipient1, null, null)); | ||
recipients.add(new LmtpAddress(recipient2, null, null)); | ||
Map<String, Object> attrs1 = new HashMap<String, Object>(); | ||
attrs1.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "TRUE"); | ||
rcptEmail1 = recipients.get(0).getEmailAddress(); | ||
Map<String, Object> attrs2 = new HashMap<String, Object>(); | ||
attrs2.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "FALSE"); | ||
rcptEmail2 = recipients.get(1).getEmailAddress(); | ||
prov.createAccount(rcptEmail1, "test123", attrs1); | ||
prov.createAccount(rcptEmail2, "test123", attrs2); | ||
} | ||
|
||
public void testIsEnabled_AccountTrue() throws ServiceException { | ||
Account account = Provisioning.getInstance().get(Key.AccountBy.name, rcptEmail1); | ||
Assert.assertTrue(externalEmailWarning.isEnabled(account)); | ||
} | ||
|
||
public void testIsEnabled_AccountFalse() throws ServiceException { | ||
Account account = Provisioning.getInstance().get(Key.AccountBy.name, rcptEmail2); | ||
Assert.assertFalse(externalEmailWarning.isEnabled(account)); | ||
} | ||
|
||
public void testIsEnabled_RecipientsTrue() { | ||
Assert.assertTrue(externalEmailWarning.isEnabled(recipients)); | ||
} | ||
|
||
public void testIsEnabled_RecipientsFalse() throws ServiceException { | ||
Map<String, Object> attrs = new HashMap<String, Object>(); | ||
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "FALSE"); | ||
Account account = Provisioning.getInstance().get(Key.AccountBy.name, rcptEmail1); | ||
account.deleteAccount(); | ||
prov.createAccount(rcptEmail1, "test123", attrs); | ||
Assert.assertFalse(externalEmailWarning.isEnabled(recipients)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.