@@ -1657,3 +1657,55 @@ 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_true (app_client , txn_client , load_test_data ):
1664+ """Test hiding the private data from response"""
1665+
1666+ os .environ ["PRIVATE_DATA_FIELD" ] = "private_field"
1667+ os .environ ["HIDE_PRIVATE_DATA" ] = "true"
1668+
1669+ test_collection = load_test_data ("test_collection.json" )
1670+ test_collection_id = "test-collection-hide-private-data"
1671+ test_collection ["id" ] = test_collection_id
1672+ await create_collection (txn_client , test_collection )
1673+
1674+ test_item = load_test_data ("test_item.json" )
1675+ test_item_id = "test-item-hide-private-data"
1676+ test_item ["id" ] = test_item_id
1677+ test_item ["collection" ] = test_collection_id
1678+ test_item ["private_data" ] = {"item_secret" : "sensitive_info" }
1679+ await create_item (txn_client , test_item )
1680+
1681+ # Test /collections/{collection_id}/items
1682+ resp = await app_client .get (f"/collections/{ test_collection_id } /items" )
1683+ assert resp .status_code == 200
1684+ resp_json = resp .json ()
1685+ item = resp_json ["features" ][0 ]
1686+ assert "private_data" not in item
1687+
1688+ # Test /collections/{collection_id}/items/{item_id}
1689+ resp = await app_client .get (
1690+ f"/collections/{ test_collection_id } /items/{ test_item_id } "
1691+ )
1692+ assert resp .status_code == 200
1693+ resp_json = resp .json ()
1694+ assert "private_data" 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+
1703+ # Test POST /search
1704+ resp = await app_client .post ("/search" , json = {"collections" : [test_collection_id ]})
1705+ assert resp .status_code == 200
1706+ resp_json = resp .json ()
1707+ item = resp_json ["features" ][0 ]
1708+ assert "private_data" not in item
1709+
1710+ del os .environ ["PRIVATE_DATA_FIELD" ]
1711+ del os .environ ["HIDE_PRIVATE_DATA" ]
0 commit comments