Example #1
0
 def test01_Init(self):
     """test01_Init
     Test initalizing pokerauthmysql"""
     db = None
     auth = pokerauth.get_auth_instance(db, self.settings)
     result, message = auth.auth("testuser", "testpassword")
     self.assertNotEquals(False, result)
    def test07_mysql11userCreate(self):
        """test07_mysql11userCreate
        Tests userCreate() as it will behave under MySQL 1.1 by mocking up
        the situation.
        """

        class MockCursor:
            def execute(self, str):
                pass

            def insert_id(self):
                return 4815

            def close(self):
                pass

        class MockDatabase:
            def cursor(self):
                return MockCursor()

        clear_all_messages()
        auth = pokerauth.get_auth_instance(MockDatabase(), self.settings)
        self.assertEquals(auth.userCreate("nobody", "nothing"), 4815)
        self.assertTrue(search_output("creating user nobody"))
        self.assertTrue(search_output("create user with serial 4815"))
Example #3
0
 def test02_AlternatePokerAuth(self):
     """test02_AlternatePokerAuth
     Test Poker auth : get_auth_instance alternate PokerAuth"""
     db = None
     settings = pokernetworkconfig.Config([])
     settings.loadFromString(settings_alternate_xml)
     auth = pokerauth.get_auth_instance(db, None, settings)
    def test08_mysqlbeyond11userCreate(self):
        """test08_mysqlbeyond11userCreate
        Tests userCreate() as it will behave under MySQL > 1.1 by mocking up
        the situation.
        """

        class MockCursor:
            def __init__(self):
                self.lastrowid = 162342

            def execute(self, str):
                pass

            def insert_id(self):
                self.failIf(1)

            def close(self):
                pass

        class MockDatabase:
            def cursor(self):
                return MockCursor()

        clear_all_messages()
        auth = pokerauth.get_auth_instance(MockDatabase(), self.settings)
        self.assertEquals(auth.userCreate("somebody", "something"), 162342)
        self.assertTrue(search_output("creating user somebody"))
        self.assertTrue(search_output("create user with serial 162342"))
Example #5
0
 def test01_Init(self):
     """test01_Init
     Test Poker auth : get_auth_instance"""
     db = None
     settings = pokernetworkconfig.Config([])
     settings.loadFromString(settings_xml)
     auth = pokerauth.get_auth_instance(db, None, settings)
 def test01_Init(self):
     """test01_Init
     Test initalizing pokerauthmysql"""
     db = None
     auth = pokerauth.get_auth_instance(db, self.settings)
     result, message = auth.auth("testuser", "testpassword")
     self.assertNotEquals(False, result)
Example #7
0
    def test08_mysqlbeyond11userCreate(self):
        """test08_mysqlbeyond11userCreate
        Tests userCreate() as it will behave under MySQL > 1.1 by mocking up
        the situation.
        """
        class MockCursor:
            def __init__(self):
                self.lastrowid = 162342

            def execute(self, str):
                pass

            def insert_id(self):
                self.failIf(1)

            def close(self):
                pass

        class MockDatabase:
            def cursor(self):
                return MockCursor()

        clear_all_messages()
        auth = pokerauth.get_auth_instance(MockDatabase(), self.settings)
        self.assertEquals(auth.userCreate("somebody", "something"), 162342)
        self.assertTrue(search_output('creating user somebody'))
        self.assertTrue(search_output('create user with serial 162342'))
Example #8
0
 def test01_Init(self):
     """test01_Init
     Test Poker auth : get_auth_instance"""
     db = None
     settings = pokernetworkconfig.Config([])
     settings.doc = libxml2.parseMemory(settings_xml, len(settings_xml))
     settings.header = settings.doc.xpathNewContext()
     auth = pokerauth.get_auth_instance(db, settings)
 def test01_Init(self):
     """test01_Init
     Test Poker auth : get_auth_instance"""
     db = None
     settings = pokernetworkconfig.Config([])
     settings.doc = libxml2.parseMemory(settings_xml, len(settings_xml))
     settings.header = settings.doc.xpathNewContext()
     auth = pokerauth.get_auth_instance(db, settings)
 def test02_AlternatePokerAuth(self):
     """test02_AlternatePokerAuth
     Test Poker auth : get_auth_instance alternate PokerAuth"""
     db = None
     settings = pokernetworkconfig.Config([])
     settings.doc = libxml2.parseMemory(settings_alternate_xml, len(settings_alternate_xml))
     settings.header = settings.doc.xpathNewContext()
     auth = pokerauth.get_auth_instance(db, settings)
     self.failUnless(hasattr(auth, "gotcha"))
