Package com.pugh.sockso.auth

Source Code of com.pugh.sockso.auth.DBAuthenticatorTest

package com.pugh.sockso.auth;

import com.pugh.sockso.tests.TestDatabase;
import com.pugh.sockso.tests.SocksoTestCase;
import com.pugh.sockso.web.User;

public class DBAuthenticatorTest extends SocksoTestCase {

    private Authenticator auth;

    private TestDatabase db;

    @Override
    public void setUp() throws Exception {
        db = new TestDatabase();
        auth = new DBAuthenticator( db );
        db.fixture( "singleUser" );
    }

    public void testAuthenticatingAValidUser() throws Exception {
        assertTrue( auth.authenticate("foo","q") );
    }

    public void testAuthFailsWhenValidUserAndInvalidPassword() throws Exception {
        assertFalse( auth.authenticate("foo","WRONG") );
    }

    public void testAuthFailsWhenUserDoesntExist() throws Exception {
        assertFalse( auth.authenticate("baz","q") );
    }

    public void testAuthFailsWhenTheUserIsNotActive() throws Exception {
        User user = new User( -1, "fooaaaaaa", "bar", "foosss@bar.com" );
        user.setActive( false );
        user.save( db );
        assertFalse( auth.authenticate(user.getName(),"bar") );
    }

}
TOP

Related Classes of com.pugh.sockso.auth.DBAuthenticatorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.