@@ -1657,3 +1657,56 @@ async def test_use_datetime_false(app_client, load_test_data, txn_client, monkey
16571657
16581658 assert "test-item-datetime-only" not in found_ids
16591659 assert "test-item-start-end-only" in found_ids
1660+
1661+
1662+ @pytest .mark .asyncio
1663+ async def test_hide_private_data_from_item (app_client , txn_client , load_test_data ):
1664+ os .environ ["EXCLUDED_FROM_ITEMS" ] = "private_data,other_sensitive_field"
1665+
1666+ test_collection = load_test_data ("test_collection.json" )
1667+ test_collection_id = "test-collection-private-data"
1668+ test_collection ["id" ] = test_collection_id
1669+ await create_collection (txn_client , test_collection )
1670+
1671+ test_item = load_test_data ("test_item.json" )
1672+ test_item_id = "test-item-private-data"
1673+ test_item ["id" ] = test_item_id
1674+ test_item ["collection" ] = test_collection_id
1675+ test_item ["private_data" ] = {"item_secret" : "sensitive_info" }
1676+ test_item ["other_sensitive_field" ] = "confidential_value"
1677+ await create_item (txn_client , test_item )
1678+
1679+ # Test /collections/{collection_id}/items
1680+ resp = await app_client .get (f"/collections/{ test_collection_id } /items" )
1681+ assert resp .status_code == 200
1682+ resp_json = resp .json ()
1683+ item = resp_json ["features" ][0 ]
1684+ assert "private_data" not in item
1685+ assert "other_sensitive_field" not in item
1686+
1687+ # Test /collections/{collection_id}/items/{item_id}
1688+ resp = await app_client .get (
1689+ f"/collections/{ test_collection_id } /items/{ test_item_id } "
1690+ )
1691+ assert resp .status_code == 200
1692+ resp_json = resp .json ()
1693+ assert "private_data" not in resp_json
1694+ assert "other_sensitive_field" not in resp_json
1695+
1696+ # Test GET /search
1697+ resp = await app_client .get (f"/search?collections={ test_collection_id } " )
1698+ assert resp .status_code == 200
1699+ resp_json = resp .json ()
1700+ item = resp_json ["features" ][0 ]
1701+ assert "private_data" not in item
1702+ assert "other_sensitive_field" not in item
1703+
1704+ # Test POST /search
1705+ resp = await app_client .post ("/search" , json = {"collections" : [test_collection_id ]})
1706+ assert resp .status_code == 200
1707+ resp_json = resp .json ()
1708+ item = resp_json ["features" ][0 ]
1709+ assert "private_data" not in item
1710+ assert "other_sensitive_field" not in item
1711+
1712+ del os .environ ["EXCLUDED_FROM_ITEMS" ]
0 commit comments