Exemple #1
0
def test_apply_values_to_audit_quoted_values():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : __VAL__\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = [[{
        '192.168.0.10': {
            'Test value one': 'ab"cd'
        }
    }, '\'ab"cd\''], [{
        '192.168.0.10': {
            'Test value one': "ab'cd"
        }
    }, '"ab\'cd"'], [{
        '192.168.0.10': {
            'Test value one': 'abcd'
        }
    }, '"abcd"'],
                   [{
                       '192.168.0.10': {
                           'Test value one': 'a"bc\'"d'
                       }
                   }, '"a\\"bc\'\\"d"']]
    for (test_value, expected_value) in test_values:
        actual = apply_values_to_audit('abc.audit', test_content, test_value)
        test_expected = expected_content.replace('__VAL__', expected_value)
        expected = {'abc.192.168.0.10.audit': test_expected}
        assert actual == expected
def test_apply_values_to_audit_multiple_hosts():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : "__VAL__"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = {
        '192.168.0.10': {
            'Test value one': '0'
        },
        '192.168.0.11': {
            'Test value one': '1'
        }
    }
    actual = apply_values_to_audit('abc.audit', test_content, test_values)
    expected = {
        'abc.192.168.0.10.audit': expected_content.replace('__VAL__', '0'),
        'abc.192.168.0.11.audit': expected_content.replace('__VAL__', '1')
    }
    assert actual == expected
def test_apply_values_to_audit_multiple_hosts_with_ref():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  reference : "ABC|compliant"\n'
                        '  known_good : "__VAL__"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = {
        '192.168.0.10': {
            'Test value one': ('0', 'PASSED')
        },
        '192.168.0.11': {
            'Test value one': ('1', 'PASSED')
        }
    }
    actual = apply_values_to_audit('abc.audit', test_content, test_values,
                                   'ABC')
    expected = {
        'abc.192.168.0.10.audit': expected_content.replace('__VAL__', '0'),
        'abc.192.168.0.11.audit': expected_content.replace('__VAL__', '1')
    }
    assert actual == expected
def test_apply_values_to_audit_no_values():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>'
                    '</check_type>')
    actual = apply_values_to_audit('abc.audit', test_content, {})
    expected = {}
    assert actual == expected
def test_apply_values_to_audit_no_values():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>'
                    '</check_type>')
    actual = apply_values_to_audit('abc.audit', test_content, {})
    expected = {}
    assert actual == expected
def test_apply_values_to_audit_simple_content_and_values():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : "0"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = {'192.168.0.10': {'Test value one': '0'}}
    actual = apply_values_to_audit('abc.audit', test_content, test_values)
    expected = {'abc.192.168.0.10.audit': expected_content}
    assert actual == expected
def test_apply_values_to_audit_simple_content_and_values():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : "0"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = { '192.168.0.10': { 'Test value one': '0' }}
    actual = apply_values_to_audit('abc.audit', test_content, test_values)
    expected = {'abc.192.168.0.10.audit': expected_content}
    assert actual == expected
def test_apply_values_to_audit_simple_content_and_values_with_ref():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  reference : "ABC|compliant"\n'
                        '  known_good : "0"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = {'192.168.0.10': {'Test value one': ('0', 'PASSED')}}
    actual = apply_values_to_audit('abc.audit', test_content, test_values,
                                   'ABC')
    expected = {'abc.192.168.0.10.audit': expected_content}
    assert actual == expected
def test_apply_values_to_audit_multiple_known_goods_with_ref():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '  known_good : "0"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : "0"\n'
                        '  reference : "ABC|deviation"\n'
                        '  known_good : "1"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = {'192.168.0.10': {'Test value one': ('1', 'FAILED')}}
    actual = apply_values_to_audit('abc.audit', test_content, test_values,
                                   'ABC')
    expected = {'abc.192.168.0.10.audit': expected_content}
    assert actual == expected
def test_apply_values_to_audit_multiple_hosts():
    test_content = ('<check_type:"Unix">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Unix">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : "__VAL__"\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = {
        '192.168.0.10': { 'Test value one': '0' },
        '192.168.0.11': { 'Test value one': '1' }
    }
    actual = apply_values_to_audit('abc.audit', test_content, test_values)
    expected = {
        'abc.192.168.0.10.audit': expected_content.replace('__VAL__', '0'),
        'abc.192.168.0.11.audit': expected_content.replace('__VAL__', '1')
    }
    assert actual == expected
def test_apply_values_to_audit_quoted_values():
    test_content = ('<check_type:"Cisco">\n'
                    '<custom_item>\n'
                    '  description: "Test value one"\n'
                    '</custom_item>\n'
                    '</check_type>')
    expected_content = ('<check_type:"Cisco">\n'
                        '<custom_item>\n'
                        '  description: "Test value one"\n'
                        '  known_good : __VAL__\n'
                        '</custom_item>\n'
                        '</check_type>')
    test_values = [
        [{ '192.168.0.10': { 'Test value one': 'ab"cd' }}, '\'ab"cd\''],
        [{ '192.168.0.10': { 'Test value one': "ab'cd" }}, '"ab\'cd"'],
        [{ '192.168.0.10': { 'Test value one': 'abcd' }}, '"abcd"'],
        [{ '192.168.0.10': { 'Test value one': 'a"bc\'"d' }}, '"a\\"bc\'\\"d"']
    ]
    for (test_value, expected_value) in test_values:
        actual = apply_values_to_audit('abc.audit', test_content, test_value)
        test_expected = expected_content.replace('__VAL__', expected_value)
        expected = {'abc.192.168.0.10.audit': test_expected}
        assert actual == expected
def test_apply_values_to_audit_no_content():
    test_values = {'192.168.0.10': {'Test value one': '0'}}
    expected = {'abc.192.168.0.10.audit': ''}
    assert apply_values_to_audit('abc.audit', '', test_values) == expected
def test_apply_values_to_audit_no_content_or_values():
    assert apply_values_to_audit('abc.audit', '', {}) == {}
def test_apply_values_to_audit_no_content():
    test_values = { '192.168.0.10': { 'Test value one': '0' }}
    expected = {'abc.192.168.0.10.audit': ''}
    assert apply_values_to_audit('abc.audit', '', test_values) == expected
def test_apply_values_to_audit_no_content_or_values():
    assert apply_values_to_audit('abc.audit', '', {}) == {}