Example #11
0
 def test02_AlternatePokerAuth(self):
     """test02_AlternatePokerAuth
     Test Poker auth : get_auth_instance alternate PokerAuth"""
     db = None
     settings = pokernetworkconfig.Config([])
     settings.doc = libxml2.parseMemory(settings_alternate_xml,
                                        len(settings_alternate_xml))
     settings.header = settings.doc.xpathNewContext()
     auth = pokerauth.get_auth_instance(db, settings)
     self.failUnless(hasattr(auth, 'gotcha'))
    def test09_setAndGetLevel(self):
        """test09_setAndGetLevel
        Tests the SetLevel and GetLevel methods.
        """
        auth = pokerauth.get_auth_instance(self.db, self.settings)

        self.assertEquals(auth.GetLevel("first"), False)
        self.assertEquals(auth.SetLevel("first", 7), None)
        self.assertEquals(auth.GetLevel("first"), 7)
        self.assertEquals(auth.GetLevel("second"), False)
Example #13
0
    def test04_authWithoutAutoCreate(self, expectedMessage = 'user does not exist.  name: john_smith'):
        """test04_authWithoutAutoCreate
        Test Poker auth : Try basic auth with autocreate on"""
        auth = pokerauth.get_auth_instance(self.db, None, self.settings)


        self.assertEquals(auth.auth(PACKET_LOGIN,('john_smith', 'blah')), (False, 'Invalid login or password'))
        if expectedMessage:
            self.assertEquals(log_history.get_all()[-1], expectedMessage)
        self.failUnless(len(self.checkIfUserExistsInDB('john_smith')) == 0)
Example #14
0
    def test09_setAndGetLevel(self):
        """test09_setAndGetLevel
        Tests the SetLevel and GetLevel methods.
        """
        auth = pokerauth.get_auth_instance(self.db, self.settings)

        self.assertEquals(auth.GetLevel('first'), False)
        self.assertEquals(auth.SetLevel('first', 7), None)
        self.assertEquals(auth.GetLevel('first'), 7)
        self.assertEquals(auth.GetLevel('second'), False)
    def test04_authWithoutAutoCreate(self, expectedMessage="user john_smith does not exist"):
        """test04_authWithoutAutoCreate
        Test Poker auth : Try basic auth with autocreate on"""
        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()

        self.assertEquals(auth.auth("john_smith", "blah"), (False, "Invalid login or password"))
        if expectedMessage:
            self.assertTrue(search_output(expectedMessage))
        self.failUnless(len(self.checkIfUserExistsInDB("john_smith")) == 0)
Example #16
0
    def test03_authWithAutoCreate(self):
        """test03_authWithAutoCreate
        Test Poker auth : Try basic auth with autocreate on"""
        db = self.db
        settings = pokernetworkconfig.Config([])
        autocreate_xml = settings_xml.replace('<server auto_create_account="no" ', '<server auto_create_account="yes" ')
        settings.doc = libxml2.parseMemory(autocreate_xml, len(autocreate_xml))
        settings.header = settings.doc.xpathNewContext()
        auth = pokerauth.get_auth_instance(db, None, settings)

        self.assertEquals(auth.auth(PACKET_LOGIN,('joe_schmoe', 'foo')), ((4, 'joe_schmoe', 1), None))
        self.assertEquals(log_history.get_all()[-1], 'created user.  serial: 4, name: joe_schmoe')
        self.failUnless(len(self.checkIfUserExistsInDB('joe_schmoe')) == 1)
Example #17
0
    def test04_authWithoutAutoCreate(
            self, expectedMessage='user john_smith does not exist'):
        """test04_authWithoutAutoCreate
        Test Poker auth : Try basic auth with autocreate on"""
        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()

        self.assertEquals(auth.auth('john_smith', 'blah'),
                          (False, 'Invalid login or password'))
        if expectedMessage:
            self.assertTrue(search_output(expectedMessage))
        self.failUnless(len(self.checkIfUserExistsInDB('john_smith')) == 0)
