Source:
public void getTemporaryCredentials_readWrite() { setupFolderWithProjectSetting( true, STS_STORAGE_LOCATION_ID); ExternalS3StorageLocationSetting storageLocationSetting = new ExternalS3StorageLocationSetting(); storageLocationSetting.setBucket(BUCKET); storageLocationSetting.setStsEnabled(true); when(mockProjectSettingsManager.getStorageLocationSetting(STS_STORAGE_LOCATION_ID)).thenReturn( storageLocationSetting); when(mockAuthManager.canAccess(USER_INFO, PARENT_ENTITY_ID, ObjectType.ENTITY, ACCESS_TYPE.UPLOAD)) .thenReturn(mockAuthStatus); mockSts(); StsCredentials result = stsManager.getTemporaryCredentials(USER_INFO, PARENT_ENTITY_ID, StsPermission.read_write); assertStsCredentials(result); ArgumentCaptor<GetFederationTokenRequest> requestCaptor = ArgumentCaptor.forClass( GetFederationTokenRequest.class); verify(mockStsClient).getFederationToken(requestCaptor.capture()); GetFederationTokenRequest request = requestCaptor.getValue(); assertEquals(EXPECTED_STS_SESSION_NAME, request.getName()); assertEquals(StsManagerImpl.DURATION_SECONDS, request.getDurationSeconds()); String policy = request.getPolicy(); assertTrue(policy.contains("\"arn:aws:s3:::" + BUCKET + "\"")); assertTrue(policy.contains("{\"s3:prefix\":[\"\"]}")); assertTrue(policy.contains("{\"s3:prefix\":[\"*\"]}")); assertTrue(policy.contains("\"s3:*\"")); assertTrue(policy.contains("\"arn:aws:s3:::" + BUCKET + "\"")); assertTrue(policy.contains("\"arn:aws:s3:::" + BUCKET + "/*\"")); verify(mockAuthStatus).checkAuthorizationOrElseThrow(); }

Target:
public void getTemporaryCredentials_readWrite() { setupFolderWithProjectSetting( true, STS_STORAGE_LOCATION_ID); ExternalS3StorageLocationSetting storageLocationSetting = new ExternalS3StorageLocationSetting(); storageLocationSetting.setBucket(BUCKET); storageLocationSetting.setStsEnabled(true); when(mockProjectSettingsManager.getStorageLocationSetting(STS_STORAGE_LOCATION_ID)).thenReturn( storageLocationSetting); when(mockAuthManager.canAccess(same(USER_INFO), eq(PARENT_ENTITY_ID), eq(ObjectType.ENTITY), any())) .thenReturn(mockAuthStatus); mockSts(); StsCredentials result = stsManager.getTemporaryCredentials(USER_INFO, PARENT_ENTITY_ID, StsPermission.read_write); assertStsCredentials(result); ArgumentCaptor<GetFederationTokenRequest> requestCaptor = ArgumentCaptor.forClass( GetFederationTokenRequest.class); verify(mockStsClient).getFederationToken(requestCaptor.capture()); GetFederationTokenRequest request = requestCaptor.getValue(); assertEquals(EXPECTED_STS_SESSION_NAME, request.getName()); assertEquals(StsManagerImpl.DURATION_SECONDS, request.getDurationSeconds()); String policy = request.getPolicy(); assertTrue(policy.contains("\"arn:aws:s3:::" + BUCKET + "\"")); assertTrue(policy.contains("{\"s3:prefix\":[\"\"]}")); assertTrue(policy.contains("{\"s3:prefix\":[\"*\"]}")); assertTrue(policy.contains("\"s3:AbortMultipartUpload\",\"s3:DeleteObject\",\"s3:GetObject\",\"s3:ListBucket\"," + "\"s3:ListMultipartUploadParts\",\"s3:PutObject\",\"s3:ListBucketMultipartUploads\"")); assertTrue(policy.contains("\"arn:aws:s3:::" + BUCKET + "\"")); assertTrue(policy.contains("\"arn:aws:s3:::" + BUCKET + "/*\"")); verify(mockAuthManager).canAccess(USER_INFO, PARENT_ENTITY_ID, ObjectType.ENTITY, ACCESS_TYPE.DOWNLOAD); verify(mockAuthManager).canAccess(USER_INFO, PARENT_ENTITY_ID, ObjectType.ENTITY, ACCESS_TYPE.UPLOAD); verifyNoMoreInteractions(mockAuthManager); verify(mockAuthStatus, times(2)).checkAuthorizationOrElseThrow(); }