コード例 #1
0
 def test_fail_to_init_feature_if_jwt_secret_not_set(self):
     """ Fail to initialize user feature without JWT secret"""
     config = DefaultConfig()
     config.USER_JWT_SECRET = None
     app = bootstrap.create_app(__name__, config=config)
     with self.assertRaises(x.JwtSecretMissing):
         user_feature(app)
コード例 #2
0
    def test_raise_when_failing_to_import_custom_token_loader(self):
        """ Raising exception if custom token loader fails to import"""
        class CustomConfig(DefaultConfig, UserConfig):
            USER_JWT_SECRET = 'SuperSecret'
            USER_JWT_LOADER_IMPLEMENTATION = 'nonexistent.nonexistent'

        cfg = CustomConfig()
        app = bootstrap.create_app(__name__, config=cfg)
        user_feature(app)
        with self.assertRaises(x.ConfigurationException):
            user_service.get_user_by_token(123)
コード例 #3
0
    def test_can_use_custom_token_loader(self):
        """ Can register and use custom token user loader"""
        loader = 'tests.user_service_test.custom_token_loader'

        class CustomConfig(DefaultConfig, UserConfig):
            USER_JWT_SECRET = 'SuperSecret'
            USER_JWT_IMPLEMENTATION = None
            USER_JWT_LOADER_IMPLEMENTATION = loader

        cfg = CustomConfig()
        app = bootstrap.create_app(__name__, config=cfg)
        user_feature(app)
        loaded = user_service.get_user_by_token(123)
        expected = custom_token_loader(123)
        self.assertEquals(expected, loaded)
コード例 #4
0
    def test_can_use_custom_token_implementation(self):
        """ Can register and use custom token implementation"""
        token = 'tests.user_service_test.custom_token_implementation'

        class CustomConfig(DefaultConfig, UserConfig):
            USER_JWT_SECRET = 'SuperSecret'
            USER_JWT_LIFETIME_SECONDS = 10
            USER_JWT_IMPLEMENTATION = token

        cfg = CustomConfig()
        app = bootstrap.create_app(__name__, config=cfg)
        user_feature(app)
        user_id = 123
        token = user_service.get_token(user_id)
        expected = custom_token_implementation(user_id)
        self.assertEquals(expected, token)
コード例 #5
0
    def test_user_service_receives_config_options(self):
        """ Initializing user service with config options """
        class CustomConfig(DefaultConfig, UserConfig):
            USER_JWT_SECRET = '123'
            USER_PUBLIC_PROFILES = False
            USER_ACCOUNTS_REQUIRE_CONFIRMATION = False
            USER_SEND_WELCOME_MESSAGE = False
            USER_EMAIL_SUBJECTS = {}

        app = bootstrap.create_app(__name__, config=CustomConfig())
        user_feature(app)

        self.assertEquals(CustomConfig.USER_PUBLIC_PROFILES,
                          user_service.welcome_message)
        self.assertEquals(CustomConfig.USER_ACCOUNTS_REQUIRE_CONFIRMATION,
                          user_service.require_confirmation)
        self.assertEquals(CustomConfig.USER_EMAIL_SUBJECTS,
                          user_service.email_subjects)
コード例 #6
0
    def test_user_service_receives_jwt_options(self):
        """ Initializing user service with config options """
        class CustomConfig(DefaultConfig, UserConfig):
            USER_JWT_SECRET = 'SuperSecret'
            USER_JWT_ALGO = 'FAKE526'
            USER_JWT_LIFETIME_SECONDS = -1
            USER_JWT_IMPLEMENTATION = None
            USER_JWT_LOADER_IMPLEMENTATION = None

        cfg = CustomConfig()
        app = bootstrap.create_app(__name__, config=cfg)
        user_feature(app)

        self.assertEquals(cfg.get('USER_JWT_SECRET'), user_service.jwt_secret)
        self.assertEquals(cfg.get('USER_JWT_ALGO'), user_service.jwt_algo)
        self.assertEquals(cfg.get('USER_JWT_LIFETIME_SECONDS'),
                          user_service.jwt_lifetime)
        self.assertEquals(cfg.get('USER_JWT_IMPLEMENTATION'),
                          user_service.jwt_implementation)
        self.assertEquals(cfg.get('USER_JWT_LOADER_IMPLEMENTATION'),
                          user_service.jwt_loader_implementation)
コード例 #7
0
ファイル: app.py プロジェクト: projectshift/shift-user
from boiler import bootstrap
from boiler.config import TestingConfig
from shiftuser.config import UserConfig
"""
Create app for testing
This is not a real application, we only use it to run tests against.
"""


class Config(TestingConfig, UserConfig):
    USER_JWT_SECRET = 'typically will come from environment'
    SECRET_KEY = 'supersecret'


# create app
app = bootstrap.create_app(
    __name__,
    config=Config(),
)
bootstrap.add_orm(app)
bootstrap.add_mail(app)
bootstrap.add_routing(app)