Example #18
0
    def test08_mysqlbeyond11userCreate(self):
        """test08_mysqlbeyond11userCreate
        Tests userCreate() as it will behave under MySQL > 1.1 by mocking up
        the situation.
        """
        class MockCursor:
            def __init__(self):
                self.lastrowid = 162342
            def execute(self, *a): pass
            def close(self): pass
        class MockDatabase:
            def cursor(self): return MockCursor()

        auth = pokerauth.get_auth_instance(MockDatabase(), None, self.settings)
        self.assertEquals(auth.userCreate("somebody", "something"), 162342)
        self.assertEquals(log_history.get_all()[-1], 'created user.  serial: 162342, name: somebody')
    def test05_authWhenDoubleEntry(self):
        """test05_authWhenDoubleEntry
        Tests case in fallback authentication where more than one entry exists.
        """
        cursor = self.db.cursor()
        for ii in [1,2]:
            cursor.execute(
                "INSERT INTO "+self.parameters["table"]+" (username, password, privilege) values (%s, %s, %s)",
                ('doyle_brunson', 'foo', User.REGULAR)
            )
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, None, self.settings)
        
        log_history.reset()
        self.assertEquals(auth.auth(PACKET_LOGIN,('doyle_brunson', 'foo')), (False, "Invalid login or password"))
        self.assertEquals(log_history.get_all(), ['more than one row for doyle_brunson'])
 def test07_mysql11userCreate(self):
     """test07_mysql11userCreate
     Tests userCreate() as it will behave under MySQL 1.1 by mocking up
     the situation.
     """
     class MockCursor:
         def __init__(self):
             self.lastrowid = 4815
         def execute(self, *a): pass
         def close(self): pass
     class MockDatabase:
         def cursor(self): return MockCursor()
         
     auth = pokerauth.get_auth_instance(MockDatabase(), None, self.settings)
     self.assertEquals(auth.userCreate("nobody", "nothing"), 4815)
     self.assertTrue(log_history.search('creating user nobody'))
     self.assertTrue(log_history.search('create user with serial 4815'))
    def test03_authWithAutoCreate(self):
        """test03_authWithAutoCreate
        Test Poker auth : Try basic auth with autocreate on"""
        db = self.db
        settings = pokernetworkconfig.Config([])
        autocreate_xml = settings_xml.replace('<server auto_create_account="no" ', "<server ")
        settings.doc = libxml2.parseMemory(autocreate_xml, len(autocreate_xml))
        settings.header = settings.doc.xpathNewContext()
        auth = pokerauth.get_auth_instance(db, settings)

        clear_all_messages()
        self.assertEquals(auth.auth("joe_schmoe", "foo"), ((4, "joe_schmoe", 1), None))
        self.assertEquals(
            get_messages(),
            ["user joe_schmoe does not exist, create it", "creating user joe_schmoe", "create user with serial 4"],
        )
        self.failUnless(len(self.checkIfUserExistsInDB("joe_schmoe")) == 1)
    def test05_authWhenDoubleEntry(self):
        """test05_authWhenDoubleEntry
        Tests case in fallback authentication where more than one entry exists.
        """
        cursor = self.db.cursor()
        for ii in [1, 2]:
            cursor.execute(
                "INSERT INTO %s (username, password, privilege) values ('%s', '%s', %i)"
                % (self.parameters["table"], "doyle_brunson", "foo", User.REGULAR)
            )
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth("doyle_brunson", "foo"), (False, "Invalid login or password"))
        self.assertEquals(get_messages(), [])
Example #23
0
    def test05_authWhenDoubleEntry(self):
        """test05_authWhenDoubleEntry
        Tests case in fallback authentication where more than one entry exists.
        """
        cursor = self.db.cursor()
        for ii in [1, 2]:
            cursor.execute(
                "INSERT INTO %s (username, password, privilege) values ('%s', '%s', %i)"
                % (self.parameters["table"], 'doyle_brunson', 'foo',
                   User.REGULAR))
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth('doyle_brunson', 'foo'),
                          (False, "Invalid login or password"))
        self.assertEquals(get_messages(), [])
