示例#1
0
def test_link_localtime_traversal_attack(questionable_timezone):
    with assert_raises(tzupdate.DirectoryTraversalError):
        tzupdate.link_localtime(
            questionable_timezone,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )
示例#2
0
def test_link_localtime_traversal_attack(questionable_timezone):
    with assert_raises(tzupdate.DirectoryTraversalError):
        tzupdate.link_localtime(
            questionable_timezone,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )
示例#3
0
def test_link_localtime_timezone_not_available(isfile_mock):
    isfile_mock.return_value = False
    with assert_raises(tzupdate.TimezoneNotLocallyAvailableError):
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH,
        )
示例#4
0
def test_link_localtime_timezone_not_available(isfile_mock):
    isfile_mock.return_value = False
    with pytest.raises(tzupdate.TimezoneNotLocallyAvailableError):
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )
示例#5
0
def test_link_localtime_localtime_missing_no_raise(symlink_mock, isfile_mock,
                                                   unlink_mock):
    isfile_mock.return_value = True
    code = errno.ENOENT
    unlink_mock.side_effect = OSError(code, "No such file or directory")

    # This should handle OSError and not raise further
    tzupdate.link_localtime(FAKE_TIMEZONE, tzupdate.DEFAULT_ZONEINFO_PATH,
                            tzupdate.DEFAULT_LOCALTIME_PATH)
示例#6
0
def test_link_localtime_traversal_attack_dotdot(questionable_timezone):
    assume(tzupdate.DEFAULT_ZONEINFO_PATH not in questionable_timezone)
    questionable_timezone = "../../../" + questionable_timezone

    with pytest.raises(tzupdate.DirectoryTraversalError):
        tzupdate.link_localtime(
            questionable_timezone,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )
示例#7
0
def test_link_localtime_permission_denied(isfile_mock, unlink_mock):
    isfile_mock.return_value = True
    unlink_mock.side_effect = OSError(errno.EACCES, 'Permission denied yo')
    with assert_raises(OSError) as raise_cm:
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH,
        )

    eq(raise_cm.exception.errno, errno.EACCES)
示例#8
0
def test_link_localtime_permission_denied(isfile_mock, unlink_mock):
    isfile_mock.return_value = True
    unlink_mock.side_effect = OSError(errno.EACCES, 'Permission denied yo')
    with assert_raises(OSError) as raise_cm:
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )

    eq(raise_cm.exception.errno, errno.EACCES)
示例#9
0
def test_link_localtime_permission_denied(isfile_mock, unlink_mock):
    isfile_mock.return_value = True
    unlink_mock.side_effect = OSError(errno.EACCES, "Permission denied yo")
    with pytest.raises(OSError) as raise_cm:
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )

    assert raise_cm.value.errno == errno.EACCES
示例#10
0
def test_link_localtime_localtime_missing_no_raise(symlink_mock, isfile_mock,
                                                   unlink_mock):
    isfile_mock.return_value = True
    code = errno.ENOENT
    unlink_mock.side_effect = OSError(code, 'No such file or directory')

    # This should handle OSError and not raise further
    tzupdate.link_localtime(
        FAKE_TIMEZONE,
        tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH,
    )
示例#11
0
def test_link_localtime_oserror_not_permission(isfile_mock, unlink_mock):
    isfile_mock.return_value = True
    code = errno.ENOSPC
    unlink_mock.side_effect = OSError(code, 'No space yo')

    with assert_raises(OSError) as thrown_exc:
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH,
        )

    eq(thrown_exc.exception.errno, code)
示例#12
0
def test_link_localtime_oserror_not_permission(isfile_mock, unlink_mock):
    isfile_mock.return_value = True
    code = errno.ENOSPC
    unlink_mock.side_effect = OSError(code, "No space yo")

    with pytest.raises(OSError) as thrown_exc:
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )

    assert thrown_exc.value.errno == code
