Commit Graph

988 Commits

Author SHA1 Message Date
bigtedde 67334c4e83 removed BaseTestCase from helpers.py 2023-07-26 14:50:52 -07:00
bigtedde d2f32986f3 removed TestCaseBase from testsuite/archive.py 2023-07-26 12:18:25 -07:00
Thomas Waldmann 5013121bd8
fix E501 2023-07-26 01:24:20 +02:00
Thomas Waldmann 6151b369c4
fix E741 2023-07-26 01:24:00 +02:00
Thomas Waldmann 35ac39b751
fix F401 2023-07-26 01:23:37 +02:00
Thomas Waldmann 3017701958
simplify flake8 configuration
we use black since a while, so some stuff does not need to be ignored any more.
2023-07-25 23:56:31 +02:00
Thomas Waldmann b0497499cc
fix test_disk_full, fixes #7617
- master branch has different free space requirements from 1.2-maint,
  so we now use a 700MB filesystem
- used pytest.mark.parametrize for the test passes, kind of a progress
  display
- fix bug in rcreate call, encryption arg is needed
- fix bug in lock file cleanup
- added repo space cleanup
- updated docstring with current linux instructions (ubuntu)
- stopped using the "reserved" files, the "input" files are good enough
  to get some space freed.
-
2023-07-25 22:13:36 +02:00
Thomas Waldmann b97c3d3a55
simplify BaseTestCase.assert_raises 2023-07-25 15:14:46 +02:00
Thomas Waldmann a2e7854911
simplify changedir with @contextmanager 2023-07-25 15:12:32 +02:00
Thomas Waldmann 02fcabe31f
remove unused methods of BaseTestCase
also: clean up imports / comments
2023-07-25 15:07:53 +02:00
Thomas Waldmann b8a52a4769
tests: remove usage of environment_variable context manager
rather use monkeypatch.setenv/delenv.
2023-07-25 13:29:02 +02:00
Ted Lawson 2e59a702f6
`cmd` function now creates repo_location argument (#7734)
f'repo={repo_location}' moved to 'cmd' function
2023-07-24 23:54:47 +02:00
TW e1cd38a0df
Merge pull request #7722 from bigtedde/archiver-tests
Archiver folder - all tests converted from unittest to pytest
2023-07-23 15:07:03 +02:00
bigtedde 6f35f5b0a4 simplified remote repo check 2023-07-22 23:39:10 -07:00
bigtedde b8b80c5fef get_kind added to ArchiverSetup 2023-07-20 21:32:23 -07:00
bigtedde 683bf7275a redundent comments 2023-07-20 21:04:32 -07:00
bigtedde 0fa103460b removed 'prefix' 2023-07-19 17:24:15 -07:00
bigtedde 975a094e6e generate_archiver_tests added: generate tests by specifying kinds of archivers 2023-07-19 16:23:42 -07:00
bigtedde 8a5664dcfd remote archiver prefix check 2023-07-16 14:01:06 -07:00
bigtedde fcddbc6356 Fixed: camelcase, generate test dupe, init vars declerations, general cleanup 2023-07-16 13:33:54 -07:00
bigtedde 0c899a7985 extract_cmd cleanup 2023-07-13 20:14:04 -04:00
bigtedde bbb5340e8c diff_cmd cleanup 2023-07-13 19:52:59 -04:00
bigtedde 535b336b14 delete_cmd cleanup 2023-07-13 19:37:32 -04:00
bigtedde 3a7ee07cf3 debug_cmds cleanup 2023-07-13 19:33:56 -04:00
bigtedde 225fdb0b72 increased readability in delete_cmd 2023-07-13 17:29:11 -04:00
bigtedde eb37f4b9aa corrupted_archiver changed from fixture to function call 2023-07-13 17:26:12 -04:00
bigtedde 7fea384fa7 removed print statement from transfer_cmd 2023-07-13 17:16:30 -04:00
bigtedde 9a8d5da822 ValueError added in 'open_repository' 2023-07-13 15:51:58 -04:00
bigtedde 73c178d628 cleanup create_cmd 2023-07-13 15:42:50 -04:00
bigtedde b2d8210e5d testsuite/benchmark.py - 'cmd' -> 'cmd_fixture' 2023-07-13 11:45:59 -04:00
bigtedde f502941137 check_cmd cleaned up 2023-07-13 11:27:18 -04:00
bigtedde fdb21af6e6 cleanup bypass_lock_option tests 2023-07-13 11:09:12 -04:00
Ted Lawson 33645ad38a
Repo tests - conversion to pytest (#7626) 2023-07-11 01:40:51 +02:00
Ted Lawson 7df34fc4a6
Archive pytest conversion (#7661)
parameterized stats_progress and timestamp_parsing tests
2023-07-11 01:14:51 +02:00
bigtedde 1e5c62f1a1 test_unix_socket fix 2023-07-09 22:12:03 -04:00
bigtedde 912df41c4a test_unix_socket fix 2023-07-09 21:42:37 -04:00
bigtedde 62bfd5e13a create_cmd changes 2023-07-09 18:32:02 -04:00
bigtedde 2c5f6645b4 changed socket path to secure temp file 2023-07-09 17:46:50 -04:00
bigtedde ed02164b68 fixed fuse_mount CM 2023-07-09 17:32:31 -04:00
bigtedde f1af13e544 removed unittest skips 2023-07-09 17:06:30 -04:00
bigtedde efc4481996 removed erroneous test from init 2023-07-09 16:40:53 -04:00
bigtedde 6cb87e5ff7 transfer_cmd converted 2023-07-09 16:31:44 -04:00
bigtedde 751bac0fb7 tar_cmds converted 2023-07-09 15:57:01 -04:00
bigtedde 6ca4e15c4b fixed issue in test_unix_socket 2023-07-09 15:27:41 -04:00
bigtedde 9a8fb00c10 serve_cmd converted 2023-07-09 15:05:27 -04:00
bigtedde 5cdbf03110 rlist_cmd converted 2023-07-09 14:57:13 -04:00
bigtedde a9cf42f6e3 rlist_cmd 2023-07-09 14:56:12 -04:00
bigtedde 116428cd4f rinfo_cmd converted 2023-07-09 14:41:12 -04:00
bigtedde 0f160cda29 return_codes converted 2023-07-09 14:34:06 -04:00
bigtedde 227f43958f rename_cmd converted 2023-07-09 11:57:57 -04:00
bigtedde c68e0b9936 recreate_cmd converted 2023-07-09 11:50:24 -04:00
bigtedde 673cd4718e rcreate_cmd converted 2023-07-09 11:13:15 -04:00
bigtedde a3bfc4d390 rdelete_cmd converted 2023-07-09 10:43:51 -04:00
bigtedde 216f13831e rcompress_cmd converted 2023-07-08 17:43:30 -04:00
bigtedde a4fc546c8a prune_cmd converted 2023-07-08 17:28:32 -04:00
TW 4dfce1cca4
Merge pull request #7719 from bket/fix_test
Fix failing test on OpenBSD
2023-07-08 02:20:07 +02:00
bigtedde 7e14361700 patterns converted 2023-07-07 17:50:44 -04:00
bigtedde 0a104a3435 mount_cmds converted 2023-07-07 17:48:29 -04:00
bigtedde 91dd71e3b1 lock_cmds converted 2023-07-07 16:49:01 -04:00
bigtedde 08ab71669a list_cmd converted 2023-07-07 16:40:39 -04:00
bigtedde 3cccf19671 key_cmds converted 2023-07-07 15:53:49 -04:00
bigtedde 725149cb8b info_cmd converted, edited generate tests comment 2023-07-07 15:26:50 -04:00
bigtedde b5901eb0a6 merge upstream changes 2023-07-07 15:16:11 -04:00
bigtedde a438176b85 help_cmd converted 2023-07-07 10:08:25 -05:00
Björn Ketelaars 1074089d37 Fix failing test on OpenBSD
A borgbackup-2.0.0b6 test fails on OpenBSD with the message below.

```
=================================== FAILURES ===================================
_____________________________ test_get_runtime_dir _____________________________

path = '/run/user/55/borg', mode = 511, pretty_deadly = True

    def ensure_dir(path, mode=stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO, pretty_deadly=True):
        """
        Ensures that the dir exists with the right permissions.
        1) Make sure the directory exists in a race-free operation
        2) If mode is not None and the directory has been created, give the right
        permissions to the leaf directory. The current umask value is masked out first.
        3) If pretty_deadly is True, catch exceptions, reraise them with a pretty
        message.
        Returns if the directory has been created and has the right permissions,
        An exception otherwise. If a deadly exception happened it is reraised.
        """
        try:
>           os.makedirs(path, mode=mode, exist_ok=True)

build/lib.openbsd-7.3-amd64-cpython-310/borg/helpers/fs.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
```

If `$XDG_RUNTIME_DIR` is not set `platformdirs.user_runtime_dir()`
returns one of 3 different paths
(https://github.com/platformdirs/platformdirs/pull/201). Proposed fix is
to check if `get_runtime_dir()` returns one of these paths.
2023-07-07 15:38:13 +02:00
TW 7914e38160
Merge pull request #7712 from ThomasWaldmann/manifest-item_keys
manifest: move item_keys into config dict, fixes #7710
2023-07-07 00:58:27 +02:00
TW cfbfe2423f
Merge pull request #7676 from RayyanAnsari/paths-win
Properly normalise paths on Windows
2023-07-07 00:42:03 +02:00
TW e63775a316
Merge pull request #7711 from ThomasWaldmann/doc-updates-master
doc updates (master)
2023-07-07 00:30:16 +02:00
Felix Schwarz ae0b3d2fff replace "datetime.utcfromtimestamp" with custom helper to avoid deprecation warnings when using Python 3.12 2023-07-06 21:46:19 +02:00
bigtedde 5bc1bbd3a3 extract_cmd converted 2023-07-04 19:35:48 -05:00
bigtedde 95d48c054a disk_full converted 2023-07-04 18:38:10 -05:00
Thomas Waldmann 51e68c24e4
manifest: move item_keys into config dict, fixes #7710
also: manifest.version == 2 now
2023-07-05 01:11:24 +02:00
bigtedde dfaea063a5 diff_cmd converted 2023-07-04 17:15:15 -05:00
Thomas Waldmann 8db8fd601b
docs: OS X -> macOS 2023-07-04 23:59:44 +02:00
bigtedde 99bf56cfcd delete_cmd converted 2023-07-04 16:53:06 -05:00
bigtedde d18525ae49 debug_cmds added 2023-07-04 16:35:09 -05:00
bigtedde 2cf784d5c6 combined all tests into one single Archiver folder PR 2023-07-04 15:35:51 -05:00
Rayyan Ansari 7e0cdd7c5e testsuite: Enable test_archived_paths on Windows 2023-07-04 19:44:22 +01:00
Rayyan Ansari 54b654e3b1 fs: Properly normalise paths on Windows
Use forward slashes and integrate the drive letter into the path.
2023-07-04 19:44:22 +01:00
Thomas Waldmann 45cda981f9
test_sparse_file: skip test on win32
about 10-50% of the github windows CI runs fail due to
this - root cause unknown.

Example failure:

        # we first check if we could create a sparse input file:
        sparse_support = is_sparse(filename, total_size, hole_size)
        if sparse_support:
            # we could create a sparse input file, so creating a backup of it and
            # extracting it again (as sparse) should also work:
            self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
            self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
            with changedir(self.output_path):
                self.cmd(f"--repo={self.repository_location}", "extract", "test", "--sparse")
            self.assert_dirs_equal("input", "output/input")
            filename = os.path.join(self.output_path, "input", "sparse")
            with open(filename, "rb") as fd:
                # check if file contents are as expected
>               self.assert_equal(fd.read(hole_size), b"\0" * hole_size)
E               AssertionError: b'\x0[8388602 chars]x00\xf0Y\xb5\xe3\xee\xf3\x1f\xe3L\xcf\xae\x92\[159253621 chars]\x00' != b'\x0[8388602 chars]x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0[159383505 chars]\x00'

src/borg/testsuite/archiver/extract_cmd.py:212: AssertionError
2023-06-22 23:10:31 +02:00
Ted Lawson a5c4d0d310
Xattr.py unittest to pytest conversion (#7657) 2023-06-20 16:08:44 +02:00
Tarrailt 616d5e7330
Add --format option to `borg diff`, resolve issue #4634 (#7534)
diff: add --format option

also: refactoring/improvements of BaseFormatter
2023-06-11 22:41:36 +02:00
TW 8506c05ab6
Merge pull request #7642 from Deric-W/typehints
replace `LRUCache` internals with `OrderedDict`
2023-06-11 17:11:41 +02:00
Eric Wolf e683c80c75
replace `LRUCache` internals with `OrderedDict`
Replacing the internals should make the implementation faster
and simpler since the order tracking is done by the `OrderedDict`.

Furthermore, this commit adds type hints to `LRUCache` and
renames the `upd` method to `replace` to make its use more clear.
2023-06-10 20:57:32 +02:00
Thomas Waldmann 518c4fbca8
skip test_import_tar_with_dotdot for binary testing 2023-06-10 14:17:07 +02:00
Peter Gerber 438cf2e7ef
Sanitize paths during archive creation/extraction/...
Paths are not always sanitized when creating an archive and,
more importantly, never when extracting one. The following example
shows how this can be used to attempt to write a file outside the
extraction directory:

$ echo abcdef | borg create -r ~/borg/a --stdin-name x/../../../../../etc/shadow archive-1 -
$ borg list -r ~/borg/a archive-1
-rw-rw---- root   root          7 Sun, 2022-10-23 19:14:27  x/../../../../../etc/shadow
$ mkdir borg/target
$ cd borg/target
$ borg extract -r ~/borg/a archive-1
x/../../../../../etc/shadow: makedirs: [Errno 13] Permission denied: '/home/user/borg/target/x/../../../../../etc'

Note that Borg tries to extract the file to /etc/shadow and the
permission error is a result of the user not having access.

This patch ensures file names are sanitized before archiving.
As for files extracted from the archive, paths are sanitized
by making all paths relative, removing '.' elements, and removing
superfluous slashes (as in '//'). '..' elements, however, are
rejected outright. The reasoning here is that it is easy to start
a path with './' or insert a '//' by accident (e.g. via --stdin-name
or import-tar). '..', however, seem unlikely to be the result
of an accident and could indicate a tampered repository.

With paths being sanitized as they are being read, this "errors"
will be corrected during the `borg transfer` required when upgrading
to Borg 2. Hence, the sanitation, when reading the archive,
can be removed once support for reading v1 repositories is dropped.
V2 repository will not contain non-sanitized paths. Of course,
a check for absolute paths and '..' elements needs to kept in
place to detect tempered archives.

I recommend treating this as a security issue. I see the following
cases where extracting a file outside the extraction path could
constitute a security risk:

a) When extraction is done as a different user than archive
creation. The user that created the archive may be able to
get a file overwritten as a different user.
b) When the archive is created on one host and extracted on
another. The user that created the archive may be able to
get a file overwritten on another host.
c) When an archive is created and extracted after a OS reinstall.
When a host is suspected compromised, it is common to reinstall
(or set up a new machine), extract the backups and then evaluate
their integrity. A user that manipulates the archive before such
a reinstall may be able to get a file overwritten outside the
extraction path and may evade integrity checks.

Notably absent is the creation and extraction on the same host as
the same user. In such case, an adversary must be assumed to be able
to replace any file directly.

This also (partially) fixes #7099.
2023-06-07 23:23:53 +02:00
Thomas Waldmann ae97584218
fix logging, add some comments
shutting down logging is problematic as it is global
and we do multi-threaded execution, e.g. in tests.

thus, rather just flush the important loggers and keep
them alive.
2023-06-06 21:13:31 +02:00
Thomas Waldmann ffc59dd071
implement unix domain (ipc) socket support
server (listening) side:
borg serve --socket  # default location
borg serve --socket=/path/to/socket

client side:
borg -r socket:///path/to/repo create ...
borg --socket=/path/to/socket -r socket:///path/to/repo ...

served connections:
- for ssh: proto: one connection
- for socket: proto: many connections (one after the other)

The socket has user and group permissions (770).

skip socket tests on win32, they hang infinitely, until
github CI terminates them after 60 minutes.

socket tests: use unique socket name

don't use the standard / default socket name, otherwise tests
running in parallel would interfere with each other by using
the same socket / the same borg serve process.

write a .pid file, clean up .pid and .sock file at exit

add stderr print for accepted/finished socket connection
2023-06-06 21:12:54 +02:00
Thomas Waldmann 7878a34fd4
add get_runtime_dir / BORG_RUNTIME_DIR, tests, docs 2023-06-06 11:58:48 +02:00
TW 9f51600f20
Merge pull request #7627 from ThomasWaldmann/fix-chunksize-distrib-test-master
fix test_buzhash_chunksize_distribution
2023-06-06 10:43:53 +02:00
Thomas Waldmann 6625fb52ac
fix test_buzhash_chunksize_distribution
the last chunk can be smaller than 2**min_exp.
2023-06-06 10:09:53 +02:00
bigtedde 83d821171e Parameterize 'version' and 'item' tests 2023-06-04 14:38:22 -07:00
TW e70b5b1e94
Merge pull request #7620 from bigtedde/parameterize_test_compress
Parametrize compression tests
2023-06-02 23:03:24 +02:00
bigtedde e0f6685498 parameterized compression tests 2023-06-02 12:55:35 -07:00
David Rambo 4efc7cd0bd Add support and tests for shell-style alternatives
Code review fixes

Remove empty line
2023-05-31 15:38:05 -07:00
Thomas Waldmann e2ea5cf164
tests: fix usage of .reopen()
also:
add missing param to RemoteRepositoryTestCase.open method, but ignore it.
2023-05-29 23:02:42 +02:00
Thomas Waldmann 746cef1cba
teardown logging in exec_cmd
for normal borg command invocation:
- logging is set up in Archiver.run
- the atexit handler calls logging.shutdown when process terminates

for tests:
- Archiver.run called by exec_cmd
- no atexit handler executed as process lives on
- borg.logger.teardown (calls shutdown and configured=False) now
  called in exec_cmd
2023-05-29 22:40:50 +02:00
Thomas Waldmann c3a4568870
channel progress output via logging system
- simplify progress output (no \r, no terminal size related tweaks)
- emit progress output via the logging system (so it does not use stderr
  of borg serve)
- progress code always logs a json string, the json has all needed
  to either do json log output or plain text log output.
- use formatters to generate plain or json output from that.
- clean up setup_logging
- use a StderrHandler that always uses the **current** sys.stderr
- tweak TestPassphrase to not accidentally trigger just because of seeing 12 in output
2023-05-29 22:40:47 +02:00
Thomas Waldmann 0be545dc45
remove ProgressIndicatorEndless (not used) 2023-05-29 22:40:45 +02:00
Thomas Waldmann e351e67aee
RepositoryServer: do not use stderr for logging, see #7604
Instead, install a handler that sends the LogRecord dicts to a queue.
That queue is then emptied in the borg serve main loop and
the LogRecords are sent msgpacked via stdout to the client,
similar to the RPC results.

On the client side, the LogRecords are recreated from the
received dicts and fed into the clientside logging system.

As we use msgpacked LogRecord dicts, we don't need JSON for
this purpose on the borg serve side any more.
On the client side, the LogRecords will then be either formatted
as normal text or as JSON log output (by the clientside log
formatter).
2023-05-29 22:40:42 +02:00