Example #24
0
    def test05_authWhenDoubleEntry(self):
        """test05_authWhenDoubleEntry
        Tests case in fallback authentication where more than one entry exists.
        """
        cursor = self.db.cursor()
        cursor.execute("DROP TABLE users")
        cursor.execute("""CREATE TABLE users (
 	    serial int unsigned not null auto_increment,
	    name varchar(32), password varchar(32), privilege int default 1,
            primary key (serial))""")
        for ii in [1,2]:
            cursor.execute("INSERT INTO users (name, password) values (%s, %s)", ('doyle_brunson', 'foo'))
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, None, self.settings)
        
        log_history.reset()
        self.assertEquals(auth.auth(PACKET_LOGIN,('doyle_brunson', 'foo')), (False, "Invalid login or password"))
        self.assertEquals(log_history.get_all(), ['multiple entries for user in database.  name: doyle_brunson'])
Example #25
0
    def test03_authWithAutoCreate(self):
        """test03_authWithAutoCreate
        Test Poker auth : Try basic auth with autocreate on"""
        db = self.db
        settings = pokernetworkconfig.Config([])
        autocreate_xml = settings_xml.replace(
            '<server auto_create_account="no" ', '<server ')
        settings.doc = libxml2.parseMemory(autocreate_xml, len(autocreate_xml))
        settings.header = settings.doc.xpathNewContext()
        auth = pokerauth.get_auth_instance(db, settings)

        clear_all_messages()
        self.assertEquals(auth.auth('joe_schmoe', 'foo'),
                          ((4, 'joe_schmoe', 1), None))
        self.assertEquals(get_messages(), [
            'user joe_schmoe does not exist, create it',
            'creating user joe_schmoe', 'create user with serial 4'
        ])
        self.failUnless(len(self.checkIfUserExistsInDB('joe_schmoe')) == 1)
    def test06_validAuthWhenEntryExists(self):
        """test06_validAuthWhenEntryExists
        Tests case for single-row returned existing auth, both success and failure.
        """
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO users (created, name, password) values (%d, '%s', '%s')" % (seconds(), "dan_harrington", "bar")
        )
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth("dan_harrington", "bar"), ((4L, "dan_harrington", 1L), None))
        self.assertEquals(get_messages(), [])

        clear_all_messages()
        self.assertEquals(auth.auth("dan_harrington", "wrongpass"), (False, "Invalid login or password"))
        self.assertEquals(get_messages(), ["password mismatch for dan_harrington"])
    def test06_validAuthWhenEntryExists(self):
        """test06_validAuthWhenEntryExists
        Tests case for single-row returned existing auth, both success and failure.
        """
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO %s (username, password, privilege) values ('%s', '%s', %i)"
            % (self.parameters["table"], "dan_harrington", "bar", User.REGULAR)
        )
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth("dan_harrington", "bar"), (("dan_harrington", "dan_harrington", 1L), None))
        self.assertEquals(get_messages(), [])

        clear_all_messages()
        self.assertEquals(auth.auth("dan_harrington", "wrongpass"), (False, "Invalid login or password"))
        self.assertEquals(get_messages(), [])
    def test06_validAuthWhenEntryExists(self):
        """test06_validAuthWhenEntryExists
        Tests case for single-row returned existing auth, both success and failure.
        """
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO "+self.parameters["table"]+" (username, password, privilege) values (%s, %s, %s)",
            ('dan_harrington', 'bar', User.REGULAR)
        )
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, None, self.settings)

        log_history.reset()
        self.assertEquals(auth.auth(PACKET_LOGIN,('dan_harrington', 'bar')), (('dan_harrington', 'dan_harrington', 1L), None))
        self.assertEquals(log_history.get_all(), [])
        
        log_history.reset()
        self.assertEquals(auth.auth(PACKET_LOGIN,('dan_harrington', 'wrongpass')), (False, 'Invalid login or password'))
        self.assertEquals(log_history.get_all(), ['password mismatch for dan_harrington'])
