-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41a350c
commit 4ece734
Showing
4 changed files
with
71 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
package com.icegreen.greenmail.test.commands; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.CoreMatchers.startsWith; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintStream; | ||
import java.net.Socket; | ||
|
||
import javax.mail.MessagingException; | ||
|
||
import com.icegreen.greenmail.junit.GreenMailRule; | ||
import com.icegreen.greenmail.pop3.commands.AuthCommand; | ||
import com.icegreen.greenmail.user.UserException; | ||
import com.icegreen.greenmail.util.ServerSetupTest; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.startsWith; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import com.icegreen.greenmail.junit.GreenMailRule; | ||
import com.icegreen.greenmail.pop3.commands.AuthCommand; | ||
import com.icegreen.greenmail.user.UserException; | ||
import com.icegreen.greenmail.util.ServerSetupTest; | ||
|
||
public class POP3CommandTest { | ||
private static final String CRLF = "\r\n"; | ||
|
@@ -75,4 +78,34 @@ public void authPlainWithContinuation() throws IOException, UserException { | |
} | ||
} | ||
|
||
@Test | ||
public void authDisabled() throws IOException, UserException { | ||
try (Socket socket = new Socket(hostAddress, port)) { | ||
assertThat(socket.isConnected(), is(equalTo(true))); | ||
PrintStream printStream = new PrintStream(socket.getOutputStream()); | ||
final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); | ||
|
||
greenMail.getManagers().getUserManager().setAuthRequired(false); | ||
|
||
assertThat(reader.readLine(), is(startsWith("+OK POP3 GreenMail Server v"))); | ||
printStream.print("USER [email protected]" + CRLF); | ||
assertThat(reader.readLine(), is(equalTo("+OK"))); | ||
} | ||
} | ||
|
||
@Test | ||
public void authEnabled() throws IOException, UserException { | ||
try (Socket socket = new Socket(hostAddress, port)) { | ||
assertThat(socket.isConnected(), is(equalTo(true))); | ||
PrintStream printStream = new PrintStream(socket.getOutputStream()); | ||
final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); | ||
|
||
greenMail.getManagers().getUserManager().setAuthRequired(true); | ||
|
||
assertThat(reader.readLine(), is(startsWith("+OK POP3 GreenMail Server v"))); | ||
printStream.print("USER [email protected]" + CRLF); | ||
assertThat(reader.readLine(), is(not(equalTo("+OK")))); | ||
} | ||
} | ||
|
||
} |