1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-26 16:04:06 +00:00

tests: do not look up uid 0 / gid 0, but current process uid/gid

some systems do not have uid/gid 0 (windows).
This commit is contained in:
Thomas Waldmann 2023-01-15 01:38:13 +01:00
parent 4dcc48f5c4
commit ff545033e3
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -1,4 +1,5 @@
import json
import os
from collections import OrderedDict
from datetime import datetime, timezone
from io import StringIO
@ -295,18 +296,22 @@ def __next__(self):
def test_get_item_uid_gid():
# test requires that:
# - a name for user 0 and group 0 exists, usually root:root or root:wheel.
# - a user/group name for the current process' real uid/gid exists.
# - a system user/group udoesnotexist:gdoesnotexist does NOT exist.
user0, group0 = uid2user(0), gid2group(0)
try:
puid, pgid = os.getuid(), os.getgid() # UNIX only
except AttributeError:
puid, pgid = 0, 0
puser, pgroup = uid2user(puid), gid2group(pgid)
# this is intentionally a "strange" item, with not matching ids/names.
item = Item(path="filename", uid=1, gid=2, user=user0, group=group0)
item = Item(path="filename", uid=1, gid=2, user=puser, group=pgroup)
uid, gid = get_item_uid_gid(item, numeric=False)
# these are found via a name-to-id lookup
assert uid == 0
assert gid == 0
assert uid == puid
assert gid == pgid
uid, gid = get_item_uid_gid(item, numeric=True)
# these are directly taken from the item.uid and .gid
@ -319,7 +324,7 @@ def test_get_item_uid_gid():
assert gid == 4
# item metadata broken, has negative ids.
item = Item(path="filename", uid=-1, gid=-2, user=user0, group=group0)
item = Item(path="filename", uid=-1, gid=-2, user=puser, group=pgroup)
uid, gid = get_item_uid_gid(item, numeric=True)
# use the uid/gid defaults (which both default to 0).