forked from bigjosh/subethasmtp
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix PlainAuthenticationHandlerFactory base64 decode behaviour (#143)
- Loading branch information
1 parent
8f00b1c
commit 25ed5c9
Showing
2 changed files
with
40 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
src/test/java/org/subethamail/smtp/PlainAuthenticationHandlerFactoryTest.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,31 @@ | ||
package org.subethamail.smtp; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.subethamail.smtp.auth.LoginFailedException; | ||
import org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory; | ||
import org.subethamail.smtp.auth.UsernamePasswordValidator; | ||
|
||
public class PlainAuthenticationHandlerFactoryTest { | ||
|
||
@Test | ||
public void testBadBase64String() throws RejectException { | ||
UsernamePasswordValidator validator = (username, password, c) -> { | ||
if (!username.equals("fred") || !password.equals("blah")) { | ||
throw new LoginFailedException(); | ||
} | ||
}; | ||
AuthenticationHandler auth = new PlainAuthenticationHandlerFactory(validator).create(); | ||
MessageContext context = Mockito.mock(MessageContext.class); | ||
try { | ||
auth.auth("AUTH PLAIN b", context); | ||
Assert.fail(); | ||
} catch (RejectException e) { | ||
assertEquals("Invalid command argument, not a valid Base64 string", e.getMessage()); | ||
} | ||
} | ||
|
||
} |