Beispiel #1
0
def test_correct_format_ok_validtypes():
    '''
    Verify that valid config is allowed when
    proper keys and lists of strings are specified
    '''
    # files and commands (file-redaction.yaml)
    parsed_data = {'commands': ['/bin/test', '/bin/test2'], 'files': ['/var/lib/aaa', '/var/lib/nnn']}
    expected_keys = ('commands', 'files')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_redaction_file)
    assert not err
    assert msg is None

    # patterns w. list of strings (file-content-redaction.yaml)
    parsed_data = {'patterns': ['abcd', 'bcdef'], 'keywords': ['example', 'example2']}
    expected_keys = ('patterns', 'keywords')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_content_redaction_file)
    assert not err
    assert msg is None

    # patterns w. regex object (file-content-redaction.yaml)
    parsed_data = {'patterns': {'regex': ['abcd', 'bcdef']}, 'keywords': ['example', 'example2']}
    expected_keys = ('patterns', 'keywords')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_content_redaction_file)
    assert not err
    assert msg is None
Beispiel #2
0
def test_config_verification_bad_invalidkeys():
    '''
    Verify that a config with invalid keys is not allowed
    '''
    parsed_data = {'commands': None, 'files': None, 'somekey': None}
    expected_keys = ('commands', 'files')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_redaction_file)
    assert err
    assert 'Unknown section' in msg
Beispiel #3
0
def test_correct_format_bad_invalidtypes():
    '''
    Verify that a config with valid keys,
    but invalid data types, is not allowed
    '''
    parsed_data = {'commands': 'somestring', 'files': ['/var/lib/aaa', '/var/lib/bbb']}
    expected_keys = ('commands', 'files')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_redaction_file)
    assert err
    assert 'must be a list of strings' in msg
Beispiel #4
0
def test_config_verification_ok_emptyvalues():
    '''
    Verify that valid config is allowed when
    proper keys and empty (None) values are specified
    '''
    parsed_data = {'patterns': None, 'keywords': ['abc', 'def']}
    expected_keys = ('patterns', 'keywords')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_content_redaction_file)
    assert not err
    assert msg is None
Beispiel #5
0
def test_correct_format_bad_patterns_invalidkey():
    '''
    Verify that a config with patterns, if a dict
    containing the key "regex", only contains the key "regex"
    '''
    parsed_data = {'patterns': {'regex': [], 'wrongkey': ['a(bc)', 'nextregex']}}
    expected_keys = ('patterns', 'keywords')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_content_redaction_file)
    assert err
    assert 'Only "regex" is valid' in msg
Beispiel #6
0
def test_correct_format_bad_keys_in_wrong_file():
    '''
    Verify that an otherwise valid key is not
    specified in the wrong file (i.e. patterns
    in file-redaction.yaml)
    '''
    parsed_data = {'files': ['/etc/example'], 'patterns': ['abc', 'def']}
    expected_keys = ('files', 'commands')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_redaction_file)
    assert err
    assert 'Unknown section(s) in ' + conf_file_redaction_file in msg
Beispiel #7
0
def test_correct_format_bad_patterns_regexinvalidtype():
    '''
    Verify that if a regex key exists in the
    patterns section, that the value is a list
    of strings
    '''
    parsed_data = {'patterns': {'regex': 'a(b)'}}
    expected_keys = ('patterns', 'keywords')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_content_redaction_file)
    assert err
    assert 'regex section under patterns must be a list of strings' in msg
Beispiel #8
0
def test_correct_format_bad_patterns_keysnoregex():
    '''
    Verify that a config with patterns, if a dict
    with a single key, only contains the key
    "regex"
    '''
    parsed_data = {'patterns': {'wrongkey': ['a(bc)', 'nextregex']}}
    expected_keys = ('patterns', 'keywords')
    err, msg = correct_format(parsed_data, expected_keys, conf_file_content_redaction_file)
    assert err
    assert 'contains an object but the "regex" key was not specified' in msg