Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't check POP password when logging in with -Dgreenmail.auth.disa… #309

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public void authenticate(String pass)
if (user == null)
throw new UserException("No user selected");

user.authenticate(pass);
if (manager.isAuthRequired()) {
user.authenticate(pass);
}
inbox = imapHostManager.getInbox(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
*/
package com.icegreen.greenmail.user;

import com.icegreen.greenmail.imap.ImapHostManager;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import com.icegreen.greenmail.imap.ImapHostManager;

public class UserManager {
private static final Logger log = LoggerFactory.getLogger(UserManager.class);
Expand Down Expand Up @@ -65,7 +69,7 @@ public boolean test(String userId, String password) {
GreenMailUser u = getUser(userId);

if (!authRequired) {
if(null == u) { // Auto create user
if (null == u) { // Auto create user
try {
createUser(userId, userId, password);
} catch (UserException e) {
Expand All @@ -88,6 +92,10 @@ public void setAuthRequired(boolean auth) {
authRequired = auth;
}

public boolean isAuthRequired() {
return authRequired;
}

public ImapHostManager getImapHostManager() {
return imapHostManager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package com.icegreen.greenmail.test;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.junit.Rule;
import org.junit.Test;

import com.icegreen.greenmail.configuration.GreenMailConfiguration;
import com.icegreen.greenmail.junit.GreenMailRule;
import com.icegreen.greenmail.pop3.Pop3State;
import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.user.UserException;
import com.icegreen.greenmail.user.UserImpl;
import com.icegreen.greenmail.user.UserManager;
import com.icegreen.greenmail.util.GreenMailUtil;
import com.icegreen.greenmail.util.Retriever;
import com.icegreen.greenmail.util.ServerSetup;
import com.icegreen.greenmail.util.ServerSetupTest;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class AuthenticationDisabledTest {
@Rule
public final GreenMailRule greenMail = new GreenMailRule(new ServerSetup[]{ServerSetupTest.SMTP, ServerSetupTest.IMAP})
.withConfiguration(GreenMailConfiguration.aConfig().withDisabledAuthentication());
public final GreenMailRule greenMail = new GreenMailRule(
new ServerSetup[] { ServerSetupTest.SMTP, ServerSetupTest.IMAP })
.withConfiguration(GreenMailConfiguration.aConfig().withDisabledAuthentication());

@Test
public void testSendMailAndReceiveWithAuthDisabled() throws MessagingException, IOException {
Expand Down Expand Up @@ -57,7 +65,7 @@ public void testReceiveWithAuthDisabled() {
@Test
public void testReceiveWithAuthDisabledAndProvisionedUser() {
final String to = "to@localhost";
greenMail.setUser(to,"to","secret");
greenMail.setUser(to, "to", "secret");

greenMail.waitForIncomingEmail(500, 1);

Expand All @@ -66,4 +74,27 @@ public void testReceiveWithAuthDisabledAndProvisionedUser() {
assertEquals(0, messages.length);
}
}

@Test
public void testPop3ConnectNoAuth() throws MessagingException, UserException, FolderException {
UserManager userManager = greenMail.getManagers().getUserManager();
Pop3State status = new Pop3State(userManager);
userManager.setAuthRequired(false);

UserImpl user = new UserImpl("email@example.com", "user", "pwd", null);
status.setUser(user);
status.authenticate("pass");
}

@Test(expected = UserException.class)
public void testPop3ConnectAuth() throws MessagingException, UserException, FolderException {
UserManager userManager = greenMail.getManagers().getUserManager();
Pop3State status = new Pop3State(userManager);
userManager.setAuthRequired(true);

UserImpl user = new UserImpl("email@example.com", "user", "pwd", null);
status.setUser(user);
status.authenticate("pass");
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.icegreen.greenmail.user;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.icegreen.greenmail.imap.ImapHostManager;
import com.icegreen.greenmail.imap.ImapHostManagerImpl;
import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.pop3.Pop3Server;
import com.icegreen.greenmail.store.InMemoryStore;
import com.icegreen.greenmail.store.MailFolder;
import com.icegreen.greenmail.test.Pop3ServerTest;
import com.sun.mail.pop3.POP3Store;

import org.junit.Test;

import static org.junit.Assert.*;


public class UserManagerTest {
@Test
public void testListUsers() throws UserException {
Expand Down Expand Up @@ -68,8 +67,8 @@ public void testNoAuthRequired() {
UserManager userManager = new UserManager(imapHostManager);
userManager.setAuthRequired(false);

assertTrue(userManager.listUser().isEmpty());
assertTrue(userManager.test("foo@localhost", null));
assertEquals(1, userManager.listUser().size());
}

@Test
Expand All @@ -89,8 +88,8 @@ public void testAuthRequired() {
UserManager userManager = new UserManager(imapHostManager);
userManager.setAuthRequired(true);

assertTrue(userManager.listUser().isEmpty());
assertFalse(userManager.test("foo@localhost", null));
assertTrue(userManager.listUser().isEmpty());
}

@Test
Expand Down