Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Fix parsing and test strings now binary to reflect type of check_output
Browse files Browse the repository at this point in the history
  • Loading branch information
emkll committed Aug 2, 2019
1 parent 0a98222 commit 793fe5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions securedrop_export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/sd-export-config-bad-2.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"pci_bus_id": "two"
"no_pci_bus_id": "nope"
}
8 changes: 4 additions & 4 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 793fe5c

Please sign in to comment.