Example #1
0
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
Example #2
0
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
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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
Example #7
0
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
Example #8
0
def test_init_app_late():
    app = Flask("text")
    multipass = Multipass()
    multipass.init_app(app)
    assert app.extensions["multipass"].multipass is multipass
Example #9
0
def test_init_app_twice():
    multipass = Multipass()
    app = Flask("test")
    multipass.init_app(app)
    with pytest.raises(RuntimeError):
        multipass.init_app(app)
Example #10
0
def test_init_app_late():
    app = Flask('text')
    multipass = Multipass()
    multipass.init_app(app)
    assert app.extensions['multipass'].multipass is multipass
Example #11
0
def test_init_app_twice():
    multipass = Multipass()
    app = Flask('test')
    multipass.init_app(app)
    with pytest.raises(RuntimeError):
        multipass.init_app(app)
Example #12
0
    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)
Example #13
0
def test_init_app_late():
    app = Flask('text')
    multipass = Multipass()
    multipass.init_app(app)
    assert app.extensions['multipass'].multipass is multipass
Example #14
0
        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()