コード例 #1
0
def test_files_group(mock_stat):
    """
    Test the file group.

    Our mocked files want root, nobody, (root, nobody), (root, root).
    """
    f = FileCheck()
    f.files = files

    mock_stat.return_value = make_stat()
    results = capture_results(f)

    my_results = get_results(results, 'group')
    assert my_results.results[0].result == constants.SUCCESS
    assert my_results.results[1].result == constants.WARNING
    assert my_results.results[2].result == constants.SUCCESS
    assert my_results.results[3].result == constants.SUCCESS

    mock_stat.return_value = make_stat(gid=nobody.pw_gid)
    results = capture_results(f)
    my_results = get_results(results, 'group')
    assert my_results.results[0].result == constants.WARNING
    assert my_results.results[0].kw.get('got') == 'nobody'
    assert my_results.results[0].kw.get('expected') == 'root'
    assert my_results.results[0].kw.get('type') == 'group'

    assert my_results.results[1].result == constants.SUCCESS
    assert my_results.results[2].result == constants.SUCCESS

    assert my_results.results[3].result == constants.WARNING
    assert my_results.results[3].kw.get('got') == 'nobody'
    assert my_results.results[3].kw.get('expected') == 'root,bin'
    assert my_results.results[3].kw.get('type') == 'group'
    assert my_results.results[3].kw.get('msg') == \
        'Group of fiz is nobody and should be one of root,bin'
コード例 #2
0
def test_files_not_found(mock_exists):
    mock_exists.return_value = False

    f = FileCheck()
    f.files = files

    results = capture_results(f)

    for type in ('mode', 'group', 'owner'):
        my_results = get_results(results, type)
        assert len(my_results.results) == len(f.files)
        for result in my_results.results:
            assert result.result == constants.SUCCESS
            assert result.kw.get('msg') == 'File does not exist'
コード例 #3
0
def test_files_group(mock_stat):
    mock_stat.return_value = make_stat()

    f = FileCheck()
    f.files = files

    results = capture_results(f)

    my_results = get_results(results, 'group')
    assert my_results.results[0].result == constants.SUCCESS
    assert my_results.results[1].result == constants.WARNING

    mock_stat.return_value = make_stat(gid=nobody.pw_gid)
    results = capture_results(f)
    my_results = get_results(results, 'group')
    assert my_results.results[0].result == constants.WARNING
    assert my_results.results[1].result == constants.SUCCESS
コード例 #4
0
def test_files_mode(mock_stat):
    mock_stat.return_value = make_stat()

    f = FileCheck()
    f.files = files

    results = capture_results(f)

    my_results = get_results(results, 'mode')
    assert my_results.results[0].result == constants.SUCCESS
    assert my_results.results[1].result == constants.WARNING

    mock_stat.return_value = make_stat(mode=33204)
    results = capture_results(f)
    my_results = get_results(results, 'mode')
    assert my_results.results[0].result == constants.WARNING
    assert my_results.results[1].result == constants.SUCCESS
コード例 #5
0
def test_files_mode(mock_stat):
    mock_stat.return_value = make_stat()

    f = FileCheck()
    f.files = files

    results = capture_results(f)

    my_results = get_results(results, 'mode')
    assert my_results.results[0].result == constants.SUCCESS
    assert my_results.results[1].result == constants.ERROR

    # Too restrictive
    mock_stat.return_value = make_stat(mode=33152)  # 0600
    results = capture_results(f)
    my_results = get_results(results, 'mode')
    assert my_results.results[0].result == constants.ERROR
    assert my_results.results[1].result == constants.ERROR
    assert my_results.results[2].result == constants.ERROR
    assert my_results.results[3].result == constants.ERROR
    assert my_results.results[4].result == constants.ERROR

    # Too permissive
    mock_stat.return_value = make_stat(mode=33206)  # 0666
    results = capture_results(f)
    my_results = get_results(results, 'mode')
    assert my_results.results[0].result == constants.WARNING
    assert my_results.results[1].result == constants.WARNING
    assert my_results.results[2].result == constants.WARNING
    assert my_results.results[3].result == constants.WARNING
    assert my_results.results[4].result == constants.WARNING

    # Too restrictive with allowed multi-mode value
    mock_stat.return_value = make_stat(mode=33184)  # 0640
    results = capture_results(f)
    my_results = get_results(results, 'mode')
    assert my_results.results[0].result == constants.ERROR
    assert my_results.results[1].result == constants.ERROR
    assert my_results.results[2].result == constants.ERROR
    assert my_results.results[3].result == constants.ERROR
    assert my_results.results[4].result == constants.SUCCESS