3030import org .mockito .Spy ;
3131import org .mockito .junit .jupiter .MockitoExtension ;
3232import org .sagebionetworks .repo .manager .EntityManager ;
33+ import org .sagebionetworks .repo .manager .entity .EntityAuthorizationManager ;
3334import org .sagebionetworks .repo .manager .file .CsvFileHandleProvider ;
3435import org .sagebionetworks .repo .manager .file .FileHandleManager ;
3536import org .sagebionetworks .repo .manager .grid .PatchRowHandler ;
3637import org .sagebionetworks .repo .manager .grid .PatchStore ;
38+ import org .sagebionetworks .repo .model .ACCESS_TYPE ;
3739import org .sagebionetworks .repo .model .RecordSet ;
3840import org .sagebionetworks .repo .model .UserInfo ;
41+ import org .sagebionetworks .repo .model .auth .AuthorizationStatus ;
3942import org .sagebionetworks .repo .model .dao .asynch .AsyncJobProgressCallback ;
4043import org .sagebionetworks .repo .model .dbo .grid .CreateGridSession ;
4144import org .sagebionetworks .repo .model .dbo .grid .GridDao ;
@@ -80,6 +83,9 @@ public class RecordSetCreateGridHandlerTest {
8083 @ Mock
8184 private FileHandleManager mockFileHandleManager ;
8285
86+ @ Mock
87+ private EntityAuthorizationManager mockAuthorizationManager ;
88+
8389 @ Mock
8490 private CsvFileHandleProvider mockCsvProvider ;
8591
@@ -145,6 +151,7 @@ public void testCanCreate() {
145151 public void testBuildSessionFromRecordSet () throws IOException {
146152 when (mockUser .getId ()).thenReturn (userId );
147153 when (mockEntityManager .getEntity (mockUser , recordSet .getId (), RecordSet .class )).thenReturn (recordSet );
154+ when (mockAuthorizationManager .hasAccess (mockUser , recordSet .getId (), ACCESS_TYPE .DOWNLOAD )).thenReturn (AuthorizationStatus .authorized ());
148155 when (mockEntityManager .findBoundSchema (recordSet .getId ())).thenReturn (Optional .of (
149156 new JsonSchemaObjectBinding ().setJsonSchemaVersionInfo (new JsonSchemaVersionInfo ().set$id (schema$id ))));
150157
@@ -156,7 +163,7 @@ public void testBuildSessionFromRecordSet() throws IOException {
156163
157164 when (mockGridDao .createReplica (userId , gridSessionId , isAgent , EventSource .INTERNAL )).thenReturn (replica );
158165
159- when (mockFileHandleManager .getRawFileHandle ( mockUser , recordSet .getDataFileHandleId ())).thenReturn (csvFile );
166+ when (mockFileHandleManager .getRawFileHandleUnchecked ( recordSet .getDataFileHandleId ())).thenReturn (csvFile );
160167
161168 Long maxRowSize = (long ) TableModelUtils .calculateMaxRowSize (csvSchema );
162169
@@ -188,6 +195,7 @@ public void testBuildSessionFromRecordSet() throws IOException {
188195 public void testBuildSessionFromRecordSetWithNoValidationSchema () throws IOException {
189196 when (mockUser .getId ()).thenReturn (userId );
190197 when (mockEntityManager .getEntity (mockUser , recordSet .getId (), RecordSet .class )).thenReturn (recordSet );
198+ when (mockAuthorizationManager .hasAccess (mockUser , recordSet .getId (), ACCESS_TYPE .DOWNLOAD )).thenReturn (AuthorizationStatus .authorized ());
191199 when (mockEntityManager .findBoundSchema (recordSet .getId ())).thenReturn (Optional .empty ());
192200
193201 gridSession = new GridSession ().setSessionId (gridSessionId );
@@ -197,7 +205,7 @@ public void testBuildSessionFromRecordSetWithNoValidationSchema() throws IOExcep
197205
198206 when (mockGridDao .createReplica (userId , gridSessionId , isAgent , EventSource .INTERNAL )).thenReturn (replica );
199207
200- when (mockFileHandleManager .getRawFileHandle ( mockUser , recordSet .getDataFileHandleId ())).thenReturn (csvFile );
208+ when (mockFileHandleManager .getRawFileHandleUnchecked ( recordSet .getDataFileHandleId ())).thenReturn (csvFile );
201209
202210 Long maxRowSize = (long ) TableModelUtils .calculateMaxRowSize (csvSchema );
203211
@@ -231,6 +239,7 @@ public void testBuildSessionFromRecordSetWithNoCsvDescriptor() throws IOExceptio
231239
232240 when (mockUser .getId ()).thenReturn (userId );
233241 when (mockEntityManager .getEntity (mockUser , recordSet .getId (), RecordSet .class )).thenReturn (recordSet );
242+ when (mockAuthorizationManager .hasAccess (mockUser , recordSet .getId (), ACCESS_TYPE .DOWNLOAD )).thenReturn (AuthorizationStatus .authorized ());
234243 when (mockEntityManager .findBoundSchema (recordSet .getId ())).thenReturn (Optional .empty ());
235244
236245 gridSession = new GridSession ().setSessionId (gridSessionId );
@@ -240,7 +249,7 @@ public void testBuildSessionFromRecordSetWithNoCsvDescriptor() throws IOExceptio
240249
241250 when (mockGridDao .createReplica (userId , gridSessionId , isAgent , EventSource .INTERNAL )).thenReturn (replica );
242251
243- when (mockFileHandleManager .getRawFileHandle ( mockUser , recordSet .getDataFileHandleId ())).thenReturn (csvFile );
252+ when (mockFileHandleManager .getRawFileHandleUnchecked ( recordSet .getDataFileHandleId ())).thenReturn (csvFile );
244253
245254 Long maxRowSize = (long ) TableModelUtils .calculateMaxRowSize (csvSchema );
246255
@@ -273,6 +282,7 @@ public void testBuildSessionFromRecordSetWithNoCsvDescriptor() throws IOExceptio
273282 public void testBuildSessionFromRecordSetWithIOException () throws IOException {
274283 when (mockUser .getId ()).thenReturn (userId );
275284 when (mockEntityManager .getEntity (mockUser , recordSet .getId (), RecordSet .class )).thenReturn (recordSet );
285+ when (mockAuthorizationManager .hasAccess (mockUser , recordSet .getId (), ACCESS_TYPE .DOWNLOAD )).thenReturn (AuthorizationStatus .authorized ());
276286 when (mockEntityManager .findBoundSchema (recordSet .getId ())).thenReturn (Optional .empty ());
277287
278288 gridSession = new GridSession ().setSessionId (gridSessionId );
@@ -282,7 +292,7 @@ public void testBuildSessionFromRecordSetWithIOException() throws IOException {
282292
283293 when (mockGridDao .createReplica (userId , gridSessionId , isAgent , EventSource .INTERNAL )).thenReturn (replica );
284294
285- when (mockFileHandleManager .getRawFileHandle ( mockUser , recordSet .getDataFileHandleId ())).thenReturn (csvFile );
295+ when (mockFileHandleManager .getRawFileHandleUnchecked ( recordSet .getDataFileHandleId ())).thenReturn (csvFile );
286296
287297 IOException ioe = new IOException ("nope" );
288298
@@ -313,6 +323,7 @@ public void testBuildSessionFromRecordSetWithIOException() throws IOException {
313323 public void testBuildSessionFromRecordSetWithEmptyCsvSchema () throws IOException {
314324 when (mockUser .getId ()).thenReturn (userId );
315325 when (mockEntityManager .getEntity (mockUser , recordSet .getId (), RecordSet .class )).thenReturn (recordSet );
326+ when (mockAuthorizationManager .hasAccess (mockUser , recordSet .getId (), ACCESS_TYPE .DOWNLOAD )).thenReturn (AuthorizationStatus .authorized ());
316327 when (mockEntityManager .findBoundSchema (recordSet .getId ())).thenReturn (Optional .empty ());
317328
318329 gridSession = new GridSession ().setSessionId (gridSessionId );
@@ -322,7 +333,7 @@ public void testBuildSessionFromRecordSetWithEmptyCsvSchema() throws IOException
322333
323334 when (mockGridDao .createReplica (userId , gridSessionId , isAgent , EventSource .INTERNAL )).thenReturn (replica );
324335
325- when (mockFileHandleManager .getRawFileHandle ( mockUser , recordSet .getDataFileHandleId ())).thenReturn (csvFile );
336+ when (mockFileHandleManager .getRawFileHandleUnchecked ( recordSet .getDataFileHandleId ())).thenReturn (csvFile );
326337
327338 csvSchema = Collections .emptyList ();
328339
0 commit comments