mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +00:00
Added functional tests for mime type and extension searches
This commit is contained in:
parent
fee80988e8
commit
ac7be89674
@ -19,6 +19,8 @@
|
|||||||
package org.sleuthkit.autopsy.mainui.datamodel;
|
package org.sleuthkit.autopsy.mainui.datamodel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -80,6 +82,12 @@ public class TableSearchTest extends NbTestCase {
|
|||||||
AbstractFile customDataArtifactSourceFile = null; // The source file of customDataArtifact
|
AbstractFile customDataArtifactSourceFile = null; // The source file of customDataArtifact
|
||||||
AbstractFile customDataArtifactLinkedFile = null; // The linked file of customDataArtifact
|
AbstractFile customDataArtifactLinkedFile = null; // The linked file of customDataArtifact
|
||||||
|
|
||||||
|
// Extension and MIME type test
|
||||||
|
private String customMimeType = "fake/type";
|
||||||
|
private String customFileName = "test.fake";
|
||||||
|
private static String customExtension = "fake";
|
||||||
|
private static final List<String> CUSTOM_EXTENSIONS = Arrays.asList("." + customExtension); //NON-NLS
|
||||||
|
private static final List<String> EMPTY_RESULT_SET_EXTENSIONS = Arrays.asList(".blah", ".blah2", ".crazy"); //NON-NLS
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(TableSearchTest.class).
|
NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(TableSearchTest.class).
|
||||||
@ -99,7 +107,8 @@ public class TableSearchTest extends NbTestCase {
|
|||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
dataArtifactSearchTest();
|
dataArtifactSearchTest();
|
||||||
mimeTypeSearchTest();
|
mimeSearchTest();
|
||||||
|
extensionSearchTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,7 +134,7 @@ public class TableSearchTest extends NbTestCase {
|
|||||||
fileA1.setMIMEType("text/plain");
|
fileA1.setMIMEType("text/plain");
|
||||||
fileA1.save();
|
fileA1.save();
|
||||||
AbstractFile folderA2 = db.addLocalDirectory(dataSource1.getId(), "folder2");
|
AbstractFile folderA2 = db.addLocalDirectory(dataSource1.getId(), "folder2");
|
||||||
AbstractFile fileA2 =db.addLocalFile("file2.jpg", "", 0, 0, 0, 0, 0, true, TskData.EncodingType.NONE, folderA2);
|
AbstractFile fileA2 = db.addLocalFile("file2.jpg", "", 0, 0, 0, 0, 0, true, TskData.EncodingType.NONE, folderA2);
|
||||||
fileA2.setMIMEType("image/jpeg");
|
fileA2.setMIMEType("image/jpeg");
|
||||||
fileA2.save();
|
fileA2.save();
|
||||||
AbstractFile folderA3 = db.addLocalDirectory(folderA2.getId(), "folder3");
|
AbstractFile folderA3 = db.addLocalDirectory(folderA2.getId(), "folder3");
|
||||||
@ -141,6 +150,10 @@ public class TableSearchTest extends NbTestCase {
|
|||||||
fileB1.setMIMEType("text/plain");
|
fileB1.setMIMEType("text/plain");
|
||||||
fileB1.save();
|
fileB1.save();
|
||||||
|
|
||||||
|
AbstractFile customFile = db.addLocalFile(customFileName, "", 0, 0, 0, 0, 0, true, TskData.EncodingType.NONE, folderB1);
|
||||||
|
customFile.setMIMEType(customMimeType);
|
||||||
|
customFile.save();
|
||||||
|
|
||||||
// Create a custom artifact and attribute types
|
// Create a custom artifact and attribute types
|
||||||
customDataArtifactType = blackboard.getOrAddArtifactType(CUSTOM_DA_TYPE_NAME, CUSTOM_DA_TYPE_DISPLAY_NAME, BlackboardArtifact.Category.DATA_ARTIFACT);
|
customDataArtifactType = blackboard.getOrAddArtifactType(CUSTOM_DA_TYPE_NAME, CUSTOM_DA_TYPE_DISPLAY_NAME, BlackboardArtifact.Category.DATA_ARTIFACT);
|
||||||
customAttributeType = blackboard.getOrAddAttributeType(CUSTOM_ATTR_TYPE_NAME,
|
customAttributeType = blackboard.getOrAddAttributeType(CUSTOM_ATTR_TYPE_NAME,
|
||||||
@ -241,7 +254,7 @@ public class TableSearchTest extends NbTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mimeTypeSearchTest() {
|
public void mimeSearchTest() {
|
||||||
// Quick test that everything is initialized
|
// Quick test that everything is initialized
|
||||||
assertTrue(db != null);
|
assertTrue(db != null);
|
||||||
|
|
||||||
@ -272,35 +285,127 @@ public class TableSearchTest extends NbTestCase {
|
|||||||
assertEquals(0, results.getTotalResultsCount());
|
assertEquals(0, results.getTotalResultsCount());
|
||||||
assertEquals(0, results.getItems().size());
|
assertEquals(0, results.getItems().size());
|
||||||
|
|
||||||
/*
|
// Get plain text files from all data sources
|
||||||
// Check that a few of the expected column names are present
|
param = new FileTypeMimeSearchParams("text/plain", null);
|
||||||
List<String> columnDisplayNames = results.getColumns().stream().map(p -> p.getDisplayName()).collect(Collectors.toList());
|
results = viewsDAO.getFilesByMime(param);
|
||||||
assertTrue(columnDisplayNames.contains(BlackboardAttribute.Type.TSK_COMMENT.getDisplayName()));
|
assertEquals(3, results.getTotalResultsCount());
|
||||||
assertTrue(columnDisplayNames.contains(BlackboardAttribute.Type.TSK_COUNT.getDisplayName()));
|
assertEquals(3, results.getItems().size());
|
||||||
assertTrue(columnDisplayNames.contains(customAttributeType.getDisplayName()));
|
|
||||||
|
// Get the custom file by MIME type
|
||||||
|
param = new FileTypeMimeSearchParams(customMimeType, null);
|
||||||
|
results = viewsDAO.getFilesByMime(param);
|
||||||
|
assertEquals(1, results.getTotalResultsCount());
|
||||||
|
assertEquals(1, results.getItems().size());
|
||||||
|
|
||||||
// Get one of the rows
|
|
||||||
RowDTO rowDTO = results.getItems().get(0);
|
RowDTO rowDTO = results.getItems().get(0);
|
||||||
assertTrue(rowDTO instanceof DataArtifactRowDTO);
|
assertTrue(rowDTO instanceof FileRowDTO);
|
||||||
DataArtifactRowDTO dataArtifactRowDTO = (DataArtifactRowDTO) rowDTO;
|
FileRowDTO fileRowDTO = (FileRowDTO) rowDTO;
|
||||||
|
|
||||||
// Check that the artifact, source content and linked file are correct
|
|
||||||
assertEquals(customDataArtifact, dataArtifactRowDTO.getDataArtifact());
|
|
||||||
assertEquals(customDataArtifactSourceFile, dataArtifactRowDTO.getSrcContent());
|
|
||||||
//assertEquals(customDataArtifactLinkedFile, dataArtifactRowDTO.getLinkedFile()); I'm doing something wrong or this isn't working yet
|
|
||||||
|
|
||||||
// Check that some of the expected column values are present
|
|
||||||
assertTrue(dataArtifactRowDTO.getCellValues().contains(ARTIFACT_CUSTOM_ATTR_STRING));
|
|
||||||
assertTrue(dataArtifactRowDTO.getCellValues().contains(ARTIFACT_COMMENT));
|
|
||||||
assertTrue(dataArtifactRowDTO.getCellValues().contains(ARTIFACT_INT));
|
|
||||||
assertTrue(dataArtifactRowDTO.getCellValues().contains(ARTIFACT_DOUBLE));*/
|
|
||||||
|
|
||||||
|
assertEquals(customFileName, fileRowDTO.getFileName());
|
||||||
|
assertEquals(customExtension, fileRowDTO.getExtension());
|
||||||
} catch (ExecutionException ex) {
|
} catch (ExecutionException ex) {
|
||||||
Exceptions.printStackTrace(ex);
|
Exceptions.printStackTrace(ex);
|
||||||
Assert.fail(ex.getMessage());
|
Assert.fail(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void extensionSearchTest() {
|
||||||
|
// Quick test that everything is initialized
|
||||||
|
assertTrue(db != null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ViewsDAO viewsDAO = MainDAO.getInstance().getViewsDAO();
|
||||||
|
|
||||||
|
// Get all text documents from data source 1
|
||||||
|
FileTypeExtensionsSearchParams param = new FileTypeExtensionsSearchParams(FileExtRootFilter.TSK_DOCUMENT_FILTER, dataSource1.getId());
|
||||||
|
SearchResultsDTO results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(3, results.getTotalResultsCount());
|
||||||
|
assertEquals(3, results.getItems().size());
|
||||||
|
|
||||||
|
// Get Word documents from data source 1
|
||||||
|
param = new FileTypeExtensionsSearchParams(FileExtDocumentFilter.AUT_DOC_OFFICE, dataSource1.getId());
|
||||||
|
results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(1, results.getTotalResultsCount());
|
||||||
|
assertEquals(1, results.getItems().size());
|
||||||
|
|
||||||
|
// Get image/jpeg files from data source 1
|
||||||
|
param = new FileTypeExtensionsSearchParams(FileExtRootFilter.TSK_IMAGE_FILTER, dataSource1.getId());
|
||||||
|
results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(1, results.getTotalResultsCount());
|
||||||
|
assertEquals(1, results.getItems().size());
|
||||||
|
|
||||||
|
// Get text documents from all data sources
|
||||||
|
param = new FileTypeExtensionsSearchParams(FileExtRootFilter.TSK_DOCUMENT_FILTER, null);
|
||||||
|
results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(4, results.getTotalResultsCount());
|
||||||
|
assertEquals(4, results.getItems().size());
|
||||||
|
|
||||||
|
// Get jpeg files from data source 2
|
||||||
|
param = new FileTypeExtensionsSearchParams(FileExtRootFilter.TSK_IMAGE_FILTER, dataSource2.getId());
|
||||||
|
results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(0, results.getTotalResultsCount());
|
||||||
|
assertEquals(0, results.getItems().size());
|
||||||
|
|
||||||
|
// Search for file extensions that should produce no results
|
||||||
|
param = new FileTypeExtensionsSearchParams(CustomRootFilter.EMPTY_RESULT_SET_FILTER, null);
|
||||||
|
results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(0, results.getTotalResultsCount());
|
||||||
|
assertEquals(0, results.getItems().size());
|
||||||
|
|
||||||
|
// Get the custom file by extension
|
||||||
|
param = new FileTypeExtensionsSearchParams(CustomRootFilter.CUSTOM_FILTER, null);
|
||||||
|
results = viewsDAO.getFilesByExtension(param);
|
||||||
|
assertEquals(1, results.getTotalResultsCount());
|
||||||
|
assertEquals(1, results.getItems().size());
|
||||||
|
|
||||||
|
RowDTO rowDTO = results.getItems().get(0);
|
||||||
|
assertTrue(rowDTO instanceof FileRowDTO);
|
||||||
|
FileRowDTO fileRowDTO = (FileRowDTO) rowDTO;
|
||||||
|
|
||||||
|
assertEquals(customFileName, fileRowDTO.getFileName());
|
||||||
|
assertEquals(customExtension, fileRowDTO.getExtension());
|
||||||
|
} catch (ExecutionException ex) {
|
||||||
|
Exceptions.printStackTrace(ex);
|
||||||
|
Assert.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum CustomRootFilter implements FileExtSearchFilter {
|
||||||
|
|
||||||
|
CUSTOM_FILTER(0, "CUSTOM_FILTER", "Test", CUSTOM_EXTENSIONS), //NON-NLS
|
||||||
|
EMPTY_RESULT_SET_FILTER(1, "EMPTY_RESULT_SET_FILTER", "Test", EMPTY_RESULT_SET_EXTENSIONS); //NON-NLS
|
||||||
|
final int id;
|
||||||
|
final String name;
|
||||||
|
final String displayName;
|
||||||
|
final List<String> filter;
|
||||||
|
|
||||||
|
private CustomRootFilter(int id, String name, String displayName, List<String> filter) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.displayName = displayName;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return this.displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getFilter() {
|
||||||
|
return Collections.unmodifiableList(this.filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user