Skip to content

Commit 1e71507

Browse files
committed
better java match
1 parent 957c405 commit 1e71507

File tree

6 files changed

+12
-335
lines changed

6 files changed

+12
-335
lines changed

src/firebolt/common/token_storage.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/firebolt/utils/file_operations.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ def generate_salt() -> str:
7474
def generate_encrypted_file_name(cache_key: str, encryption_key: str) -> str:
7575
"""Generate encrypted file name from cache key using AES-GCM encryption.
7676
77-
This implementation matches the Java EncryptionService to ensure compatibility.
77+
This implementation matches the Java FilenameGenerator to ensure compatibility.
7878
7979
Args:
8080
cache_key (str): The cache key to encrypt
8181
encryption_key (str): The encryption key
8282
8383
Returns:
84-
str: Base64 encoded AES-GCM encrypted filename
84+
str: Double base64 encoded AES-GCM encrypted filename ending in .txt
8585
"""
8686
# Derive AES key using SHA-256
8787
key_hash = sha256(encryption_key.encode("utf-8")).digest()
@@ -96,5 +96,11 @@ def generate_encrypted_file_name(cache_key: str, encryption_key: str) -> str:
9696
aesgcm = AESGCM(aes_key)
9797
encrypted_data = aesgcm.encrypt(nonce, cache_key.encode("utf-8"), None)
9898

99-
# Base64 encode
100-
return b64encode(encrypted_data).decode("ascii")
99+
first_base64 = b64encode(encrypted_data).decode("ascii")
100+
101+
# URL-safe base64 encode without padding (matches Java FilenameGenerator)
102+
second_base64 = (
103+
urlsafe_b64encode(first_base64.encode("ascii")).decode("ascii").rstrip("=")
104+
)
105+
106+
return second_base64 + ".txt"

src/firebolt/utils/token_storage.py

Lines changed: 0 additions & 181 deletions
This file was deleted.

tests/unit/client/auth/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_auth_adds_header(access_token: str) -> None:
8585

8686

8787
@mark.nofakefs
88-
def test_auth_token_storage(
88+
def test_auth_token_caching(
8989
httpx_mock: HTTPXMock,
9090
client_id: str,
9191
client_secret: str,

tests/unit/client/auth/test_auth_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def test_auth_adds_header(access_token: str) -> None:
8888

8989

9090
@mark.nofakefs
91-
async def test_auth_token_storage(
91+
async def test_auth_token_caching(
9292
httpx_mock: HTTPXMock,
9393
client_id: str,
9494
client_secret: str,

tests/unit/common/test_token_storage.py

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)