Example #29
0
    def test06_validAuthWhenEntryExists(self):
        """test06_validAuthWhenEntryExists
        Tests case for single-row returned existing auth, both success and failure.
        """
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO users (created, name, password) values (%s, %s, %s)",
            (seconds(), 'dan_harrington', 'bar')
        )
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, None, self.settings)

        log_history.reset()
        self.assertEquals(auth.auth(PACKET_LOGIN,('dan_harrington', 'bar')), ((4L, 'dan_harrington', 1L), None))
        self.assertEquals(log_history.get_all(), [])
        
        log_history.reset()
        self.assertEquals(auth.auth(PACKET_LOGIN,('dan_harrington', 'wrongpass')), (False, 'Invalid login or password'))
        self.assertEquals(log_history.get_all(), ['invalid password in login attempt.  name: dan_harrington, serial: 4'])
    def test05_authWhenDoubleEntry(self):
        """test05_authWhenDoubleEntry
        Tests case in fallback authentication where more than one entry exists.
        """
        cursor = self.db.cursor()
        cursor.execute("DROP TABLE users")
        cursor.execute(
            """CREATE TABLE users (
 	    serial int unsigned not null auto_increment,
	    name varchar(32), password varchar(32), privilege int default 1,
            primary key (serial))"""
        )
        for ii in [1, 2]:
            cursor.execute("INSERT INTO users (name, password) values ('%s', '%s')" % ("doyle_brunson", "foo"))
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth("doyle_brunson", "foo"), (False, "Invalid login or password"))
        self.assertEquals(get_messages(), ["*ERROR* more than one row for doyle_brunson"])
Example #31
0
    def test06_validAuthWhenEntryExists(self):
        """test06_validAuthWhenEntryExists
        Tests case for single-row returned existing auth, both success and failure.
        """
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO users (created, name, password) values (%d, '%s', '%s')"
            % (seconds(), 'dan_harrington', 'bar'))
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth('dan_harrington', 'bar'),
                          ((4L, 'dan_harrington', 1L), None))
        self.assertEquals(get_messages(), [])

        clear_all_messages()
        self.assertEquals(auth.auth('dan_harrington', 'wrongpass'),
                          (False, 'Invalid login or password'))
        self.assertEquals(get_messages(),
                          ['password mismatch for dan_harrington'])
Example #32
0
    def test06_validAuthWhenEntryExists(self):
        """test06_validAuthWhenEntryExists
        Tests case for single-row returned existing auth, both success and failure.
        """
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO %s (username, password, privilege) values ('%s', '%s', %i)"
            %
            (self.parameters["table"], 'dan_harrington', 'bar', User.REGULAR))
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth('dan_harrington', 'bar'),
                          (('dan_harrington', 'dan_harrington', 1L), None))
        self.assertEquals(get_messages(), [])

        clear_all_messages()
        self.assertEquals(auth.auth('dan_harrington', 'wrongpass'),
                          (False, 'Invalid login or password'))
        self.assertEquals(get_messages(), [])
Example #33
0
    def test05_authWhenDoubleEntry(self):
        """test05_authWhenDoubleEntry
        Tests case in fallback authentication where more than one entry exists.
        """
        cursor = self.db.cursor()
        cursor.execute("DROP TABLE users")
        cursor.execute("""CREATE TABLE users (
 	    serial int unsigned not null auto_increment,
	    name varchar(32), password varchar(32), privilege int default 1,
            primary key (serial))""")
        for ii in [1, 2]:
            cursor.execute(
                "INSERT INTO users (name, password) values ('%s', '%s')" %
                ('doyle_brunson', 'foo'))
        cursor.close()

        auth = pokerauth.get_auth_instance(self.db, self.settings)

        clear_all_messages()
        self.assertEquals(auth.auth('doyle_brunson', 'foo'),
                          (False, "Invalid login or password"))
        self.assertEquals(get_messages(),
                          ['*ERROR* more than one row for doyle_brunson'])
Example #34
0
    def test07_mysql11userCreate(self):
        """test07_mysql11userCreate
        Tests userCreate() as it will behave under MySQL 1.1 by mocking up
        the situation.
        """
        class MockCursor:
            def execute(self, str):
                pass

            def insert_id(self):
                return 4815

            def close(self):
                pass

        class MockDatabase:
            def cursor(self):
                return MockCursor()

        clear_all_messages()
        auth = pokerauth.get_auth_instance(MockDatabase(), self.settings)
        self.assertEquals(auth.userCreate("nobody", "nothing"), 4815)
        self.assertTrue(search_output('creating user nobody'))
        self.assertTrue(search_output('create user with serial 4815'))