Beispiel #1
0
def basic_store():
    store = stores.RuleStore()
    store.load_config({
        'groups': [
            {
                'name': 'admin',
                'members': [
                    '*****@*****.**',
                ],
            },
            {
                'name': 'silly-cirno',
                'members': [
                    '*****@*****.**',
                ],
            },
        ],
        'rules': [
            {
                'host': '.*',
                'request_method': '.*',
                'request_uri': '.*',
                'group': 'admin',
                'allow': True,
            },
            {
                'host': 'gensokyo.local',
                'request_method': '.*',
                'request_uri': '.*',
                'group': 'silly-cirno',
                'allow': False,
            },
        ],
    })
    return store
Beispiel #2
0
def test_loading_empty_config_is_ok():
    store = stores.RuleStore()
    store.load_config({
        'groups': [],
        'rules': [],
    })
    assert store.has_been_initialized
    assert store.rules == []
Beispiel #3
0
def test_loading_group_with_no_rules_is_ok():
    store = stores.RuleStore()
    store.load_config({
        'groups': [
            {
                'name': 'akbs',
                'members': [
                    '*****@*****.**',
                ]
            },
        ],
        'rules': [],
    })
    assert store.has_been_initialized
    assert store.rules == []
Beispiel #4
0
def test_loading_rule_with_nonexistent_group_errors():
    store = stores.RuleStore()
    config_with_nonexistent_group = {
        'groups': [],
        'rules': [
            {
                'host': '.*',
                'request_method': '.*',
                'request_uri': '.*',
                'group': 'nonexistent',
                'allow': True,
            }
        ],
    }

    with pytest.raises(exceptions.InvalidConfig):
        store.load_config(config_with_nonexistent_group)
Beispiel #5
0
def test_uninitialized_rule_store_raises_exception():
    store = stores.RuleStore()

    with pytest.raises(exceptions.UninitializedRuleStore):
        store.has_access(mock.Mock())