Autopsy  4.19.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-2020 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 
147  // pass by host menu with auto-generate host (which should already be selected)
148  wo.btNext().clickMouse();
149 
150  //select the toggle button for Disk Image or VM File it will be the first button created and proceed to next panel
151  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 0);
152  jtbo.clickMouse();
153  wo.btNext().clickMouse();
154  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 0);
155  String img_path = getEscapedPath(System.getProperty("img_path"));
156  String imageDir = img_path;
157  ((JTextComponent) jtfo0.getSource()).setText(imageDir);
158  JComboBoxOperator comboBoxOperator = new JComboBoxOperator(wo, 0);
159  comboBoxOperator.setSelectedItem("(GMT-5:00) America/New_York");
160  wo.btNext().clickMouse();
161  } catch (TimeoutExpiredException ex) {
162  screenshot("TimeoutScreenshot");
163  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
164  }
165  }
166 
168  try {
169  /*
170  * This time out is to give time for creating case database and
171  * opening solr index
172  */
173  new Timeout("pausing", 120000).sleep();
174  logger.info("Starting Add Logical Files process");
175  WizardOperator wo = new WizardOperator("Add Data Source");
176  wo.setTimeouts(setTimeout("WindowWaiter.WaitWindowTimeOut", 240000));
177  while (!wo.btNext().isEnabled()) {
178  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
179  }
180 
181  // pass by host menu with auto-generate host (which should already be selected)
182  wo.btNext().clickMouse();
183 
184  //select the toggle button for Logical Files it will be the third button created and proceed to next panel
185  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 2);
186  jtbo.clickMouse();
187  wo.btNext().clickMouse();
188  JButtonOperator addButtonOperator = new JButtonOperator(wo, "Add");
189  addButtonOperator.pushNoBlock();
190  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
191  fileChooserOperator.setCurrentDirectory(new File(getEscapedPath(System.getProperty("img_path"))));
192  // set the current directory one level above the directory containing logicalFileSet folder.
193  fileChooserOperator.goUpLevel();
194  fileChooserOperator.chooseFile(new File(getEscapedPath(System.getProperty("img_path"))).getName());
195  wo.btNext().clickMouse();
196  } catch (TimeoutExpiredException ex) {
197  screenshot("TimeoutScreenshot");
198  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
199  }
200  }
201 
202  public void testAddSourceWizard1() {
203  try {
204  WizardOperator wo = new WizardOperator("Add Data Source");
205  while (!wo.btFinish().isEnabled()) {
206  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
207  }
208  logger.log(Level.INFO, "Add image took {0}ms", (System.currentTimeMillis() - start));
209  wo.btFinish().clickMouse();
210  } catch (TimeoutExpiredException ex) {
211  screenshot("TimeoutScreenshot");
212  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
213  }
214  }
215 
216  public void testConfigureIngest1() {
217  try {
218  /*
219  * This timeout is to allow the setup for the ingest job settings
220  * panel to complete.
221  */
222  new Timeout("pausing", 10000).sleep();
223 
224  logger.info("Looking for hash lookup module in ingest job settings panel");
225  WizardOperator wo = new WizardOperator("Add Data Source");
226  while (!wo.btNext().isEnabled()) {
227  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
228  }
229  JTableOperator jto = new JTableOperator(wo, 0);
230  int row = jto.findCellRow("Hash Lookup", 2, 0);
231  jto.clickOnCell(row, 1);
232  logger.info("Selected hash lookup module in ingest job settings panel");
233  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
234  jbo1.pushNoBlock();
235  logger.info("Pushed Global Settings button for hash lookup module in ingest job settings panel");
236  } catch (TimeoutExpiredException ex) {
237  screenshot("TimeoutScreenshot");
238  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
239  }
240  }
241 
242  public void testConfigureHash() {
243  try {
244  logger.info("Hash Configure");
245  JDialog hashMainDialog = JDialogOperator.waitJDialog("Global Hash Lookup Settings", false, false);
246  JDialogOperator hashMainDialogOperator = new JDialogOperator(hashMainDialog);
247  List<String> databases = new ArrayList<>();
248  databases.add(getEscapedPath(System.getProperty("nsrl_path")));
249  databases.add(getEscapedPath(System.getProperty("known_bad_path")));
250  databases.stream().map((database) -> {
251  JButtonOperator importButtonOperator = new JButtonOperator(hashMainDialogOperator, "Import");
252  importButtonOperator.pushNoBlock();
253  JDialog addDatabaseDialog = JDialogOperator.waitJDialog("Import Hash Set", false, false);
254  JDialogOperator addDatabaseDialogOperator = new JDialogOperator(addDatabaseDialog);
255  JButtonOperator browseButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "Open...", 0);
256  browseButtonOperator.pushNoBlock();
257  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
258  fileChooserOperator.chooseFile(database);
259  JButtonOperator okButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "OK", 0);
260  return okButtonOperator;
261  }).map((okButtonOperator) -> {
262  okButtonOperator.pushNoBlock();
263  return okButtonOperator;
264  }).forEach((_item) -> {
265  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
266  });
267  // Used if the database has no index
268  //JDialog jd3 = JDialogOperator.waitJDialog("No Index Exists", false, false);
269  //JDialogOperator jdo3 = new JDialogOperator(jd3);
270  //JButtonOperator jbo3 = new JButtonOperator(jdo3, "Yes", 0);
271  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
272  //jbo3.pushNoBlock();
273  JButtonOperator jbo4 = new JButtonOperator(hashMainDialogOperator, "OK", 0);
274  jbo4.pushNoBlock();
275  } catch (TimeoutExpiredException ex) {
276  screenshot("TimeoutScreenshot");
277  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
278  }
279  }
280 
281  public void testConfigureIngest2() {
282  try {
283  logger.info("Looking for keyword search module in ingest job settings panel");
284  WizardOperator wo = new WizardOperator("Add Data Source");
285  while (!wo.btNext().isEnabled()) {
286  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
287  }
288  JTableOperator jto = new JTableOperator(wo, 0);
289  int row = jto.findCellRow("Keyword Search", 2, 0);
290  jto.clickOnCell(row, 1);
291  logger.info("Selected keyword search module in ingest job settings panel");
292  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
293  jbo1.pushNoBlock();
294  logger.info("Pushed Global Settings button for keyword search module in ingest job settings panel");
295  } catch (TimeoutExpiredException ex) {
296  screenshot("TimeoutScreenshot");
297  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
298  }
299  }
300 
301  public void testConfigureSearch() {
302  try {
303  logger.info("Search Configure");
304  JDialog jd = JDialogOperator.waitJDialog("Global Keyword Search Settings", false, false);
305  JDialogOperator jdo = new JDialogOperator(jd);
306  String words = getEscapedPath(System.getProperty("keyword_path"));
307  JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0);
308  jbo0.pushNoBlock();
309  JFileChooserOperator jfco0 = new JFileChooserOperator();
310  jfco0.chooseFile(words);
311  JTableOperator jto = new JTableOperator(jdo, 0);
312  jto.clickOnCell(0, 0);
313  new Timeout("pausing", 1000).sleep(); // give it a second to process
314  if (Boolean.parseBoolean(System.getProperty("mugen_mode"))) {
315  JTabbedPaneOperator jtpo = new JTabbedPaneOperator(jdo);
316  jtpo.selectPage("String Extraction");
317  JCheckBoxOperator jcbo0 = new JCheckBoxOperator(jtpo, "Arabic (Arabic)");
318  jcbo0.doClick();
319  JCheckBoxOperator jcbo1 = new JCheckBoxOperator(jtpo, "Han (Chinese, Japanese, Korean)");
320  jcbo1.doClick();
321  new Timeout("pausing", 1000).sleep(); // give it a second to process
322  }
323  JButtonOperator jbo2 = new JButtonOperator(jdo, "OK", 0);
324  jbo2.pushNoBlock();
325  WizardOperator wo = new WizardOperator("Add Data Source");
326  new Timeout("pausing", 10000).sleep(); // let things catch up
327  wo.btNext().clickMouse();
328  } catch (TimeoutExpiredException ex) {
329  screenshot("TimeoutScreenshot");
330  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
331  }
332  }
333 
334  public void testIngest() {
335  try {
336  logger.info("Ingest 3");
337  new Timeout("pausing", 10000).sleep(); // wait for ingest to actually start
338  long startIngest = System.currentTimeMillis();
340  while (man.isIngestRunning()) {
341  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
342  }
343  logger.log(Level.INFO, "Ingest (including enqueue) took {0}ms", (System.currentTimeMillis() - startIngest));
344  // allow keyword search to finish saving artifacts, just in case
345  // but randomize the timing so that we don't always get the same error
346  // consistently, making it seem like default behavior
347  Random rand = new Random();
348  new Timeout("pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
349  } catch (TimeoutExpiredException ex) {
350  screenshot("TimeoutScreenshot");
351  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
352  }
353 
354  }
355 
357  try {
358  logger.info("Data Sources Node");
359  MainWindowOperator mwo = MainWindowOperator.getDefault();
360  JTreeOperator jto = new JTreeOperator(mwo, "Data Sources");
361  String[] nodeNames = {"Data Sources"};
362  TreePath tp = jto.findPath(nodeNames);
363  expandNodes(jto, tp);
364  } catch (TimeoutExpiredException ex) {
365  screenshot("TimeoutScreenshot");
366  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
367  }
368  }
369 
371  try {
372  logger.info("Generate Report Toolbars");
373  MainWindowOperator mwo = MainWindowOperator.getDefault();
374  JButtonOperator jbo = new JButtonOperator(mwo, "Generate Report");
375  jbo.pushNoBlock();
376  } catch (TimeoutExpiredException ex) {
377  screenshot("TimeoutScreenshot");
378  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
379  }
380  }
381 
382  public void testGenerateReportButton() throws IOException {
383  try {
384  logger.info("Generate Report Button");
385  setTimeout("ComponentOperator.WaitComponentTimeout", 240000);
386  JDialog reportDialog = JDialogOperator.waitJDialog("Generate Report", false, false);
387  JDialogOperator reportDialogOperator = new JDialogOperator(reportDialog);
388  JListOperator listOperator = new JListOperator(reportDialogOperator);
389  JButtonOperator jbo0 = new JButtonOperator(reportDialogOperator, "Next");
390  DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss");
391  Date date = new Date();
392  String datenotime = dateFormat.format(date);
393  listOperator.clickOnItem(0, 1);
394  jbo0.pushNoBlock();
395  new Timeout("pausing", 2000).sleep();
396 
397  // Next button on the data source selection panel
398  JButtonOperator dataSourceSelectionPanelNext = new JButtonOperator(reportDialogOperator, "Next");
399  dataSourceSelectionPanelNext.pushNoBlock();
400  new Timeout("pausing", 2000).sleep();
401 
402  JButtonOperator jbo1 = new JButtonOperator(reportDialogOperator, "Finish");
403  jbo1.pushNoBlock();
404  JDialog previewDialog = JDialogOperator.waitJDialog("Progress", false, false);
405  JDialogOperator previewDialogOperator = new JDialogOperator(previewDialog);
406  JLabelOperator.waitJLabel(previewDialog, "Complete", false, false);
407  JButtonOperator jbo2 = new JButtonOperator(previewDialogOperator, "Close");
408  jbo2.pushNoBlock();
409  new Timeout("pausing", 10000).sleep();
410  System.setProperty("ReportStr", datenotime);
411  } catch (TimeoutExpiredException ex) {
412  screenshot("TimeoutScreenshot");
413  logger.log(Level.SEVERE, "AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
414  }
415  }
416 
417  public void screenshot(String name) {
418  String outPath = getEscapedPath(System.getProperty("out_path"));
419  File screenShotFile = new File(outPath + "\\" + name + ".png");
420  if (!screenShotFile.exists()) {
421  logger.info("Taking screenshot.");
422  try {
423  Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
424  BufferedImage capture = new Robot().createScreenCapture(screenRect);
425  ImageIO.write(capture, "png", screenShotFile);
426  new Timeout("pausing", 1000).sleep(); // give it a second to save
427  } catch (IOException ex) {
428  logger.log(Level.WARNING, "IOException taking screenshot.", ex);
429  } catch (AWTException ex) {
430  logger.log(Level.WARNING, "AWTException taking screenshot.", ex);
431  }
432  }
433  }
434 
435  /*
436  * Nightly test failed at WindowWaiter.WaitWindowTimeOut because of
437  * TimeoutExpiredException. So we use this conveninent method to override
438  * the default Jemmy Timeouts value.
439  */
440  private Timeouts setTimeout(String name, int value) {
441  Timeouts timeouts = JemmyProperties.getCurrentTimeouts();
442  timeouts.setTimeout(name, value);
443  return timeouts;
444  }
445 
446  private void setMultiUserPerferences() {
448  //PostgreSQL database settings
449  CaseDbConnectionInfo connectionInfo = new CaseDbConnectionInfo(
450  System.getProperty("dbHost"),
451  System.getProperty("dbPort"),
452  System.getProperty("dbUserName"),
453  System.getProperty("dbPassword"),
454  TskData.DbType.POSTGRESQL);
455  try {
457  } catch (UserPreferencesException ex) {
458  logger.log(Level.SEVERE, "Error saving case database connection info", ex); //NON-NLS
459  }
460  //Solr Index settings
461  UserPreferences.setIndexingServerHost(System.getProperty("solrHost"));
462  UserPreferences.setIndexingServerPort(Integer.parseInt(System.getProperty("solrPort")));
463  //ActiveMQ Message Service Setting, username and password field are empty
465  System.getProperty("messageServiceHost"),
466  Integer.parseInt(System.getProperty("messageServicePort")),
467  "",
468  "");
469  try {
471  } catch (UserPreferencesException ex) {
472  logger.log(Level.SEVERE, "Error saving messaging service connection info", ex); //NON-NLS
473  }
474 
475  UserPreferences.setZkServerHost(System.getProperty("zooKeeperHost"));
476  UserPreferences.setZkServerPort(System.getProperty("zooKeeperPort"));
477  }
478 
479  private void expandNodes(JTreeOperator jto, TreePath tp) {
480  try {
481  jto.expandPath(tp);
482  for (TreePath t : jto.getChildPaths(tp)) {
483  expandNodes(jto, t);
484  }
485  } catch (NoSuchPathException ne) {
486  logger.log(Level.SEVERE, "Error expanding tree path", ne);
487  }
488  }
489 }
static void setZkServerHost(String hostName)
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-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.