Autopsy  4.4
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  NbDialogOperator nbdo = new NbDialogOperator(title);
98  JButtonOperator jbo = new JButtonOperator(nbdo, 0); // the "New Case" button
99  jbo.pushNoBlock();
100  }
101 
102  public void testNewCaseWizard() {
103  logger.info("New Case Wizard");
104  WizardOperator wo = new WizardOperator("New Case Information");
105  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 1);
106  jtfo0.typeText("AutopsyTestCase"); // Name the case "AutopsyTestCase"
107  JTextFieldOperator jtfo1 = new JTextFieldOperator(wo, 2);
108  jtfo1.typeText(getEscapedPath(System.getProperty("out_path")));
109  wo.btNext().clickMouse();
110  JTextFieldOperator jtfo2 = new JTextFieldOperator(wo, 0);
111  jtfo2.typeText("000"); // Set the case number
112  JTextFieldOperator jtfo3 = new JTextFieldOperator(wo, 1);
113  jtfo3.typeText("Examiner 1"); // Set the case examiner
114  start = System.currentTimeMillis();
115  wo.btFinish().clickMouse();
116  }
117 
119  /*
120  * This time out is to give time for creating case database and opening solr index
121  */
122  new Timeout("pausing", 120000).sleep();
123  logger.info("Starting Add Image process");
124  WizardOperator wo = new WizardOperator("Add Data Source");
125  wo.setTimeouts(resetTimeouts("WindowWaiter.WaitWindowTimeOut", 240000));
126  while(!wo.btNext().isEnabled()){
127  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
128  }
129  //select the toggle button for Disk Image or VM File it will be the first button created and proceed to next panel
130  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 0);
131  jtbo.clickMouse();
132  wo.btNext().clickMouse();
133  JTextFieldOperator jtfo0 = new JTextFieldOperator(wo, 0);
134  String img_path = getEscapedPath(System.getProperty("img_path"));
135  String imageDir = img_path;
136  ((JTextComponent) jtfo0.getSource()).setText(imageDir);
137  JComboBoxOperator comboBoxOperator = new JComboBoxOperator(wo, 0);
138  comboBoxOperator.setSelectedItem("(GMT-5:00) America/New_York");
139  wo.btNext().clickMouse();
140  }
141 
143  /*
144  * This time out is to give time for creating case database and opening solr index
145  */
146  new Timeout("pausing", 120000).sleep();
147  logger.info("Starting Add Logical Files process");
148  WizardOperator wo = new WizardOperator("Add Data Source");
149  wo.setTimeouts(resetTimeouts("WindowWaiter.WaitWindowTimeOut", 240000));
150  while(!wo.btNext().isEnabled()){
151  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
152  }
153  //select the toggle button for Logical Files it will be the third button created and proceed to next panel
154  JToggleButtonOperator jtbo = new JToggleButtonOperator(wo, 2);
155  jtbo.clickMouse();
156  wo.btNext().clickMouse();
157  JButtonOperator addButtonOperator = new JButtonOperator(wo, "Add");
158  addButtonOperator.pushNoBlock();
159  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
160  fileChooserOperator.setCurrentDirectory(new File(getEscapedPath(System.getProperty("img_path"))));
161  // set the current directory one level above the directory containing logicalFileSet folder.
162  fileChooserOperator.goUpLevel();
163  fileChooserOperator.chooseFile(new File(getEscapedPath(System.getProperty("img_path"))).getName());
164  wo.btNext().clickMouse();
165  }
166 
167  public void testAddSourceWizard1() {
168  WizardOperator wo = new WizardOperator("Add Data Source");
169  while (!wo.btFinish().isEnabled()) {
170  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
171  }
172  logger.log(Level.INFO, "Add image took {0}ms", (System.currentTimeMillis() - start));
173  wo.btFinish().clickMouse();
174  }
175 
176  public void testConfigureIngest1() {
177  /*
178  * This timeout is to allow the setup for the ingest job settings panel
179  * to complete.
180  */
181  new Timeout("pausing", 10000).sleep();
182 
183  logger.info("Looking for hash lookup module in ingest job settings panel");
184  WizardOperator wo = new WizardOperator("Add Data Source");
185  while(!wo.btNext().isEnabled()){
186  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
187  }
188  JTableOperator jto = new JTableOperator(wo, 0);
189  int row = jto.findCellRow("Hash Lookup", 2, 0);
190  jto.clickOnCell(row, 1);
191  logger.info("Selected hash lookup module in ingest job settings panel");
192  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
193  jbo1.pushNoBlock();
194  logger.info("Pushed Global Settings button for hash lookup module in ingest job settings panel");
195  }
196 
197  public void testConfigureHash() {
198  logger.info("Hash Configure");
199  JDialog hashMainDialog = JDialogOperator.waitJDialog("Global Hash Lookup Settings", false, false);
200  JDialogOperator hashMainDialogOperator = new JDialogOperator(hashMainDialog);
201  List<String> databases = new ArrayList<>();
202  databases.add(getEscapedPath(System.getProperty("nsrl_path")));
203  databases.add(getEscapedPath(System.getProperty("known_bad_path")));
204  databases.stream().map((database) -> {
205  JButtonOperator importButtonOperator = new JButtonOperator(hashMainDialogOperator, "Import");
206  importButtonOperator.pushNoBlock();
207  JDialog addDatabaseDialog = JDialogOperator.waitJDialog("Import Hash Database", false, false);
208  JDialogOperator addDatabaseDialogOperator = new JDialogOperator(addDatabaseDialog);
209  JButtonOperator browseButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "Open...", 0);
210  browseButtonOperator.pushNoBlock();
211  JFileChooserOperator fileChooserOperator = new JFileChooserOperator();
212  fileChooserOperator.chooseFile(database);
213  JButtonOperator okButtonOperator = new JButtonOperator(addDatabaseDialogOperator, "OK", 0);
214  return okButtonOperator;
215  }).map((okButtonOperator) -> {
216  okButtonOperator.pushNoBlock();
217  return okButtonOperator;
218  }).forEach((_item) -> {
219  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
220  });
221  // Used if the database has no index
222  //JDialog jd3 = JDialogOperator.waitJDialog("No Index Exists", false, false);
223  //JDialogOperator jdo3 = new JDialogOperator(jd3);
224  //JButtonOperator jbo3 = new JButtonOperator(jdo3, "Yes", 0);
225  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
226  //jbo3.pushNoBlock();
227  JButtonOperator jbo4 = new JButtonOperator(hashMainDialogOperator, "OK", 0);
228  jbo4.pushNoBlock();
229  }
230 
231  public void testConfigureIngest2() {
232  logger.info("Looking for keyword search module in ingest job settings panel");
233  WizardOperator wo = new WizardOperator("Add Data Source");
234  while(!wo.btNext().isEnabled()){
235  new Timeout("pausing", 1000).sleep(); // give it a second till the Add Data Source dialog enabled
236  }
237  JTableOperator jto = new JTableOperator(wo, 0);
238  int row = jto.findCellRow("Keyword Search", 2, 0);
239  jto.clickOnCell(row, 1);
240  logger.info("Selected keyword search module in ingest job settings panel");
241  JButtonOperator jbo1 = new JButtonOperator(wo, "Global Settings");
242  jbo1.pushNoBlock();
243  logger.info("Pushed Global Settings button for keyword search module in ingest job settings panel");
244  }
245 
246  public void testConfigureSearch() {
247  logger.info("Search Configure");
248  JDialog jd = JDialogOperator.waitJDialog("Global Keyword Search Settings", false, false);
249  JDialogOperator jdo = new JDialogOperator(jd);
250  String words = getEscapedPath(System.getProperty("keyword_path"));
251  JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0);
252  jbo0.pushNoBlock();
253  JFileChooserOperator jfco0 = new JFileChooserOperator();
254  jfco0.chooseFile(words);
255  JTableOperator jto = new JTableOperator(jdo, 0);
256  jto.clickOnCell(0, 0);
257  new Timeout("pausing", 1000).sleep(); // give it a second to process
258  if (Boolean.parseBoolean(System.getProperty("mugen_mode"))) {
259  JTabbedPaneOperator jtpo = new JTabbedPaneOperator(jdo);
260  jtpo.selectPage("String Extraction");
261  JCheckBoxOperator jcbo0 = new JCheckBoxOperator(jtpo, "Arabic (Arabic)");
262  jcbo0.doClick();
263  JCheckBoxOperator jcbo1 = new JCheckBoxOperator(jtpo, "Han (Chinese, Japanese, Korean)");
264  jcbo1.doClick();
265  new Timeout("pausing", 1000).sleep(); // give it a second to process
266  }
267  JButtonOperator jbo2 = new JButtonOperator(jdo, "OK", 0);
268  jbo2.pushNoBlock();
269  WizardOperator wo = new WizardOperator("Add Data Source");
270  new Timeout("pausing", 10000).sleep(); // let things catch up
271  wo.btNext().clickMouse();
272  }
273 
274  public void testIngest() {
275  logger.info("Ingest 3");
276  new Timeout("pausing", 10000).sleep(); // wait for ingest to actually start
277  long startIngest = System.currentTimeMillis();
279  while (man.isIngestRunning()) {
280  new Timeout("pausing", 1000).sleep(); // give it a second (or five) to process
281  }
282  logger.log(Level.INFO, "Ingest (including enqueue) took {0}ms", (System.currentTimeMillis() - startIngest));
283  // allow keyword search to finish saving artifacts, just in case
284  // but randomize the timing so that we don't always get the same error
285  // consistently, making it seem like default behavior
286  Random rand = new Random();
287  new Timeout("pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
288  screenshot("Finished Ingest");
289 
290  }
291 
293  logger.info("Generate Report Toolbars");
294  MainWindowOperator mwo = MainWindowOperator.getDefault();
295  JButtonOperator jbo = new JButtonOperator(mwo, "Generate Report");
296  jbo.pushNoBlock();
297  new Timeout("pausing", 5000).sleep();
298  }
299 
300  public void testGenerateReportButton() throws IOException {
301  logger.info("Generate Report Button");
302  JDialog reportDialog = JDialogOperator.waitJDialog("Generate Report", false, false);
303  JDialogOperator reportDialogOperator = new JDialogOperator(reportDialog);
304  JListOperator listOperator = new JListOperator(reportDialogOperator);
305  JButtonOperator jbo0 = new JButtonOperator(reportDialogOperator, "Next");
306  DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss");
307  Date date = new Date();
308  String datenotime = dateFormat.format(date);
309  listOperator.clickOnItem(0, 1);
310  new Timeout("pausing", 2000).sleep();
311  jbo0.pushNoBlock();
312  new Timeout("pausing", 2000).sleep();
313  JButtonOperator jbo1 = new JButtonOperator(reportDialogOperator, "Finish");
314  jbo1.pushNoBlock();
315  new Timeout("pausing", 1000).sleep();
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: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.