Autopsy  4.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.JemmyProperties;
43 import org.netbeans.jemmy.Timeout;
44 import org.netbeans.jemmy.Timeouts;
45 import org.netbeans.jemmy.operators.JButtonOperator;
46 import org.netbeans.jemmy.operators.JCheckBoxOperator;
47 import org.netbeans.jemmy.operators.JComboBoxOperator;
48 import org.netbeans.jemmy.operators.JDialogOperator;
49 import org.netbeans.jemmy.operators.JFileChooserOperator;
50 import org.netbeans.jemmy.operators.JLabelOperator;
51 import org.netbeans.jemmy.operators.JListOperator;
52 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
53 import org.netbeans.jemmy.operators.JTableOperator;
54 import org.netbeans.jemmy.operators.JTextFieldOperator;
55 import org.netbeans.jemmy.operators.JToggleButtonOperator;
60 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
61 import org.sleuthkit.datamodel.TskData;
62 
63 public class AutopsyTestCases {
64 
65  private static final Logger logger = Logger.getLogger(AutopsyTestCases.class.getName());
66  private long start;
67 
75  public static String getEscapedPath(String path) {
76  if (path.startsWith("\\\\")) { //already has escaped to \\\\NetworkLocation
77  return path;
78  }
79  if (path.startsWith("\\")) {
80  return "\\" + path;
81  } else {
82  return path;
83  }
84  }
85 
86  public AutopsyTestCases(boolean isMultiUser) {
87  start = 0;
88  if (isMultiUser) {
90  } else {
92  }
93  }
94 
95  public void testNewCaseWizardOpen(String title) {
96  logger.info("New Case");
97  resetTimeouts("WindowWaiter.WaitWindowTimeout", 240000);
98  NbDialogOperator nbdo = new NbDialogOperator(title);
99  JButtonOperator jbo = new JButtonOperator(nbdo, 0); // the "New Case" button
100  jbo.pushNoBlock();
101  }
102 
103  public void testNewCaseWizard() {
104  logger.info("New Case Wizard");
105  WizardOperator wo = new WizardOperator("New Case Information");
106  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 1);
107  jtfo0.typeText("AutopsyTestCase"); // Name the case "AutopsyTestCase"
108  JTextFieldOperator jtfo1 = new JTextFieldOperator(wo, 2);
109  jtfo1.typeText(getEscapedPath(System.getProperty("out_path")));
110  wo.btNext().clickMouse();
111  JTextFieldOperator jtfo2 = new JTextFieldOperator(wo, 0);
112  jtfo2.typeText("000"); // Set the case number
113  JTextFieldOperator jtfo3 = new JTextFieldOperator(wo, 1);
114  jtfo3.typeText("Examiner 1"); // Set the case examiner
115  start = System.currentTimeMillis();
116  wo.btFinish().clickMouse();
117  }
118 
120  /*
121  * This time out is to give time for creating case database and opening solr index
122  */
123  new Timeout("pausing", 120000).sleep();
124  logger.info("Starting Add Image process");
125  resetTimeouts("WindowWaiter.WaitWindowTimeOut", 240000);
126  WizardOperator wo = new WizardOperator("Add Data Source");
127  while(!wo.btNext().isEnabled()){
128  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
129  }
130  //select the toggle button for Disk Image or VM File it will be the first button created and proceed to next panel
131  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 0);
132  jtbo.clickMouse();
133  wo.btNext().clickMouse();
134  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 0);
135  String img_path = getEscapedPath(System.getProperty("img_path"));
136  String imageDir = img_path;
137  ((JTextComponent) jtfo0.getSource()).setText(imageDir);
138  JComboBoxOperator comboBoxOperator = new JComboBoxOperator(wo, 0);
139  comboBoxOperator.setSelectedItem("(GMT-5:00) America/New_York");
140  wo.btNext().clickMouse();
141  }
142 
144  /*
145  * This time out is to give time for creating case database and opening solr index
146  */
147  new Timeout("pausing", 120000).sleep();
148  logger.info("Starting Add Logical Files process");
149  WizardOperator wo = new WizardOperator("Add Data Source");
150  wo.setTimeouts(resetTimeouts("WindowWaiter.WaitWindowTimeOut", 240000));
151  while(!wo.btNext().isEnabled()){
152  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
153  }
154  //select the toggle button for Logical Files it will be the third button created and proceed to next panel
155  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 2);
156  jtbo.clickMouse();
157  wo.btNext().clickMouse();
158  JButtonOperator addButtonOperator = new JButtonOperator(wo, "Add");
159  addButtonOperator.pushNoBlock();
160  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
161  fileChooserOperator.setCurrentDirectory(new File(getEscapedPath(System.getProperty("img_path"))));
162  // set the current directory one level above the directory containing logicalFileSet folder.
163  fileChooserOperator.goUpLevel();
164  fileChooserOperator.chooseFile(new File(getEscapedPath(System.getProperty("img_path"))).getName());
165  wo.btNext().clickMouse();
166  }
167 
168  public void testAddSourceWizard1() {
169  WizardOperator wo = new WizardOperator("Add Data Source");
170  while (!wo.btFinish().isEnabled()) {
171  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
172  }
173  logger.log(Level.INFO, "Add image took {0}ms", (System.currentTimeMillis() - start));
174  wo.btFinish().clickMouse();
175  }
176 
177  public void testConfigureIngest1() {
178  /*
179  * This timeout is to allow the setup for the ingest job settings panel
180  * to complete.
181  */
182  new Timeout("pausing", 10000).sleep();
183 
184  logger.info("Looking for hash lookup module in ingest job settings panel");
185  WizardOperator wo = new WizardOperator("Add Data Source");
186  while(!wo.btNext().isEnabled()){
187  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
188  }
189  JTableOperator jto = new JTableOperator(wo, 0);
190  int row = jto.findCellRow("Hash Lookup", 2, 0);
191  jto.clickOnCell(row, 1);
192  logger.info("Selected hash lookup module in ingest job settings panel");
193  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
194  jbo1.pushNoBlock();
195  logger.info("Pushed Global Settings button for hash lookup module in ingest job settings panel");
196  }
197 
198  public void testConfigureHash() {
199  logger.info("Hash Configure");
200  JDialog hashMainDialog = JDialogOperator.waitJDialog("Global Hash Lookup Settings", false, false);
201  JDialogOperator hashMainDialogOperator = new JDialogOperator(hashMainDialog);
202  List<String> databases = new ArrayList<>();
203  databases.add(getEscapedPath(System.getProperty("nsrl_path")));
204  databases.add(getEscapedPath(System.getProperty("known_bad_path")));
205  databases.stream().map((database) -> {
206  JButtonOperator importButtonOperator = new JButtonOperator(hashMainDialogOperator, "Import");
207  importButtonOperator.pushNoBlock();
208  JDialog addDatabaseDialog = JDialogOperator.waitJDialog("Import Hash Database", false, false);
209  JDialogOperator addDatabaseDialogOperator = new JDialogOperator(addDatabaseDialog);
210  JButtonOperator browseButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "Open...", 0);
211  browseButtonOperator.pushNoBlock();
212  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
213  fileChooserOperator.chooseFile(database);
214  JButtonOperator okButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "OK", 0);
215  return okButtonOperator;
216  }).map((okButtonOperator) -> {
217  okButtonOperator.pushNoBlock();
218  return okButtonOperator;
219  }).forEach((_item) -> {
220  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
221  });
222  // Used if the database has no index
223  //JDialog jd3 = JDialogOperator.waitJDialog("No Index Exists", false, false);
224  //JDialogOperator jdo3 = new JDialogOperator(jd3);
225  //JButtonOperator jbo3 = new JButtonOperator(jdo3, "Yes", 0);
226  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
227  //jbo3.pushNoBlock();
228  JButtonOperator jbo4 = new JButtonOperator(hashMainDialogOperator, "OK", 0);
229  jbo4.pushNoBlock();
230  }
231 
232  public void testConfigureIngest2() {
233  logger.info("Looking for keyword search module in ingest job settings panel");
234  WizardOperator wo = new WizardOperator("Add Data Source");
235  while(!wo.btNext().isEnabled()){
236  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
237  }
238  JTableOperator jto = new JTableOperator(wo, 0);
239  int row = jto.findCellRow("Keyword Search", 2, 0);
240  jto.clickOnCell(row, 1);
241  logger.info("Selected keyword search module in ingest job settings panel");
242  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
243  jbo1.pushNoBlock();
244  logger.info("Pushed Global Settings button for keyword search module in ingest job settings panel");
245  }
246 
247  public void testConfigureSearch() {
248  logger.info("Search Configure");
249  JDialog jd = JDialogOperator.waitJDialog("Global Keyword Search Settings", false, false);
250  JDialogOperator jdo = new JDialogOperator(jd);
251  String words = getEscapedPath(System.getProperty("keyword_path"));
252  JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0);
253  jbo0.pushNoBlock();
254  JFileChooserOperator jfco0 = new JFileChooserOperator();
255  jfco0.chooseFile(words);
256  JTableOperator jto = new JTableOperator(jdo, 0);
257  jto.clickOnCell(0, 0);
258  new Timeout("pausing", 1000).sleep(); // give it a second to process
259  if (Boolean.parseBoolean(System.getProperty("mugen_mode"))) {
260  JTabbedPaneOperator jtpo = new JTabbedPaneOperator(jdo);
261  jtpo.selectPage("String Extraction");
262  JCheckBoxOperator jcbo0 = new JCheckBoxOperator(jtpo, "Arabic (Arabic)");
263  jcbo0.doClick();
264  JCheckBoxOperator jcbo1 = new JCheckBoxOperator(jtpo, "Han (Chinese, Japanese, Korean)");
265  jcbo1.doClick();
266  new Timeout("pausing", 1000).sleep(); // give it a second to process
267  }
268  JButtonOperator jbo2 = new JButtonOperator(jdo, "OK", 0);
269  jbo2.pushNoBlock();
270  WizardOperator wo = new WizardOperator("Add Data Source");
271  new Timeout("pausing", 10000).sleep(); // let things catch up
272  wo.btNext().clickMouse();
273  }
274 
275  public void testIngest() {
276  logger.info("Ingest 3");
277  new Timeout("pausing", 10000).sleep(); // wait for ingest to actually start
278  long startIngest = System.currentTimeMillis();
280  while (man.isIngestRunning()) {
281  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
282  }
283  logger.log(Level.INFO, "Ingest (including enqueue) took {0}ms", (System.currentTimeMillis() - startIngest));
284  // allow keyword search to finish saving artifacts, just in case
285  // but randomize the timing so that we don't always get the same error
286  // consistently, making it seem like default behavior
287  Random rand = new Random();
288  new Timeout("pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
289  screenshot("Finished Ingest");
290 
291  }
292 
294  logger.info("Generate Report Toolbars");
295  MainWindowOperator mwo = MainWindowOperator.getDefault();
296  JButtonOperator jbo = new JButtonOperator(mwo, "Generate Report");
297  jbo.pushNoBlock();
298  new Timeout("pausing", 5000).sleep();
299  }
300 
301  public void testGenerateReportButton() throws IOException {
302  logger.info("Generate Report Button");
303  resetTimeouts("ComponentOperator.WaitComponentTimeout", 240000);
304  JDialog reportDialog = JDialogOperator.waitJDialog("Generate Report", false, false);
305  JDialogOperator reportDialogOperator = new JDialogOperator(reportDialog);
306  JListOperator listOperator = new JListOperator(reportDialogOperator);
307  JButtonOperator jbo0 = new JButtonOperator(reportDialogOperator, "Next");
308  DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss");
309  Date date = new Date();
310  String datenotime = dateFormat.format(date);
311  listOperator.clickOnItem(0, 1);
312  jbo0.pushNoBlock();
313  new Timeout("pausing", 2000).sleep();
314  JButtonOperator jbo1 = new JButtonOperator(reportDialogOperator, "Finish");
315  jbo1.pushNoBlock();
316  JDialog previewDialog = JDialogOperator.waitJDialog("Progress", false, false);
317  screenshot("Progress");
318  JDialogOperator previewDialogOperator = new JDialogOperator(previewDialog);
319  JLabelOperator.waitJLabel(previewDialog, "Complete", false, false);
320  JButtonOperator jbo2 = new JButtonOperator(previewDialogOperator, "Close");
321  jbo2.pushNoBlock();
322  new Timeout("pausing", 10000).sleep();
323  System.setProperty("ReportStr", datenotime);
324  screenshot("Done Testing");
325  }
326 
327  public void screenshot(String name) {
328  logger.info("Taking screenshot.");
329  try {
330  Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
331  BufferedImage capture = new Robot().createScreenCapture(screenRect);
332  String outPath = getEscapedPath(System.getProperty("out_path"));
333  ImageIO.write(capture, "png", new File(outPath + "\\" + name + ".png"));
334  new Timeout("pausing", 1000).sleep(); // give it a second to save
335  } catch (IOException ex) {
336  logger.log(Level.WARNING, "IOException taking screenshot.", ex);
337  } catch (AWTException ex) {
338  logger.log(Level.WARNING, "AWTException taking screenshot.", ex);
339 
340  }
341  }
342 
343  /*
344  * Nightly test failed at WindowWaiter.WaitWindowTimeOut because of TimeoutExpiredException. So we
345  * use this conveninent method to override the default Jemmy Timeouts value.
346  */
347 
348  private Timeouts resetTimeouts(String name, int value) {
349  Timeouts timeouts = JemmyProperties.getCurrentTimeouts();
350  timeouts.setTimeout(name, value);
351  return timeouts;
352  }
353 
354  private void setMultiUserPerferences() {
356  //PostgreSQL database settings
357  CaseDbConnectionInfo connectionInfo = new CaseDbConnectionInfo(
358  System.getProperty("dbHost"),
359  System.getProperty("dbPort"),
360  System.getProperty("dbUserName"),
361  System.getProperty("dbPassword"),
362  TskData.DbType.POSTGRESQL);
363  try {
365  } catch (UserPreferencesException ex) {
366  logger.log(Level.SEVERE, "Error saving case database connection info", ex); //NON-NLS
367  }
368  //Solr Index settings
369  UserPreferences.setIndexingServerHost(System.getProperty("solrHost"));
370  UserPreferences.setIndexingServerPort(Integer.parseInt(System.getProperty("solrPort")));
371  //ActiveMQ Message Service Setting, username and password field are empty
373  System.getProperty("messageServiceHost"),
374  Integer.parseInt(System.getProperty("messageServicePort")),
375  "",
376  "");
377  try {
379  } catch (UserPreferencesException ex) {
380  logger.log(Level.SEVERE, "Error saving messaging service connection info", ex); //NON-NLS
381  }
382  }
383 }
static synchronized IngestManager getInstance()
static void setIsMultiUserModeEnabled(boolean enabled)
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo)
Timeouts resetTimeouts(String name, int value)
static void setIndexingServerHost(String hostName)

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