FileDocCategorySizeDatePackage
TestBlowfishAuthenticationController.javaAPI DocApache Lucene 2.1.04157Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.server.authentication

TestBlowfishAuthenticationController

public class TestBlowfishAuthenticationController extends TestCase
author
Simon Willnauer

Fields Summary
private BlowfishAuthenticationController
controller
private String
key
private String
accountName
private String
clientIp
Constructors Summary
Methods Summary
protected voidsetUp()

         
        this.controller = new BlowfishAuthenticationController();
        this.controller.setKey(this.key);
        
        this.controller.initialize();
    
protected voidtearDown()

        super.tearDown();
    
public voidtestAuthenticatAccount()

        GDataAccount account = new GDataAccount();
        account.setName(accountName);
        account.setPassword("testme");
        account.setRole(AccountRole.ENTRYAMINISTRATOR);
        
        String token = this.controller.authenticatAccount(account,this.clientIp);
        String notSame = this.controller.calculateAuthToken("192.168.0",Integer.toString(account.getRolesAsInt()),this.accountName);
        assertNotSame(notSame,token);
        String authString = "192.168.0#"+this.accountName +"#"+account.getRolesAsInt()+"#";
        assertTrue(this.controller.deCryptAuthToken(token).startsWith(authString));
        assertTrue(this.controller.deCryptAuthToken(notSame).startsWith(authString));
    
public voidtestAuthenticateToken()

        GDataAccount account = new GDataAccount();
        account.setName("simon");
        account.setPassword("testme");
        account.setRole(AccountRole.ENTRYAMINISTRATOR);
        String token = this.controller.calculateAuthToken("192.168.0",Integer.toString(account.getRolesAsInt()),this.accountName);
        
        assertTrue(this.controller.authenticateToken(token,this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName));
        assertTrue(this.controller.authenticateToken(token,this.clientIp,AccountRole.USER,this.accountName));
        assertFalse(this.controller.authenticateToken(token,this.clientIp,AccountRole.USERADMINISTRATOR,"someOtherAccount"));
        try{
        this.controller.authenticateToken(token+"test",this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName);
        fail("exception expected");
        }catch (Exception e) {
            // TODO: handle exception
        }
        this.controller.setLoginTimeout(0);
        assertFalse(this.controller.authenticateToken(token,this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName));