|
32 | 32 | from tests.daily.connectors.google_drive.consts_and_utils import FOLDER_2_URL
|
33 | 33 | from tests.daily.connectors.google_drive.consts_and_utils import FOLDER_3_URL
|
34 | 34 | from tests.daily.connectors.google_drive.consts_and_utils import load_all_docs
|
| 35 | +from tests.daily.connectors.google_drive.consts_and_utils import ( |
| 36 | + RESTRICTED_ACCESS_FOLDER_URL, |
| 37 | +) |
35 | 38 | from tests.daily.connectors.google_drive.consts_and_utils import SECTIONS_FILE_IDS
|
36 | 39 | from tests.daily.connectors.google_drive.consts_and_utils import SHARED_DRIVE_1_FILE_IDS
|
37 | 40 | from tests.daily.connectors.google_drive.consts_and_utils import SHARED_DRIVE_1_URL
|
38 | 41 | from tests.daily.connectors.google_drive.consts_and_utils import SHARED_DRIVE_2_FILE_IDS
|
39 | 42 | from tests.daily.connectors.google_drive.consts_and_utils import TEST_USER_1_EMAIL
|
40 | 43 | from tests.daily.connectors.google_drive.consts_and_utils import TEST_USER_1_FILE_IDS
|
| 44 | +from tests.daily.connectors.google_drive.consts_and_utils import TEST_USER_2_EMAIL |
41 | 45 | from tests.daily.connectors.google_drive.consts_and_utils import TEST_USER_2_FILE_IDS
|
42 | 46 | from tests.daily.connectors.google_drive.consts_and_utils import TEST_USER_3_EMAIL
|
43 | 47 | from tests.daily.connectors.google_drive.consts_and_utils import TEST_USER_3_FILE_IDS
|
@@ -111,7 +115,16 @@ def test_include_shared_drives_only_with_size_threshold(
|
111 | 115 | retrieved_docs = load_all_docs(connector)
|
112 | 116 |
|
113 | 117 | # 2 extra files from shared drive owned by non-admin and not shared with admin
|
114 |
| - assert len(retrieved_docs) == 52 |
| 118 | + # TODO: added a file in a "restricted" folder, which the connector sometimes succeeds at finding |
| 119 | + # and adding. Specifically, our shared drive retrieval logic currently assumes that |
| 120 | + # "having access to a shared drive" means that the connector has access to all files in the shared drive. |
| 121 | + # therefore when a user successfully retrieves a shared drive, we mark it as "done". If that user's |
| 122 | + # access is restricted for a folder in the shared drive, the connector will not retrieve that folder. |
| 123 | + # If instead someone with FULL access to the shared drive retrieves it, the connector will retrieve |
| 124 | + # the folder and all its files. There is currently no consistency to the order of assignment of users |
| 125 | + # to shared drives, so this is a heisenbug. When we guarantee that restricted folders are retrieved, |
| 126 | + # we can change this to 53 |
| 127 | + assert len(retrieved_docs) == 52 or len(retrieved_docs) == 53 |
115 | 128 |
|
116 | 129 |
|
117 | 130 | @patch(
|
@@ -149,7 +162,8 @@ def test_include_shared_drives_only(
|
149 | 162 | )
|
150 | 163 |
|
151 | 164 | # 2 extra files from shared drive owned by non-admin and not shared with admin
|
152 |
| - assert len(retrieved_docs) == 53 |
| 165 | + # TODO: switch to 54 when restricted access issue is resolved |
| 166 | + assert len(retrieved_docs) == 53 or len(retrieved_docs) == 54 |
153 | 167 |
|
154 | 168 | assert_expected_docs_in_retrieved_docs(
|
155 | 169 | retrieved_docs=retrieved_docs,
|
@@ -423,3 +437,43 @@ def get_specific_folders_in_my_drive(
|
423 | 437 | retrieved_docs=retrieved_docs,
|
424 | 438 | expected_file_ids=expected_file_ids,
|
425 | 439 | )
|
| 440 | + |
| 441 | + |
| 442 | +@patch( |
| 443 | + "onyx.file_processing.extract_file_text.get_unstructured_api_key", |
| 444 | + return_value=None, |
| 445 | +) |
| 446 | +def test_specific_user_emails_restricted_folder( |
| 447 | + mock_get_api_key: MagicMock, |
| 448 | + google_drive_service_acct_connector_factory: Callable[..., GoogleDriveConnector], |
| 449 | +) -> None: |
| 450 | + print("\n\nRunning test_specific_user_emails_restricted_folder") |
| 451 | + |
| 452 | + # Test with admin email - should get 1 doc |
| 453 | + admin_connector = google_drive_service_acct_connector_factory( |
| 454 | + primary_admin_email=ADMIN_EMAIL, |
| 455 | + include_shared_drives=False, |
| 456 | + include_my_drives=False, |
| 457 | + include_files_shared_with_me=False, |
| 458 | + shared_folder_urls=RESTRICTED_ACCESS_FOLDER_URL, |
| 459 | + shared_drive_urls=None, |
| 460 | + my_drive_emails=None, |
| 461 | + specific_user_emails=ADMIN_EMAIL, |
| 462 | + ) |
| 463 | + admin_docs = load_all_docs(admin_connector) |
| 464 | + assert len(admin_docs) == 1 |
| 465 | + |
| 466 | + # Test with test users - should get 0 docs |
| 467 | + test_users = [TEST_USER_1_EMAIL, TEST_USER_2_EMAIL, TEST_USER_3_EMAIL] |
| 468 | + test_connector = google_drive_service_acct_connector_factory( |
| 469 | + primary_admin_email=ADMIN_EMAIL, |
| 470 | + include_shared_drives=False, |
| 471 | + include_my_drives=False, |
| 472 | + include_files_shared_with_me=False, |
| 473 | + shared_folder_urls=RESTRICTED_ACCESS_FOLDER_URL, |
| 474 | + shared_drive_urls=None, |
| 475 | + my_drive_emails=None, |
| 476 | + specific_user_emails=",".join(test_users), |
| 477 | + ) |
| 478 | + test_docs = load_all_docs(test_connector) |
| 479 | + assert len(test_docs) == 0 |
0 commit comments