def init_app(self, app): """Initialize the extension for a Flask application. This is only necessary if the application was not provided in the constructor, e.g. because there is more than one application or you are using an application factory. :param app: The flask application """ if 'multipass' in app.extensions: raise RuntimeError('Flask application already initialized') state = app.extensions['multipass'] = _MultipassState(self, app) # TODO: write docs for the config (see flask-cache for a pretty example) app.config.setdefault('MULTIPASS_AUTH_PROVIDERS', {}) app.config.setdefault('MULTIPASS_IDENTITY_PROVIDERS', {}) app.config.setdefault('MULTIPASS_PROVIDER_MAP', {}) app.config.setdefault('MULTIPASS_IDENTITY_INFO_KEYS', None) app.config.setdefault('MULTIPASS_LOGIN_SELECTOR_TEMPLATE', None) app.config.setdefault('MULTIPASS_LOGIN_FORM_TEMPLATE', None) app.config.setdefault('MULTIPASS_LOGIN_ENDPOINT', 'login') app.config.setdefault('MULTIPASS_LOGIN_URLS', ('/login/', '/login/<provider>')) app.config.setdefault('MULTIPASS_SUCCESS_ENDPOINT', 'index') app.config.setdefault('MULTIPASS_FAILURE_MESSAGE', 'Authentication failed: {error}') app.config.setdefault('MULTIPASS_FAILURE_CATEGORY', 'error') app.config.setdefault('MULTIPASS_ALL_MATCHING_IDENTITIES', False) app.config.setdefault('MULTIPASS_REQUIRE_IDENTITY', True) with app.app_context(): self._create_login_rule() state.auth_providers = ImmutableDict(self._create_providers('AUTH', AuthProvider)) state.identity_providers = ImmutableDict(self._create_providers('IDENTITY', IdentityProvider)) state.provider_map = ImmutableDict(get_canonical_provider_map(current_app.config['MULTIPASS_PROVIDER_MAP'])) validate_provider_map(state)
def test_validate_provider_map(valid, auth_providers, identity_providers, provider_map): state = _MultipassState(None, None) state.auth_providers = {x: {} for x in auth_providers} state.identity_providers = {x: {} for x in identity_providers} state.provider_map = {a: [{'identity_provider': u}] for a, u in iteritems(provider_map)} if valid: validate_provider_map(state) else: pytest.raises(ValueError, validate_provider_map, state)
def test_validate_provider_map(valid, auth_providers, identity_providers, provider_map): state = _MultipassState(None, None) state.auth_providers = {x: {} for x in auth_providers} state.identity_providers = {x: {} for x in identity_providers} state.provider_map = { a: [{ 'identity_provider': u }] for a, u in iteritems(provider_map) } if valid: validate_provider_map(state) else: pytest.raises(ValueError, validate_provider_map, state)