FileResourceBlocklist { public static boolean isValid( FileResource fileResource ) { if ( fileResource == null || fileResource.getContentType() == null || fileResource.getName() == null ) { return false; } if ( CONTENT_TYPES.contains( fileResource.getContentType().toLowerCase() ) ) { return false; } if ( FILE_EXTENSIONS.contains( FilenameUtils.getExtension( fileResource.getName().toLowerCase() ) ) ) { return false; } return true; }  static boolean isValid( FileResource fileResource );  }
@Test public void testValid() { FileResource frA = new FileResource( "My_Checklist.pdf", "application/pdf", 324, "", FileResourceDomain.DATA_VALUE ); FileResource frB = new FileResource( "Evaluation.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 541, "", FileResourceDomain.MESSAGE_ATTACHMENT ); FileResource frC = new FileResource( "FinancialReport.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 143, "", FileResourceDomain.DATA_VALUE ); assertTrue( FileResourceBlocklist.isValid( frA ) ); assertTrue( FileResourceBlocklist.isValid( frB ) ); assertTrue( FileResourceBlocklist.isValid( frC ) ); }
@Test public void testInvalid() { FileResource frA = new FileResource( "Click_Me.exe", "application/x-ms-dos-executable", 451, "", FileResourceDomain.DATA_VALUE ); FileResource frB = new FileResource( "evil_script.sh", "application/pdf", 125, "", FileResourceDomain.MESSAGE_ATTACHMENT ); FileResource frC = new FileResource( "cookie_stealer", "text/javascript", 631, "", FileResourceDomain.USER_AVATAR ); FileResource frD = new FileResource( "malicious_software.msi", null, 235, "", FileResourceDomain.USER_AVATAR ); assertFalse( FileResourceBlocklist.isValid( frA ) ); assertFalse( FileResourceBlocklist.isValid( frB ) ); assertFalse( FileResourceBlocklist.isValid( frC ) ); assertFalse( FileResourceBlocklist.isValid( frD ) ); assertFalse( FileResourceBlocklist.isValid( null ) ); }