Esempio n. 1
0
def test_monitor_users_same_permissions(app):
    """If the user's permissions match the token's, leave it enabled"""
    with app.app_context():
        insert_usr(app, permissions=[A, B])
        with mocked_perms({'*****@*****.**': [A, B]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_enabled(app)
Esempio n. 2
0
def test_monitor_users_disable_user_gone(app):
    """If the user is gone, disable"""
    with app.app_context():
        insert_usr(app, permissions=[A, B])
        with mocked_perms({}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [A, B])
Esempio n. 3
0
def test_monitor_users_disable_user_gone_no_token_perms(app):
    """If the user is gone, disable even a token with no permissions."""
    with app.app_context():
        insert_usr(app, permissions=[])
        with mocked_perms({}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [])
Esempio n. 4
0
def test_monitor_users_disable_reduced_perms(app):
    """If the user's permissions are a subset of those for the token, disable"""
    with app.app_context():
        insert_usr(app, permissions=[A, B])
        with mocked_perms({'*****@*****.**': [A]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [A, B])
Esempio n. 5
0
def test_monitor_users_disable_changed_perms(app):
    """If the user's permissions are a, b and the token's are b, c, disable"""
    with app.app_context():
        insert_usr(app, permissions=[B, C])
        with mocked_perms({'*****@*****.**': [A, B]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [B, C])
Esempio n. 6
0
def test_monitor_users_disable_user_gone_no_token_perms(app):
    """If the user is gone, disable even a token with no permissions."""
    with app.app_context():
        insert_usr(app, permissions=[])
        with mocked_perms({}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [])
Esempio n. 7
0
def test_monitor_users_reenable(app):
    """If the token is disabled and can be re-enabled, it is"""
    with app.app_context():
        insert_usr(app, permissions=[A, B], disabled=True)
        with mocked_perms({'*****@*****.**': [A, B, C]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_reenabled(app, js, [A, B])
Esempio n. 8
0
def test_monitor_users_disable_user_gone(app):
    """If the user is gone, disable"""
    with app.app_context():
        insert_usr(app, permissions=[A, B])
        with mocked_perms({}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [A, B])
Esempio n. 9
0
def test_monitor_users_disable_changed_perms(app):
    """If the user's permissions are a, b and the token's are b, c, disable"""
    with app.app_context():
        insert_usr(app, permissions=[B, C])
        with mocked_perms({'*****@*****.**': [A, B]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [B, C])
Esempio n. 10
0
def test_monitor_users_disable_reduced_perms(app):
    """If the user's permissions are a subset of those for the token, disable"""
    with app.app_context():
        insert_usr(app, permissions=[A, B])
        with mocked_perms({'*****@*****.**': [A]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_disabled(app, js, [A, B])
Esempio n. 11
0
def test_monitor_users_reenable(app):
    """If the token is disabled and can be re-enabled, it is"""
    with app.app_context():
        insert_usr(app, permissions=[A, B], disabled=True)
        with mocked_perms({'*****@*****.**': [A, B, C]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_reenabled(app, js, [A, B])
Esempio n. 12
0
def test_monitor_users_ample_permissions(app):
    """If the user's permissions exceed the token's, leave it enabled"""
    with app.app_context():
        insert_usr(app, permissions=[A, B])
        with mocked_perms({'*****@*****.**': [A, B, C]}):
            js = mock.Mock()
            usermonitor.monitor_users(js)
        assert_enabled(app)