|
20 | 20 | import tempfile |
21 | 21 | import threading |
22 | 22 | import uuid |
| 23 | +from datetime import datetime |
23 | 24 | from typing import Any |
24 | 25 | from unittest import mock |
25 | 26 |
|
|
30 | 31 | from botocore.credentials import Credentials |
31 | 32 | from fsspec.implementations.local import LocalFileSystem |
32 | 33 | from fsspec.spec import AbstractFileSystem |
| 34 | +from google.oauth2.credentials import Credentials as GoogleCredentials |
33 | 35 | from requests_mock import Mocker |
34 | 36 |
|
35 | 37 | from pyiceberg.catalog.rest.auth import AUTH_MANAGER |
@@ -760,6 +762,29 @@ def test_adls_account_name_not_overridden_when_in_properties() -> None: |
760 | 762 | ) |
761 | 763 |
|
762 | 764 |
|
| 765 | +def test_fsspec_gcs_token_with_expiry() -> None: |
| 766 | + """Test that a GCS token with an expiry is passed to gcsfs as google-auth credentials.""" |
| 767 | + properties: Properties = {"gcs.oauth2.token": "token", "gcs.oauth2.token-expires-at": "1700000000000"} |
| 768 | + |
| 769 | + with mock.patch("gcsfs.GCSFileSystem") as mock_gcsfs: |
| 770 | + FsspecFileIO(properties=properties).new_input(location="gs://bucket/path/file.parquet") |
| 771 | + |
| 772 | + token = mock_gcsfs.call_args.kwargs["token"] |
| 773 | + assert isinstance(token, GoogleCredentials) |
| 774 | + assert token.token == "token" |
| 775 | + assert token.expiry == datetime(2023, 11, 14, 22, 13, 20) |
| 776 | + |
| 777 | + |
| 778 | +def test_fsspec_gcs_token_without_expiry() -> None: |
| 779 | + """Test that a GCS token without an expiry is passed to gcsfs unchanged.""" |
| 780 | + properties: Properties = {"gcs.oauth2.token": "token"} |
| 781 | + |
| 782 | + with mock.patch("gcsfs.GCSFileSystem") as mock_gcsfs: |
| 783 | + FsspecFileIO(properties=properties).new_input(location="gs://bucket/path/file.parquet") |
| 784 | + |
| 785 | + assert mock_gcsfs.call_args.kwargs["token"] == "token" |
| 786 | + |
| 787 | + |
763 | 788 | @pytest.mark.gcs |
764 | 789 | def test_fsspec_new_input_file_gcs(fsspec_fileio_gcs: FsspecFileIO) -> None: |
765 | 790 | """Test creating a new input file from a fsspec file-io""" |
|
0 commit comments