Exemplo n.º 1
0
def _insert_user():
    """Insert starting default entries into the User table.

    Args:
        None

    Returns:
        None

    """
    # Insert into User
    if user.idx_exists(1) is False:
        password = ''.join(
            random.SystemRandom().choice(string.ascii_uppercase +
                                         string.digits) for _ in range(50))
        user.insert_row(
            DbRowUser(username='******',
                      password=data.hashstring(password),
                      first_name='pattoo',
                      last_name='pattoo',
                      user_type=1,
                      change_password=1,
                      enabled=0))

    # Insert admin into User table
    if user.idx_exists(2) is False:
        password = '******'
        user.insert_row(
            DbRowUser(username='******',
                      password=data.hashstring(password),
                      first_name='admin',
                      last_name='admin',
                      user_type=0,
                      change_password=0,
                      enabled=1))
Exemplo n.º 2
0
def _insert_user():
    """Insert starting default entries into the User table.

    Args:
        None

    Returns:
        default_users: dictionary containing the default user credentials

    """
    default_users = []

    # Insert into User
    if user.idx_exists(1) is False:

        # Creating initial password
        password = data.hashstring(''.join(random.SystemRandom().choice(
            string.ascii_uppercase + string.digits) for _ in range(50)))

        # Inserting default user
        user.insert_row(
            DbRowUser(
                username='******',
                password=password,
                first_name='pattoo',
                last_name='pattoo',
                role=1,
                password_expired=1,
                enabled=0)
            )
        default_users.append(('pattoo', password, 1))

    # Insert admin into User table
    if user.idx_exists(2) is False:
        # Creating initial password
        password = data.hashstring(''.join(random.SystemRandom().choice(
            string.ascii_uppercase + string.digits) for _ in range(50)))
        user.insert_row(
            DbRowUser(
                username='******',
                password=password,
                first_name='admin',
                last_name='admin',
                role=0,
                password_expired=1,
                enabled=1)
            )
        default_users.append(('admin', password, 0))

    return default_users
Exemplo n.º 3
0
    def test_idx_exists(self):
        """Testing method or function named "idx_exists"."""
        # Add entry to database
        uname = data.hashstring(str(random()))
        passwrd = data.hashstring(str(random()))
        f_name = data.hashstring(str(random()))
        l_name = data.hashstring(str(random()))
        user.insert_row(
            DbRowUser(
                username=uname,
                password=passwrd,
                first_name=f_name,
                last_name=l_name,
                role=1,
                password_expired=1,
                enabled=0
            )
        )

        # Make sure it exists
        idx_user = user.exists(uname)

        # Verify that the index exists
        result = user.idx_exists(idx_user)
        self.assertTrue(result)
Exemplo n.º 4
0
    def test__insert_user(self):
        """Testing method or function named "_insert_user"."""
        _insert_user()
        # Make sure user exists
        idx_user = user.exists('pattoo')
        self.assertEqual(idx_user, 1)

        # Check if index exists
        result = user.idx_exists(1)
        self.assertTrue(result)
Exemplo n.º 5
0
    def test_insert_row(self):
        """Testing method or function named "insert_row"."""
        # Add an entry to the database
        uname = data.hashstring(str(random()))
        password = data.hashstring(str(random()))
        expected = DbRowUser(
            username=uname,
            password=password,
            first_name=data.hashstring(str(random())),
            last_name=data.hashstring(str(random())),
            role=1,
            password_expired=1,
            enabled=0
        )
        user.insert_row(expected)

        # Make sure it exists
        idx_user = user.exists(uname)

        # Verify the index exists
        result = user.idx_exists(idx_user)
        self.assertTrue(result)

        # Verify that all the parameters match
        with db.db_query(20091) as session:
            row = session.query(
                User).filter(User.username == uname.encode()).one()

        self.assertEqual(expected.username, row.username.decode())
        self.assertEqual(expected.first_name, row.first_name.decode())
        self.assertEqual(expected.last_name, row.last_name.decode())
        self.assertEqual(expected.role, row.role)
        self.assertEqual(expected.password_expired, row.password_expired)
        self.assertEqual(expected.enabled, row.enabled)

        # Test password
        salt = row.password.decode().split('$')[2]
        password_hash = crypt.crypt(password, '$6${}'.format(salt))
        self.assertEqual(row.password.decode(), password_hash)