1 package org.columba.ristretto.auth.mechanism; 2 3 import java.io.IOException ; 4 5 import junit.framework.TestCase; 6 7 import org.columba.ristretto.auth.AuthenticationException; 8 import org.columba.ristretto.auth.AuthenticationMechanism; 9 10 public class CramMD5MechanismTest extends TestCase { 11 12 public void testOK() throws IOException { 13 TestAuthServer server = new TestAuthServer(); 14 server.addResponse("<1896.697170952@postoffice.reston.mci.net>".getBytes()); 15 server.addCall("tim b913a602c7eda7a495b4e6e7334d3890".getBytes()); 16 AuthenticationMechanism mechanism = new CramMD5Mechanism(); 17 18 try { 19 mechanism.authenticate(server,"tim","tanstaaftanstaaf".toCharArray()); 20 } catch (AuthenticationException e) { 21 e.printStackTrace(); 22 } 23 24 assertTrue( server.isOk()); 25 } 26 27 public void testFailure() throws IOException { 28 TestAuthServer server = new TestAuthServer(); 29 server.addCall("tim".getBytes()); 30 server.addCall("oo".getBytes()); 31 AuthenticationMechanism mechanism = new CramMD5Mechanism(); 32 33 try { 34 mechanism.authenticate(server,"tim", "foo".toCharArray()); 35 } catch (AuthenticationException e) { 36 e.printStackTrace(); 37 } 38 39 assertFalse( server.isOk()); 40 } 41 42 43 } 44 | Popular Tags |