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

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.