コード例 #1
0
 @Test(expected = InvalidModelException.class)
 public void testCreateS3AttachmentTokenBadMD5()
     throws NumberFormatException, DatastoreException, NotFoundException, UnauthorizedException,
         InvalidModelException {
   S3AttachmentToken startToken = new S3AttachmentToken();
   startToken.setFileName("SomeFile.jpg");
   String almostMd5 = "79054025255fb1a26e4bc422aef";
   startToken.setMd5(almostMd5);
   Long tokenId = new Long(456);
   String entityId = "132";
   String userId = "007";
   String expectedPath = entityId + "/" + tokenId.toString();
   String expectePreSigneUrl = "I am a presigned url! whooot!";
   when(mocIdGenerator.generateNewId()).thenReturn(tokenId);
   Credentials mockCreds = Mockito.mock(Credentials.class);
   when(mockUuserManager.getUserInfo(userId)).thenReturn(mockUser);
   when(mockPermissionsManager.hasAccess(entityId, ACCESS_TYPE.UPDATE, mockUser)).thenReturn(true);
   when(mocKLocationHelper.createFederationTokenForS3(userId, HttpMethod.PUT, expectedPath))
       .thenReturn(mockCreds);
   when(mocKLocationHelper.presignS3PUTUrl(mockCreds, expectedPath, almostMd5, "image/jpeg"))
       .thenReturn(expectePreSigneUrl);
   // Make the actual call
   S3AttachmentToken endToken = manager.createS3AttachmentToken(userId, entityId, startToken);
   assertNotNull(endToken);
   assertEquals(expectePreSigneUrl, endToken.getPresignedUrl());
 }
コード例 #2
0
 @Test
 public void testGetAttachmentUrl() throws Exception {
   Long tokenId = new Long(456);
   String entityId = "132";
   String expectedPath =
       S3TokenManagerImpl.createAttachmentPathSlash(entityId, tokenId.toString());
   String expectePreSigneUrl = "I am a presigned url! whooot!";
   when(mockUuserManager.getUserInfo(userId)).thenReturn(mockUser);
   when(mockPermissionsManager.hasAccess(entityId, ACCESS_TYPE.READ, mockUser)).thenReturn(true);
   when(mocKLocationHelper.presignS3GETUrlShortLived(userId, expectedPath))
       .thenReturn(expectePreSigneUrl);
   when(mockS3Utilitiy.doesExist(any(String.class))).thenReturn(true);
   // Make the actual call
   when(mockUuserManager.getUserInfo(userId)).thenReturn(mockUser);
   PresignedUrl url = manager.getAttachmentUrl(userId, entityId, tokenId.toString());
   assertNotNull(url);
   assertEquals(expectePreSigneUrl, url.getPresignedUrl());
   assertEquals(URLStatus.READ_FOR_DOWNLOAD, url.getStatus());
 }