Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion b2sdk/_internal/account_info/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_bucket_name_or_none_from_bucket_id(self, bucket_id: str) -> str | None:
return None

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

def save_bucket(self, bucket):
self.buckets[bucket.id_] = bucket
Expand Down
8 changes: 8 additions & 0 deletions b2sdk/_internal/raw_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,14 @@ def authorize_account(self, realm_url, application_key_id, application_key):

allowed = key_sim.get_allowed()

buckets = allowed.get('buckets')
if buckets:
for item in buckets:
try:
item['name'] = self.bucket_id_to_bucket[item['id']].bucket_name
except KeyError:
item['name'] = None

return dict(
accountId=key_sim.account_id,
authorizationToken=auth_token,
Expand Down
6 changes: 3 additions & 3 deletions b2sdk/_internal/scan/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ def make_full_path(self, file_name):
# Generate the full path to the file
full_path = os.path.normpath(os.path.join(self.root, file_name))

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

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

return full_path
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+local_folder_make_full_path.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incorrect path check in `LocalFolder.make_full_path`.
1 change: 1 addition & 0 deletions changelog.d/+raw_simulator_bucket_name_mapping.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bucket name mapping in `RawSimulator.authorize_account()`.
1 change: 1 addition & 0 deletions changelog.d/+stub_account_info_list_bucket_ids.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix broken `StubAccountInfo.list_bucket_names_ids()`.
46 changes: 46 additions & 0 deletions test/unit/scan/test_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
######################################################################
#
# File: test/unit/scan/test_folder.py
#
# Copyright 2025 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

import platform
from pathlib import Path

import pytest

from b2sdk._internal.scan.exception import UnsupportedFilename
from b2sdk._internal.scan.folder import LocalFolder


@pytest.mark.skipif(
platform.system() == 'Windows',
reason="Windows doesn't allow / or \\ in filenames",
)
class TestFolder:
@pytest.fixture
def root_path(self, tmp_path: Path):
return tmp_path / 'dir'

@pytest.fixture
def folder(self, root_path: Path):
return LocalFolder(str(root_path))

@pytest.mark.parametrize('file_path_str', ['dir/foo.txt', 'dir/foo/bar.txt', 'foo.txt'])
def test_make_full_path(self, folder: LocalFolder, root_path: Path, file_path_str: str):
file_path = root_path / file_path_str
assert folder.make_full_path(str(file_path)) == str(root_path / file_path_str)

@pytest.mark.parametrize('file_path_str', ['invalid/test.txt', 'dirinvalid.txt'])
def test_make_full_path_invalid_prefix(
self, folder: LocalFolder, tmp_path: Path, file_path_str: str
):
file_path = tmp_path / file_path_str

with pytest.raises(UnsupportedFilename):
folder.make_full_path(str(file_path))