refactor image import and add Alpine docker image

- dynamic import of QR reader
- build docker also for arm64
This commit is contained in:
scito 2022-12-24 01:59:35 +01:00 committed by Roland Kurmann
parent 915efcf192
commit 9d052dc78a
21 changed files with 910 additions and 521 deletions

View file

@ -23,9 +23,8 @@ from utils import Capturing
import extract_otp_secret_keys
class TestExtract(unittest.TestCase):
def test_happy_path(self):
class TestQRImageExtract(unittest.TestCase):
def test_img_qr_reader_happy_path(self):
with Capturing() as actual_output:
extract_otp_secret_keys.main(['test/test_googleauth_export.png'])
@ -36,34 +35,48 @@ class TestExtract(unittest.TestCase):
self.assertEqual(actual_output, expected_output)
def test_no_qr_code_in_image(self):
def test_img_qr_reader_no_qr_code_in_image(self):
with Capturing() as actual_output:
extract_otp_secret_keys.main(['test/lena_std.tif'])
with self.assertRaises(SystemExit) as context:
extract_otp_secret_keys.main(['test/lena_std.tif'])
expected_output =\
['', 'ERROR: Unable to read QR Code from file.', 'input file: test/lena_std.tif']
self.assertEqual(actual_output, expected_output)
self.assertEqual(context.exception.code, 1)
def test_nonexistent_file(self):
def test_img_qr_reader_nonexistent_file(self):
with Capturing() as actual_output:
extract_otp_secret_keys.main(['test/nonexistent.bmp'])
with self.assertRaises(SystemExit) as context:
extract_otp_secret_keys.main(['test/nonexistent.bmp'])
expected_output =\
['', 'ERROR: Input file provided is non-existent or not a file.', 'input file: test/nonexistent.bmp']
self.assertEqual(actual_output, expected_output)
self.assertEqual(context.exception.code, 1)
def test_non_image_file(self):
def test_img_qr_reader_non_image_file(self):
with Capturing() as actual_output:
extract_otp_secret_keys.main(['test/text_masquerading_as_image.jpeg'])
with self.assertRaises(SystemExit) as context:
extract_otp_secret_keys.main(['test/text_masquerading_as_image.jpeg'])
expected_output =\
['', 'ERROR: Unable to open file for reading. Please ensure that you have read access to the file and that '
'the file is a valid image file.', 'input file: test/text_masquerading_as_image.jpeg']
expected_output = [
'',
'WARN: line is not a otpauth-migration:// URL',
'input file: test/text_masquerading_as_image.jpeg',
'line "This is just a text file masquerading as an image file."',
'Probably a wrong file was given',
'',
'ERROR: no data query parameter in input URL',
'input file: test/text_masquerading_as_image.jpeg',
'line "This is just a text file masquerading as an image file."',
'Probably a wrong file was given'
]
self.assertEqual(actual_output, expected_output)
self.assertEqual(context.exception.code, 1)
def setUp(self):
self.cleanup()