|
104 | 104 | Capability.V1_DELETE_TABLE, |
105 | 105 | Capability.V1_RENAME_TABLE, |
106 | 106 | Capability.V1_REGISTER_TABLE, |
107 | | - Capability.V1_LOAD_CREDENTIALS, |
108 | 107 | Capability.V1_LIST_VIEWS, |
109 | 108 | Capability.V1_LOAD_VIEW, |
110 | 109 | Capability.V1_VIEW_EXISTS, |
@@ -1452,10 +1451,19 @@ def test_load_table_200_loading_mode( |
1452 | 1451 |
|
1453 | 1452 |
|
1454 | 1453 | def test_load_table_honor_access_delegation( |
1455 | | - rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any] |
| 1454 | + requests_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any] |
1456 | 1455 | ) -> None: |
| 1456 | + requests_mock.get( |
| 1457 | + f"{TEST_URI}v1/config", |
| 1458 | + json={ |
| 1459 | + "defaults": {}, |
| 1460 | + "overrides": {}, |
| 1461 | + "endpoints": [str(endpoint) for endpoint in [*TEST_SUPPORTED_ENDPOINTS, Capability.V1_LOAD_CREDENTIALS]], |
| 1462 | + }, |
| 1463 | + status_code=200, |
| 1464 | + ) |
1457 | 1465 | test_headers_with_remote_signing = {**TEST_HEADERS, "X-Iceberg-Access-Delegation": "remote-signing"} |
1458 | | - rest_mock.get( |
| 1466 | + requests_mock.get( |
1459 | 1467 | f"{TEST_URI}v1/namespaces/fokko/tables/table", |
1460 | 1468 | json=example_table_metadata_with_snapshot_v1_rest_json, |
1461 | 1469 | status_code=200, |
@@ -3114,9 +3122,20 @@ def test_resolve_storage_credentials_empty() -> None: |
3114 | 3122 | assert RestCatalog._resolve_storage_credentials([], None) == {} |
3115 | 3123 |
|
3116 | 3124 |
|
3117 | | -def test_load_table_with_storage_credentials(rest_mock: Mocker, example_table_metadata_with_snapshot_v1: dict[str, Any]) -> None: |
| 3125 | +def test_load_table_with_storage_credentials( |
| 3126 | + requests_mock: Mocker, example_table_metadata_with_snapshot_v1: dict[str, Any] |
| 3127 | +) -> None: |
| 3128 | + requests_mock.get( |
| 3129 | + f"{TEST_URI}v1/config", |
| 3130 | + json={ |
| 3131 | + "defaults": {}, |
| 3132 | + "overrides": {}, |
| 3133 | + "endpoints": [str(endpoint) for endpoint in [*TEST_SUPPORTED_ENDPOINTS, Capability.V1_LOAD_CREDENTIALS]], |
| 3134 | + }, |
| 3135 | + status_code=200, |
| 3136 | + ) |
3118 | 3137 | metadata_location = "s3://warehouse/database/table/metadata/00001.metadata.json" |
3119 | | - rest_mock.get( |
| 3138 | + requests_mock.get( |
3120 | 3139 | f"{TEST_URI}v1/namespaces/fokko/tables/table", |
3121 | 3140 | json={ |
3122 | 3141 | "metadata-location": metadata_location, |
@@ -3146,10 +3165,78 @@ def test_load_table_with_storage_credentials(rest_mock: Mocker, example_table_me |
3146 | 3165 | assert table.io.properties["s3.access-key-id"] == "vended-key" |
3147 | 3166 | assert table.io.properties["s3.secret-access-key"] == "vended-secret" |
3148 | 3167 | assert table.io.properties["s3.session-token"] == "vended-token" |
| 3168 | + assert len(requests_mock.request_history) == 2 |
3149 | 3169 |
|
3150 | 3170 |
|
3151 | | -def test_load_credentials_with_longest_prefix(rest_mock: Mocker) -> None: |
3152 | | - rest_mock.get( |
| 3171 | +def test_load_table_loads_credentials_when_endpoint_supported( |
| 3172 | + requests_mock: Mocker, example_table_metadata_with_snapshot_v1: dict[str, Any] |
| 3173 | +) -> None: |
| 3174 | + requests_mock.get( |
| 3175 | + f"{TEST_URI}v1/config", |
| 3176 | + json={ |
| 3177 | + "defaults": {}, |
| 3178 | + "overrides": {}, |
| 3179 | + "endpoints": [str(endpoint) for endpoint in [*TEST_SUPPORTED_ENDPOINTS, Capability.V1_LOAD_CREDENTIALS]], |
| 3180 | + }, |
| 3181 | + status_code=200, |
| 3182 | + ) |
| 3183 | + metadata_location = "s3://warehouse/database/table/metadata/00001.metadata.json" |
| 3184 | + requests_mock.get( |
| 3185 | + f"{TEST_URI}v1/namespaces/fokko/tables/table", |
| 3186 | + json={ |
| 3187 | + "metadata-location": metadata_location, |
| 3188 | + "metadata": example_table_metadata_with_snapshot_v1, |
| 3189 | + "config": { |
| 3190 | + "s3.access-key-id": "from-config", |
| 3191 | + "s3.secret-access-key": "from-config-secret", |
| 3192 | + }, |
| 3193 | + }, |
| 3194 | + status_code=200, |
| 3195 | + request_headers=TEST_HEADERS, |
| 3196 | + ) |
| 3197 | + requests_mock.get( |
| 3198 | + f"{TEST_URI}v1/namespaces/fokko/tables/table/credentials", |
| 3199 | + json={ |
| 3200 | + "storage-credentials": [ |
| 3201 | + { |
| 3202 | + "prefix": "s3://warehouse/database/", |
| 3203 | + "config": {"s3.access-key-id": "short-prefix-key"}, |
| 3204 | + }, |
| 3205 | + { |
| 3206 | + "prefix": "s3://warehouse/database/table", |
| 3207 | + "config": { |
| 3208 | + "s3.access-key-id": "long-prefix-key", |
| 3209 | + "s3.secret-access-key": "long-prefix-secret", |
| 3210 | + }, |
| 3211 | + }, |
| 3212 | + ], |
| 3213 | + }, |
| 3214 | + status_code=200, |
| 3215 | + request_headers=TEST_HEADERS, |
| 3216 | + ) |
| 3217 | + catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) |
| 3218 | + table = catalog.load_table(("fokko", "table")) |
| 3219 | + |
| 3220 | + assert table.io.properties["s3.access-key-id"] == "long-prefix-key" |
| 3221 | + assert table.io.properties["s3.secret-access-key"] == "long-prefix-secret" |
| 3222 | + assert [request.url for request in requests_mock.request_history] == [ |
| 3223 | + f"{TEST_URI}v1/config", |
| 3224 | + f"{TEST_URI}v1/namespaces/fokko/tables/table", |
| 3225 | + f"{TEST_URI}v1/namespaces/fokko/tables/table/credentials", |
| 3226 | + ] |
| 3227 | + |
| 3228 | + |
| 3229 | +def test_load_credentials_with_longest_prefix(requests_mock: Mocker) -> None: |
| 3230 | + requests_mock.get( |
| 3231 | + f"{TEST_URI}v1/config", |
| 3232 | + json={ |
| 3233 | + "defaults": {}, |
| 3234 | + "overrides": {}, |
| 3235 | + "endpoints": [str(endpoint) for endpoint in [*TEST_SUPPORTED_ENDPOINTS, Capability.V1_LOAD_CREDENTIALS]], |
| 3236 | + }, |
| 3237 | + status_code=200, |
| 3238 | + ) |
| 3239 | + requests_mock.get( |
3153 | 3240 | f"{TEST_URI}v1/namespaces/fokko/tables/table/credentials", |
3154 | 3241 | json={ |
3155 | 3242 | "storage-credentials": [ |
@@ -3177,7 +3264,7 @@ def test_load_credentials_with_longest_prefix(rest_mock: Mocker) -> None: |
3177 | 3264 | ) |
3178 | 3265 |
|
3179 | 3266 | assert credentials == {"s3.access-key-id": "long-prefix-key", "s3.secret-access-key": "long-prefix-secret"} |
3180 | | - assert rest_mock.last_request.url == f"{TEST_URI}v1/namespaces/fokko/tables/table/credentials" |
| 3267 | + assert requests_mock.last_request.url == f"{TEST_URI}v1/namespaces/fokko/tables/table/credentials" |
3181 | 3268 |
|
3182 | 3269 |
|
3183 | 3270 | def test_load_table_without_storage_credentials( |
|
0 commit comments