def setUp(self):
     eve_settings = {
         'BCRYPT_LOG_ROUNDS': 6,
         'BCRYPT_HASH_IDENT': '2b',
         'BCRYPT_HANDLE_LONG_PASSWORDS': False,
         'DOMAIN': {}
     }
     eve_app = Eve(settings=eve_settings)
     self.eve_bcrypt = Bcrypt(eve_app)
Beispiel #2
0
def create_app():
    app = Sanic(__name__)
    # Limiter(app, global_limits=['60 per minute'], key_func=get_remote_address)
    register_tortoise(app, generate_schemas=False, config=DBconfig)
    bcrypt = Bcrypt(app)
    # CORS(app, automatic_options=True)
    return app
class EveLongPasswordsTestCase(EveBasicTestCase):
    def setUp(self):
        eve_app = Quart(__name__)
        eve_app.config['BCRYPT_LOG_ROUNDS'] = 6
        eve_app.config['BCRYPT_HASH_IDENT'] = '2b'
        eve_app.config['BCRYPT_HANDLE_LONG_PASSWORDS'] = True
        self.eve_bcrypt = Bcrypt(eve_app)

    def test_long_password(self):
        """Test the work around bcrypt maximum password length."""

        # Create a password with a 72 bytes length
        password = '******' * 72
        pw_hash = self.eve_bcrypt.generate_password_hash(password)
        # Ensure that a longer password **do not** yield the same hash
        self.assertFalse(self.eve_bcrypt.check_password_hash(
            pw_hash, 'A' * 80))
Beispiel #4
0
def create_app():
    app = Sanic(__name__)
    app: asyncio_redis.Pool
    app.blueprint(api)
    bcrypt = Bcrypt(app)
    register_tortoise(app, generate_schemas=False, config=postgres.config)
    CORS(app, automatic_options=True)
    # setup_cors(app)
    return app
from motor.motor_asyncio import AsyncIOMotorClient
from sanic import Sanic
from sanic_cors import CORS
from simple_bcrypt import Bcrypt
from .config import AppConfig
from .auth import auth_bp

app = Sanic(__name__)
bcrypt = Bcrypt(app)
CORS(app)

app.config.from_object(AppConfig)
db = None


@app.listener('before_server_start')
def initializer(sanic, loop):
    global db
    # from motor.motor_asyncio import AsyncIOMotorClient
    from pymongo import MongoClient
    mongo_uri = app.config.get('SECRET')
    db_name = app.config.get('DB_NAME')

    # db = MongoClient(mongo_uri).test_mongo_ishmam
    db = AsyncIOMotorClient(mongo_uri).test_mongo_ishmam


app.blueprint(auth_bp)


Beispiel #6
0
# Configs
from config import config

# Domain Applications
from app.domain.user import init_user_app
from app.domain.messaging import init_messaging_app

# Html application
from app.http import init_http_app

# Orm database
db = Gino()

# Bcrypt
bcrypt = Bcrypt()

# Jinja template library
jinja = SanicJinja2()


def create_app(config_name=None):
    """
    Create sanic application
    """
    if config_name is None:
        config_name = os.environ.get('SANIC_APP_CONFIG', 'development')

    # Get configuration object
    config_object = config[config_name]
class FlaskBasicTestCase(unittest.TestCase):
    def setUp(self):
        flask_app = Flask(__name__)
        flask_app.config['BCRYPT_LOG_ROUNDS'] = 6
        flask_app.config['BCRYPT_HASH_IDENT'] = '2b'
        flask_app.config['BCRYPT_HANDLE_LONG_PASSWORDS'] = False
        self.flask_bcrypt = Bcrypt(flask_app)

    def test_is_string(self):
        pw_hash = self.flask_bcrypt.generate_password_hash('secret')
        self.assertTrue(isinstance(pw_hash, bytes))

    def test_custom_rounds(self):
        password = '******'
        pw_hash1 = self.flask_bcrypt.generate_password_hash(password, 5)
        self.assertNotEqual(password, pw_hash1)

    def test_check_hash(self):
        pw_hash = self.flask_bcrypt.generate_password_hash('secret')
        # check a correct password
        self.assertTrue(
            self.flask_bcrypt.check_password_hash(pw_hash, 'secret'))
        # check an incorrect password
        self.assertFalse(
            self.flask_bcrypt.check_password_hash(pw_hash, 'hunter2'))
        # check unicode
        pw_hash = self.flask_bcrypt.generate_password_hash('\u2603')
        self.assertTrue(
            self.flask_bcrypt.check_password_hash(pw_hash, '\u2603'))
        # check helpers
        pw_hash = generate_password_hash('hunter2')
        self.assertTrue(check_password_hash(pw_hash, 'hunter2'))

    def test_check_hash_unicode_is_utf8(self):
        password = '******'
        pw_hash = self.flask_bcrypt.generate_password_hash(password)
        # check a correct password
        self.assertTrue(
            self.flask_bcrypt.check_password_hash(pw_hash, b'\xe2\x98\x83'))

    def test_rounds_set(self):
        self.assertEqual(self.flask_bcrypt._log_rounds, 6)

    def test_unicode_hash(self):
        password = '******'
        h = generate_password_hash(password).decode('utf-8')
        self.assertTrue(check_password_hash(h, password))

    def test_long_password(self):
        """Test bcrypt maximum password length.

        The bcrypt algorithm has a maximum password length of 72 bytes, and
        ignores any bytes beyond that."""

        # Create a password with a 72 bytes length
        password = '******' * 72
        pw_hash = self.flask_bcrypt.generate_password_hash(password)
        # Ensure that a longer password yields the same hash
        self.assertTrue(
            self.flask_bcrypt.check_password_hash(pw_hash, 'A' * 80))
 def setUp(self):
     sanic_app = Sanic(__name__)
     sanic_app.config['BCRYPT_LOG_ROUNDS'] = 6
     sanic_app.config['BCRYPT_HASH_IDENT'] = '2b'
     sanic_app.config['BCRYPT_HANDLE_LONG_PASSWORDS'] = False
     self.sanic_bcrypt = Bcrypt(sanic_app)
 def setUp(self):
     eve_app = Quart(__name__)
     eve_app.config['BCRYPT_LOG_ROUNDS'] = 6
     eve_app.config['BCRYPT_HASH_IDENT'] = '2b'
     eve_app.config['BCRYPT_HANDLE_LONG_PASSWORDS'] = True
     self.eve_bcrypt = Bcrypt(eve_app)
 def setUp(self):
     quart_app = Quart(__name__)
     quart_app.config['BCRYPT_LOG_ROUNDS'] = 6
     quart_app.config['BCRYPT_HASH_IDENT'] = '2b'
     quart_app.config['BCRYPT_HANDLE_LONG_PASSWORDS'] = True
     self.quart_bcrypt = Bcrypt(quart_app)
 def setUp(self):
     flask_app = Flask(__name__)
     flask_app.config['BCRYPT_LOG_ROUNDS'] = 6
     flask_app.config['BCRYPT_HASH_IDENT'] = '2b'
     flask_app.config['BCRYPT_HANDLE_LONG_PASSWORDS'] = True
     self.flask_bcrypt = Bcrypt(flask_app)