Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoten committed Jan 16, 2025
1 parent 8bac27e commit 8db2f97
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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 test() throws RejectException {
MessageContext context = Mockito.mock(MessageContext.class);
UsernamePasswordValidator validator = (username, password, c) -> {
if (!username.equals("fred") || !password.equals("blah")) {
throw new LoginFailedException();
}
};
AuthenticationHandler auth = new PlainAuthenticationHandlerFactory(validator).create();
try {
auth.auth("AUTH PLAIN b", context);
Assert.fail();
} catch (RejectException e) {
assertEquals("Invalid command argument, not a valid Base64 string", e.getMessage());
}
}

}
1 change: 1 addition & 0 deletions src/test/java/org/subethamail/smtp/command/AuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,5 @@ public void testBadPass() throws Exception {
send("bad-password");
expect("501");
}

}

0 comments on commit 8db2f97

Please sign in to comment.