示例#13
0
def test_link_localtime_mounts_different(symlink_mock, stat_mock, exists_mock,
                                         isfile_mock, replace_mock):
    isfile_mock.return_value = True

    # Check st_dev
    exists_mock.return_value = True

    # It should fail since devices are not the same
    first = os.stat_result((0, 0, 123, 0, 0, 0, 0, 0, 0, 0))
    second = os.stat_result((0, 0, 456, 0, 0, 0, 0, 0, 0, 0))
    stat_mock.side_effect = [first, second]

    with pytest.raises(tzupdate.TimezoneUpdateException):
        tzupdate.link_localtime(
            FAKE_TIMEZONE,
            tzupdate.DEFAULT_ZONEINFO_PATH,
            tzupdate.DEFAULT_LOCALTIME_PATH,
        )
示例#14
0
def test_link_localtime(isfile_mock, symlink_mock, unlink_mock):
    isfile_mock.return_value = True
    expected = os.path.join(tzupdate.DEFAULT_ZONEINFO_PATH, FAKE_TIMEZONE)

    zoneinfo_tz_path = tzupdate.link_localtime(FAKE_TIMEZONE,
                                               tzupdate.DEFAULT_ZONEINFO_PATH,
                                               tzupdate.DEFAULT_LOCALTIME_PATH)

    assert unlink_mock.called_once_with([expected])
    assert symlink_mock.called_once_with(
        [expected, tzupdate.DEFAULT_LOCALTIME_PATH])

    assert zoneinfo_tz_path == expected
示例#15
0
def test_link_localtime(isfile_mock, symlink_mock, unlink_mock):
    isfile_mock.return_value = True
    expected = os.path.join(tzupdate.DEFAULT_ZONEINFO_PATH, FAKE_TIMEZONE)

    zoneinfo_tz_path = tzupdate.link_localtime(
        FAKE_TIMEZONE, tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH
    )

    assert_true(unlink_mock.called_once_with([expected]))
    assert_true(
        symlink_mock.called_once_with([expected, tzupdate.DEFAULT_LOCALTIME_PATH])
    )

    eq(zoneinfo_tz_path, expected)
示例#16
0
def test_link_localtime(exists_mock, isfile_mock, symlink_mock, replace_mock):
    isfile_mock.return_value = True

    # Don't check st_dev
    exists_mock.return_value = False

    expected = os.path.join(tzupdate.DEFAULT_ZONEINFO_PATH, FAKE_TIMEZONE)

    zoneinfo_tz_path = tzupdate.link_localtime(FAKE_TIMEZONE,
                                               tzupdate.DEFAULT_ZONEINFO_PATH,
                                               tzupdate.DEFAULT_LOCALTIME_PATH)

    assert replace_mock.called_once_with([
        tzupdate.DEFAULT_LOCALTIME_PATH + "~", tzupdate.DEFAULT_LOCALTIME_PATH
    ])
    assert symlink_mock.called_once_with(
        [expected, tzupdate.DEFAULT_LOCALTIME_PATH + "~"])

    assert zoneinfo_tz_path == expected
示例#17
0
def test_link_localtime_mounts_same(symlink_mock, stat_mock, exists_mock,
                                    isfile_mock, replace_mock):
    isfile_mock.return_value = True

    # Check st_dev
    exists_mock.return_value = True

    # It shouldn't fail since devices are the same
    first = os.stat_result((0, 0, 123, 0, 0, 0, 0, 0, 0, 0))
    second = os.stat_result((0, 0, 123, 0, 0, 0, 0, 0, 0, 0))
    stat_mock.side_effect = [first, second]

    expected = os.path.join(tzupdate.DEFAULT_ZONEINFO_PATH, FAKE_TIMEZONE)

    zoneinfo_tz_path = tzupdate.link_localtime(FAKE_TIMEZONE,
                                               tzupdate.DEFAULT_ZONEINFO_PATH,
                                               tzupdate.DEFAULT_LOCALTIME_PATH)

    assert zoneinfo_tz_path == expected