def test_create(collection, mock_exists):
    user_id = User.create('myuser', 'mypassword')
    assert user_id

    assert collection.call_count == 1

    client = Client()
    coll = client.get_user_collection()
    assert coll.find_one({'username': '******'})
def test_password_is_hashed(collection, mock_exists):
    User.create('myuser', 'mypassword')

    client = Client()
    coll = client.get_user_collection()
    user = coll.find_one({'username': '******'})

    assert user['password'] != 'mypassword'.encode('utf-8'), 'password isn\'t hashed'
    assert 'mypassword'.encode('utf-8') not in user['password']
Пример #3
0
    def get(name, password):
        c = Client()
        collection = c.get_user_collection()

        result = collection.find_one({'username': name})
        u = User(result)

        if not u.check_password(password):
            raise Exception  # FIXME: User exception

        return u
Пример #4
0
    def is_authenticated(name, auth_key):
        c = Client()
        collection = c.get_user_collection()

        result = collection.find_one({'username': name})

        if result:
            keys = result.get('auth_keys', ''.encode('utf-8')).split(' '.encode('utf-8'))

            return auth_key in keys
        return False
def test_get_client(mock_client):
    try:
        mock_client.return_value = None
        os.environ['XSSNOTIFIER_CONFIG'] = 'tests/test_database.ini'
        c = Client()

        c.get_client()

        mock_client.assert_called_once_with('myhost.com', 1324)
    finally:
        del os.environ['XSSNOTIFIER_CONFIG']
Пример #6
0
    def create(name, password):
        c = Client()

        if User.exists(name):
            raise UserExists

        collection = c.get_user_collection()

        result = collection.insert_one({
            'username': name,
            'password': User.hash_password(password),
        })

        return result.inserted_id
Пример #7
0
    def authenticate(self):
        c = Client()
        collection = c.get_user_collection()

        if 'auth_keys' in self.dbrow:
            auth_keys = self.dbrow['auth_keys'] + ' '.encode('utf-8')
        else:
            auth_keys = ''.encode('utf-8')
        key = uuid.uuid4().hex.encode('utf-8')
        auth_key = hashlib.md5(key).hexdigest().encode('utf-8')
        auth_keys += auth_key

        collection.update(
            {'_id': self.dbrow['_id']},
            {'$set': {'auth_keys': auth_keys}},
        )

        return auth_key
Пример #8
0
 def exists(name):
     c = Client()
     collection = c.get_user_collection()
     return collection.find({'username': name}).count() > 0
def test_get_message_collection(mock_client):
    mock_client.return_value = MockClient()

    c = Client()

    assert c.get_message_collection() == 'm', "Didn't get correct collection"