diff --git a/securedrop_export/export.py b/securedrop_export/export.py index 7e20728..536ae78 100755 --- a/securedrop_export/export.py +++ b/securedrop_export/export.py @@ -80,7 +80,9 @@ def __init__(self, archive, config_path): try: with open(config_path) as f: json_config = json.loads(f.read()) - self.pci_bus_id = int(json_config.get("pci_bus_id", 2)) + self.pci_bus_id = json_config.get("pci_bus_id", None) + if self.pci_bus_id is None: + raise except Exception: self.exit_gracefully("ERROR_CONFIG") @@ -132,12 +134,12 @@ def extract_tarball(self): self.exit_gracefully(msg) def check_usb_connected(self): - p = subprocess.check_output(["lsusb", "-s", self.pci_bus_id]) + p = subprocess.check_output(["lsusb", "-s", "{}:".format(self.pci_bus_id)]) # Empty string means a likely wrong pci_bus_id if p == "": msg = "ERROR_USB_CHECK" self.exit_gracefully(msg) - n_usb = len(p.rstrip().split("\n")) + n_usb = len(p.decode("utf-8").rstrip().split("\n")) # If there is one device, it is the root hub. if n_usb == 1: msg = "USB_NOT_CONNECTED" diff --git a/tests/sd-export-config-bad-2.json b/tests/sd-export-config-bad-2.json index 879fb83..f69e25b 100644 --- a/tests/sd-export-config-bad-2.json +++ b/tests/sd-export-config-bad-2.json @@ -1,3 +1,3 @@ { - "pci_bus_id": "two" + "no_pci_bus_id": "nope" } diff --git a/tests/test_export.py b/tests/test_export.py index 19be561..6c42cda 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -9,10 +9,10 @@ SAMPLE_OUTPUT_NO_PRINTER = b"network beh\nnetwork https\nnetwork ipp\nnetwork ipps\nnetwork http\nnetwork\nnetwork ipp14\nnetwork lpd" # noqa SAMPLE_OUTPUT_BOTHER_PRINTER = b"network beh\nnetwork https\nnetwork ipp\nnetwork ipps\nnetwork http\nnetwork\nnetwork ipp14\ndirect usb://Brother/HL-L2320D%20series?serial=A00000A000000\nnetwork lpd" # noqa -SAMPLE_OUTPUT_NO_USB = "Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub" # noqa -SAMPLE_OUTPUT_USB = "Bus 001 Device 002: ID 0781:5575 SanDisk Corp.\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub" # noqa +SAMPLE_OUTPUT_NO_USB = b"Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub" # noqa +SAMPLE_OUTPUT_USB = b"Bus 001 Device 002: ID 0781:5575 SanDisk Corp.\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub" # noqa SAMPLE_OUTPUT_USB_ERROR = "" -SAMPLE_OUTPUT_USB_ERROR2 = "h\ne\nl\nl\no" +SAMPLE_OUTPUT_USB_ERROR2 = b"h\ne\nl\nl\no" TEST_CONFIG = os.path.join(os.path.dirname(__file__), "sd-export-config.json") BAD_TEST_CONFIG = os.path.join(os.path.dirname(__file__), "sd-export-config-bad.json") ANOTHER_BAD_TEST_CONFIG = os.path.join(os.path.dirname(__file__), "sd-export-config-bad-2.json") @@ -46,7 +46,7 @@ def test_bad_sd_export_config_invalid_value(capsys): def test_good_sd_export_config(capsys): submission = export.SDExport("", TEST_CONFIG) - assert submission.pci_bus_id == 2 + assert submission.pci_bus_id == "2" def test_exit_gracefully_no_exception(capsys):