Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AutopsyTestCases.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.testing;
20 
21 import java.awt.AWTException;
22 import java.awt.Rectangle;
23 import java.awt.Robot;
24 import java.awt.Toolkit;
25 import java.awt.image.BufferedImage;
26 import java.io.File;
27 import java.io.IOException;
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Random;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
36 import javax.imageio.ImageIO;
37 import javax.swing.JDialog;
38 import javax.swing.text.JTextComponent;
39 import org.netbeans.jellytools.MainWindowOperator;
40 import org.netbeans.jellytools.NbDialogOperator;
41 import org.netbeans.jellytools.WizardOperator;
42 import org.netbeans.jemmy.Timeout;
43 import org.netbeans.jemmy.operators.JButtonOperator;
44 import org.netbeans.jemmy.operators.JCheckBoxOperator;
45 import org.netbeans.jemmy.operators.JComboBoxOperator;
46 import org.netbeans.jemmy.operators.JDialogOperator;
47 import org.netbeans.jemmy.operators.JFileChooserOperator;
48 import org.netbeans.jemmy.operators.JLabelOperator;
49 import org.netbeans.jemmy.operators.JListOperator;
50 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
51 import org.netbeans.jemmy.operators.JTableOperator;
52 import org.netbeans.jemmy.operators.JTextFieldOperator;
53 import org.netbeans.jemmy.operators.JToggleButtonOperator;
55 
56 public class AutopsyTestCases {
57 
58  private static final Logger logger = Logger.getLogger(AutopsyTestCases.class.getName());
59  private long start;
60 
70  public static String getEscapedPath(String path) {
71  if (path.startsWith("\\\\")) { //already has escaped to \\\\NetworkLocation
72  return path;
73  }
74  if (path.startsWith("\\")) {
75  return "\\" + path;
76  } else {
77  return path;
78  }
79  }
80 
81  public AutopsyTestCases () {
82  start = 0;
83  }
84 
85  public void testNewCaseWizardOpen(String title) {
86  logger.info("New Case");
87  NbDialogOperator nbdo = new NbDialogOperator(title);
88  JButtonOperator jbo = new JButtonOperator(nbdo, 0); // the "New Case" button
89  jbo.pushNoBlock();
90  }
91 
92  public void testNewCaseWizard() {
93  logger.info("New Case Wizard");
94  WizardOperator wo = new WizardOperator("New Case Information");
95  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 1);
96  jtfo0.typeText("AutopsyTestCase"); // Name the case "AutopsyTestCase"
97  JTextFieldOperator jtfo1 = new JTextFieldOperator(wo, 2);
98  jtfo1.typeText(getEscapedPath(System.getProperty("out_path")));
99  wo.btNext().clickMouse();
100  JTextFieldOperator jtfo2 = new JTextFieldOperator(wo, 0);
101  jtfo2.typeText("000"); // Set the case number
102  JTextFieldOperator jtfo3 = new JTextFieldOperator(wo, 1);
103  jtfo3.typeText("Examiner 1"); // Set the case examiner
104  start = System.currentTimeMillis();
105  wo.btFinish().clickMouse();
106  }
107 
109  logger.info("Starting Add Image process");
110  WizardOperator wo = new WizardOperator("Add Data");
111  //select the toggle button for Disk Image or VM File it will be the first button created and proceed to next panel
112  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 0);
113  jtbo.clickMouse();
114  wo.btNext().clickMouse();
115  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 0);
116  String img_path = getEscapedPath(System.getProperty("img_path"));
117  String imageDir = img_path;
118  ((JTextComponent) jtfo0.getSource()).setText(imageDir);
119  JComboBoxOperator comboBoxOperator = new JComboBoxOperator(wo, 0);
120  comboBoxOperator.setSelectedItem("(GMT-5:00) America/New_York");
121  wo.btNext().clickMouse();
122  }
123 
125  logger.info("Starting Add Logical Files process");
126  WizardOperator wo = new WizardOperator("Add Data");
127  //select the toggle button for Logical Files it will be the third button created and proceed to next panel
128  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 2);
129  jtbo.clickMouse();
130  wo.btNext().clickMouse();
131  JButtonOperator addButtonOperator = new JButtonOperator(wo, "Add");
132  addButtonOperator.pushNoBlock();
133  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
134  fileChooserOperator.setCurrentDirectory(new File(getEscapedPath(System.getProperty("img_path"))));
135  // set the current directory one level above the directory containing logicalFileSet folder.
136  fileChooserOperator.goUpLevel();
137  fileChooserOperator.chooseFile(new File(getEscapedPath(System.getProperty("img_path"))).getName());
138  wo.btNext().clickMouse();
139  }
140 
141  public void testAddSourceWizard1() {
142  WizardOperator wo = new WizardOperator("Add Data");
143  while (!wo.btFinish().isEnabled()) {
144  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
145  }
146  logger.log(Level.INFO, "Add image took {0}ms", (System.currentTimeMillis() - start));
147  wo.btFinish().clickMouse();
148  }
149 
150  public void testConfigureIngest1() {
151  /*
152  * This timeout is to allow the setup for the ingest job settings panel
153  * to complete.
154  */
155  new Timeout("pausing", 10000).sleep();
156 
157  logger.info("Looking for hash lookup module in ingest job settings panel");
158  WizardOperator wo = new WizardOperator("Add Data");
159  JTableOperator jto = new JTableOperator(wo, 0);
160  int row = jto.findCellRow("Hash Lookup", 2, 0);
161  jto.clickOnCell(row, 1);
162  logger.info("Selected hash lookup module in ingest job settings panel");
163  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
164  jbo1.pushNoBlock();
165  logger.info("Pushed Global Settings button for hash lookup module in ingest job settings panel");
166  }
167 
168  public void testConfigureHash() {
169  logger.info("Hash Configure");
170  JDialog hashMainDialog = JDialogOperator.waitJDialog("Global Hash Lookup Settings", false, false);
171  JDialogOperator hashMainDialogOperator = new JDialogOperator(hashMainDialog);
172  List<String> databases = new ArrayList<>();
173  databases.add(getEscapedPath(System.getProperty("nsrl_path")));
174  databases.add(getEscapedPath(System.getProperty("known_bad_path")));
175  databases.stream().map((database) -> {
176  JButtonOperator importButtonOperator = new JButtonOperator(hashMainDialogOperator, "Import");
177  importButtonOperator.pushNoBlock();
178  JDialog addDatabaseDialog = JDialogOperator.waitJDialog("Import Hash Database", false, false);
179  JDialogOperator addDatabaseDialogOperator = new JDialogOperator(addDatabaseDialog);
180  JButtonOperator browseButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "Open...", 0);
181  browseButtonOperator.pushNoBlock();
182  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
183  fileChooserOperator.chooseFile(database);
184  JButtonOperator okButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "OK", 0);
185  return okButtonOperator;
186  }).map((okButtonOperator) -> {
187  okButtonOperator.pushNoBlock();
188  return okButtonOperator;
189  }).forEach((_item) -> {
190  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
191  });
192  // Used if the database has no index
193  //JDialog jd3 = JDialogOperator.waitJDialog("No Index Exists", false, false);
194  //JDialogOperator jdo3 = new JDialogOperator(jd3);
195  //JButtonOperator jbo3 = new JButtonOperator(jdo3, "Yes", 0);
196  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
197  //jbo3.pushNoBlock();
198  JButtonOperator jbo4 = new JButtonOperator(hashMainDialogOperator, "OK", 0);
199  jbo4.pushNoBlock();
200  }
201 
202  public void testConfigureIngest2() {
203  logger.info("Looking for keyword search module in ingest job settings panel");
204  WizardOperator wo = new WizardOperator("Add Data");
205  JTableOperator jto = new JTableOperator(wo, 0);
206  int row = jto.findCellRow("Keyword Search", 2, 0);
207  jto.clickOnCell(row, 1);
208  logger.info("Selected keyword search module in ingest job settings panel");
209  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
210  jbo1.pushNoBlock();
211  logger.info("Pushed Global Settings button for keyword search module in ingest job settings panel");
212  }
213 
214  public void testConfigureSearch() {
215  logger.info("Search Configure");
216  JDialog jd = JDialogOperator.waitJDialog("Global Keyword Search Settings", false, false);
217  JDialogOperator jdo = new JDialogOperator(jd);
218  String words = getEscapedPath(System.getProperty("keyword_path"));
219  JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0);
220  jbo0.pushNoBlock();
221  JFileChooserOperator jfco0 = new JFileChooserOperator();
222  jfco0.chooseFile(words);
223  JTableOperator jto = new JTableOperator(jdo, 0);
224  jto.clickOnCell(0, 0);
225  new Timeout("pausing", 1000).sleep(); // give it a second to process
226  if (Boolean.parseBoolean(System.getProperty("mugen_mode"))) {
227  JTabbedPaneOperator jtpo = new JTabbedPaneOperator(jdo);
228  jtpo.selectPage("String Extraction");
229  JCheckBoxOperator jcbo0 = new JCheckBoxOperator(jtpo, "Arabic (Arabic)");
230  jcbo0.doClick();
231  JCheckBoxOperator jcbo1 = new JCheckBoxOperator(jtpo, "Han (Chinese, Japanese, Korean)");
232  jcbo1.doClick();
233  new Timeout("pausing", 1000).sleep(); // give it a second to process
234  }
235  JButtonOperator jbo2 = new JButtonOperator(jdo, "OK", 0);
236  jbo2.pushNoBlock();
237  WizardOperator wo = new WizardOperator("Add Data");
238  new Timeout("pausing", 10000).sleep(); // let things catch up
239  wo.btNext().clickMouse();
240  }
241 
242  public void testIngest() {
243  logger.info("Ingest 3");
244  new Timeout("pausing", 10000).sleep(); // wait for ingest to actually start
245  long startIngest = System.currentTimeMillis();
247  while (man.isIngestRunning()) {
248  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
249  }
250  logger.log(Level.INFO, "Ingest (including enqueue) took {0}ms", (System.currentTimeMillis() - startIngest));
251  // allow keyword search to finish saving artifacts, just in case
252  // but randomize the timing so that we don't always get the same error
253  // consistently, making it seem like default behavior
254  Random rand = new Random();
255  new Timeout("pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
256  screenshot("Finished Ingest");
257 
258  }
259 
261  logger.info("Generate Report Toolbars");
262  MainWindowOperator mwo = MainWindowOperator.getDefault();
263  JButtonOperator jbo = new JButtonOperator(mwo, "Generate Report");
264  jbo.pushNoBlock();
265  new Timeout("pausing", 5000).sleep();
266  }
267 
268  public void testGenerateReportButton() throws IOException {
269  logger.info("Generate Report Button");
270  JDialog reportDialog = JDialogOperator.waitJDialog("Generate Report", false, false);
271  JDialogOperator reportDialogOperator = new JDialogOperator(reportDialog);
272  JListOperator listOperator = new JListOperator(reportDialogOperator);
273  JButtonOperator jbo0 = new JButtonOperator(reportDialogOperator, "Next");
274  DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss");
275  Date date = new Date();
276  String datenotime = dateFormat.format(date);
277  listOperator.clickOnItem(0, 1);
278  new Timeout("pausing", 2000).sleep();
279  jbo0.pushNoBlock();
280  new Timeout("pausing", 2000).sleep();
281  JButtonOperator jbo1 = new JButtonOperator(reportDialogOperator, "Finish");
282  jbo1.pushNoBlock();
283  new Timeout("pausing", 1000).sleep();
284  JDialog previewDialog = JDialogOperator.waitJDialog("Progress", false, false);
285  screenshot("Progress");
286  JDialogOperator previewDialogOperator = new JDialogOperator(previewDialog);
287  JLabelOperator.waitJLabel(previewDialog, "Complete", false, false);
288  JButtonOperator jbo2 = new JButtonOperator(previewDialogOperator, "Close");
289  jbo2.pushNoBlock();
290  new Timeout("pausing", 10000).sleep();
291  System.setProperty("ReportStr", datenotime);
292  screenshot("Done Testing");
293  }
294 
295  public void screenshot(String name) {
296  logger.info("Taking screenshot.");
297  try {
298  Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
299  BufferedImage capture = new Robot().createScreenCapture(screenRect);
300  String outPath = getEscapedPath(System.getProperty("out_path"));
301  ImageIO.write(capture, "png", new File(outPath + "\\" + name + ".png"));
302  new Timeout("pausing", 1000).sleep(); // give it a second to save
303  } catch (IOException ex) {
304  logger.log(Level.WARNING, "IOException taking screenshot.", ex);
305  } catch (AWTException ex) {
306  logger.log(Level.WARNING, "AWTException taking screenshot.", ex);
307 
308  }
309  }
310 }
static synchronized IngestManager getInstance()

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.