def test_multiple_apps(): apps = Flask('test'), Flask('test') multipass = Multipass() for app in apps: multipass.init_app(app) # The separate loop here is on purpose as the extension needs to # be present on all apps after initializing them for app in apps: assert app.extensions['multipass'].multipass is multipass
def test_multiple_apps(): apps = Flask("test"), Flask("test") multipass = Multipass() for app in apps: multipass.init_app(app) # The separate loop here is on purpose as the extension needs to # be present on all apps after initializing them for app in apps: assert app.extensions["multipass"].multipass is multipass
def test_initialize_providers_unique(): app = Flask("test") app.config["MULTIPASS_AUTH_PROVIDERS"] = { "test": {"type": "unique", "foo": "bar"}, "test2": {"type": "unique", "hello": "world"}, } multipass = Multipass() multipass.register_provider(FooProvider, "foo") multipass.register_provider(UniqueProvider, "unique") with pytest.raises(RuntimeError): multipass.init_app(app)
def test_initialize_providers_unique(): app = Flask('test') app.config['MULTIPASS_AUTH_PROVIDERS'] = { 'test': {'type': 'unique', 'foo': 'bar'}, 'test2': {'type': 'unique', 'hello': 'world'}, } multipass = Multipass() multipass.register_provider(FooProvider, 'foo') multipass.register_provider(UniqueProvider, 'unique') with pytest.raises(RuntimeError): multipass.init_app(app)
def test_get_state_explicit(): app = Flask('test') app2 = Flask('test2') multipass = Multipass() multipass.init_app(app) multipass.init_app(app2) # outside app ctx with pytest.raises(RuntimeError): assert get_state().app # explicit app assert get_state(app2).app is app2 # explicit app inside other app context (unlikely) with app.app_context(): assert get_state(app2).app is app2
def test_init_app_late(): app = Flask("text") multipass = Multipass() multipass.init_app(app) assert app.extensions["multipass"].multipass is multipass
def test_init_app_twice(): multipass = Multipass() app = Flask("test") multipass.init_app(app) with pytest.raises(RuntimeError): multipass.init_app(app)
def test_init_app_late(): app = Flask('text') multipass = Multipass() multipass.init_app(app) assert app.extensions['multipass'].multipass is multipass
def test_init_app_twice(): multipass = Multipass() app = Flask('test') multipass.init_app(app) with pytest.raises(RuntimeError): multipass.init_app(app)
if not g.user: flash('Not logged in', 'error') return redirect(url_for('index')) for identity in g.user.identities: if json.loads(identity.multipass_data) is None: continue identity_info = multipass.refresh_identity(identity.identifier, json.loads(identity.multipass_data)) identity.multipass_data = json.dumps(identity_info.multipass_data) flash('Refreshed IdentityInfo: {}'.format(identity_info), 'success') db.session.commit() return redirect(url_for('index')) app.config.from_pyfile('example.cfg') multipass.register_provider(LocalAuthProvider, 'example_local') multipass.register_provider(LocalIdentityProvider, 'example_local') multipass.init_app(app) db.init_app(app) with app.app_context(): db.create_all() if not User.query.filter_by(name='Local Guinea Pig').count(): user = User(name='Local Guinea Pig', email='*****@*****.**', affiliation='Local') identity = Identity(provider='local', identifier='Test', multipass_data='null', password='******') user.identities.append(identity) db.session.add(user) db.session.commit() if __name__ == '__main__': app.run('0.0.0.0', 10500, use_evalex=False)
return redirect(url_for('index')) for identity in g.user.identities: if json.loads(identity.multipass_data) is None: continue identity_info = multipass.refresh_identity( identity.identifier, json.loads(identity.multipass_data)) identity.multipass_data = json.dumps(identity_info.multipass_data) flash('Refreshed IdentityInfo: {}'.format(identity_info), 'success') db.session.commit() return redirect(url_for('index')) app.config.from_pyfile('example.cfg') multipass.register_provider(LocalAuthProvider, 'example_local') multipass.register_provider(LocalIdentityProvider, 'example_local') multipass.init_app(app) db.init_app(app) with app.app_context(): db.create_all() if not User.query.filter_by(name='Local Guinea Pig').count(): user = User(name='Local Guinea Pig', email='*****@*****.**', affiliation='Local') identity = Identity(provider='local', identifier='Test', multipass_data='null', password='******') user.identities.append(identity) db.session.add(user) db.session.commit()