Skip to content

Commit 9f48b27

Browse files
Merge pull request #543 from reef-technologies/fix-raw-simulator-authorize-account
Various fixes
2 parents fa4a58b + cdd4d5b commit 9f48b27

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

b2sdk/_internal/account_info/stub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_bucket_name_or_none_from_bucket_id(self, bucket_id: str) -> str | None:
7777
return None
7878

7979
def list_bucket_names_ids(self) -> list[tuple[str, str]]:
80-
return list((bucket.bucket_name, bucket.id_) for bucket in self.buckets.values())
80+
return list((bucket.name, bucket.id_) for bucket in self.buckets.values())
8181

8282
def save_bucket(self, bucket):
8383
self.buckets[bucket.id_] = bucket

b2sdk/_internal/raw_simulator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,14 @@ def authorize_account(self, realm_url, application_key_id, application_key):
14041404

14051405
allowed = key_sim.get_allowed()
14061406

1407+
buckets = allowed.get('buckets')
1408+
if buckets:
1409+
for item in buckets:
1410+
try:
1411+
item['name'] = self.bucket_id_to_bucket[item['id']].bucket_name
1412+
except KeyError:
1413+
item['name'] = None
1414+
14071415
return dict(
14081416
accountId=key_sim.account_id,
14091417
authorizationToken=auth_token,

b2sdk/_internal/scan/folder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ def make_full_path(self, file_name):
180180
# Generate the full path to the file
181181
full_path = os.path.normpath(os.path.join(self.root, file_name))
182182

183-
# Get the common prefix between the new full_path and self.root
184-
common_prefix = os.path.commonprefix([full_path, self.root])
183+
# Get the common path between the new full_path and self.root
184+
common_path = os.path.commonpath([full_path, self.root])
185185

186186
# Ensure the new full_path is inside the self.root directory
187-
if common_prefix != self.root:
187+
if common_path != self.root:
188188
raise UnsupportedFilename('illegal file name', full_path)
189189

190190
return full_path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix incorrect path check in `LocalFolder.make_full_path`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bucket name mapping in `RawSimulator.authorize_account()`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix broken `StubAccountInfo.list_bucket_names_ids()`.

test/unit/scan/test_folder.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
######################################################################
2+
#
3+
# File: test/unit/scan/test_folder.py
4+
#
5+
# Copyright 2025 Backblaze Inc. All Rights Reserved.
6+
#
7+
# License https://www.backblaze.com/using_b2_code.html
8+
#
9+
######################################################################
10+
from __future__ import annotations
11+
12+
import platform
13+
from pathlib import Path
14+
15+
import pytest
16+
17+
from b2sdk._internal.scan.exception import UnsupportedFilename
18+
from b2sdk._internal.scan.folder import LocalFolder
19+
20+
21+
@pytest.mark.skipif(
22+
platform.system() == 'Windows',
23+
reason="Windows doesn't allow / or \\ in filenames",
24+
)
25+
class TestFolder:
26+
@pytest.fixture
27+
def root_path(self, tmp_path: Path):
28+
return tmp_path / 'dir'
29+
30+
@pytest.fixture
31+
def folder(self, root_path: Path):
32+
return LocalFolder(str(root_path))
33+
34+
@pytest.mark.parametrize('file_path_str', ['dir/foo.txt', 'dir/foo/bar.txt', 'foo.txt'])
35+
def test_make_full_path(self, folder: LocalFolder, root_path: Path, file_path_str: str):
36+
file_path = root_path / file_path_str
37+
assert folder.make_full_path(str(file_path)) == str(root_path / file_path_str)
38+
39+
@pytest.mark.parametrize('file_path_str', ['invalid/test.txt', 'dirinvalid.txt'])
40+
def test_make_full_path_invalid_prefix(
41+
self, folder: LocalFolder, tmp_path: Path, file_path_str: str
42+
):
43+
file_path = tmp_path / file_path_str
44+
45+
with pytest.raises(UnsupportedFilename):
46+
folder.make_full_path(str(file_path))

0 commit comments

Comments
 (0)