2022-09-03 13:38:47 +00:00
|
|
|
# pytest for extract_otp_secret_keys.py
|
2022-09-03 12:31:09 +00:00
|
|
|
|
|
|
|
# Run tests:
|
2022-09-03 13:38:47 +00:00
|
|
|
# pytest
|
2022-09-03 12:31:09 +00:00
|
|
|
|
|
|
|
# Author: Scito (https://scito.ch)
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-09-03 21:47:43 +00:00
|
|
|
from utils import read_csv, read_json, remove_file, read_file_to_str
|
2022-09-03 12:31:09 +00:00
|
|
|
|
|
|
|
import extract_otp_secret_keys
|
|
|
|
|
2022-09-03 14:12:28 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
def test_extract_csv():
|
|
|
|
# Arrange
|
|
|
|
cleanup()
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
# Act
|
|
|
|
extract_otp_secret_keys.main(['-q', '-c', 'test_example_output.csv', 'example_export.txt'])
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
# Assert
|
|
|
|
expected_csv = read_csv('example_output.csv')
|
|
|
|
actual_csv = read_csv('test_example_output.csv')
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 14:12:28 +00:00
|
|
|
assert actual_csv == expected_csv
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
# Clean up
|
|
|
|
cleanup()
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 14:12:28 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
def test_extract_json():
|
|
|
|
# Arrange
|
|
|
|
cleanup()
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
# Act
|
|
|
|
extract_otp_secret_keys.main(['-q', '-j', 'test_example_output.json', 'example_export.txt'])
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 21:47:43 +00:00
|
|
|
# Assert
|
2022-09-03 13:38:47 +00:00
|
|
|
expected_json = read_json('example_output.json')
|
|
|
|
actual_json = read_json('test_example_output.json')
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
assert actual_json == expected_json
|
2022-09-03 12:31:09 +00:00
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
# Clean up
|
|
|
|
cleanup()
|
|
|
|
|
2022-09-03 14:12:28 +00:00
|
|
|
|
2022-09-03 21:47:43 +00:00
|
|
|
def test_extract_stdout(capsys):
|
|
|
|
# Act
|
|
|
|
extract_otp_secret_keys.main(['example_export.txt'])
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
|
|
|
expected_stdout = '''Name: pi@raspberrypi
|
|
|
|
Secret: 7KSQL2JTUDIS5EF65KLMRQIIGY
|
|
|
|
Issuer: raspberrypi
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
Name: pi@raspberrypi
|
|
|
|
Secret: 7KSQL2JTUDIS5EF65KLMRQIIGY
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
Name: pi@raspberrypi
|
|
|
|
Secret: 7KSQL2JTUDIS5EF65KLMRQIIGY
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
Name: pi@raspberrypi
|
|
|
|
Secret: 7KSQL2JTUDIS5EF65KLMRQIIGY
|
|
|
|
Issuer: raspberrypi
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
assert captured.out == expected_stdout
|
|
|
|
assert captured.err == ''
|
|
|
|
|
|
|
|
|
2022-09-07 19:58:03 +00:00
|
|
|
def test_extract_not_encoded_plus(capsys):
|
|
|
|
# Act
|
|
|
|
extract_otp_secret_keys.main(['test/test_plus_problem_export.txt'])
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
|
|
|
expected_stdout = '''Name: SerenityLabs:test1@serenitylabs.co.uk
|
|
|
|
Secret: A4RFDYMF4GSLUIBQV4ZP67OJEZ2XUQVM
|
|
|
|
Issuer: SerenityLabs
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
Name: SerenityLabs:test2@serenitylabs.co.uk
|
|
|
|
Secret: SCDDZ7PW5MOZLE3PQCAZM7L4S35K3UDX
|
|
|
|
Issuer: SerenityLabs
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
Name: SerenityLabs:test3@serenitylabs.co.uk
|
|
|
|
Secret: TR76272RVYO6EAEY2FX7W7R7KUDEGPJ4
|
|
|
|
Issuer: SerenityLabs
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
Name: SerenityLabs:test4@serenitylabs.co.uk
|
|
|
|
Secret: N2ILWSXSJUQUB7S6NONPJSC62NPG7EXN
|
|
|
|
Issuer: SerenityLabs
|
|
|
|
Type: OTP_TOTP
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
assert captured.out == expected_stdout
|
|
|
|
assert captured.err == ''
|
|
|
|
|
|
|
|
|
2022-09-03 21:47:43 +00:00
|
|
|
def test_extract_printqr(capsys):
|
|
|
|
# Act
|
|
|
|
extract_otp_secret_keys.main(['-p', 'example_export.txt'])
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
|
|
|
expected_stdout = read_file_to_str('test/printqr_output.txt')
|
|
|
|
|
|
|
|
assert captured.out == expected_stdout
|
|
|
|
assert captured.err == ''
|
|
|
|
|
|
|
|
|
2022-09-04 05:42:27 +00:00
|
|
|
def test_extract_verbose(capsys):
|
|
|
|
# Act
|
|
|
|
extract_otp_secret_keys.main(['-v', 'example_export.txt'])
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
|
|
|
expected_stdout = read_file_to_str('test/print_verbose_output.txt')
|
|
|
|
|
|
|
|
assert captured.out == expected_stdout
|
|
|
|
assert captured.err == ''
|
|
|
|
|
|
|
|
|
2022-09-03 13:38:47 +00:00
|
|
|
def cleanup():
|
|
|
|
remove_file('test_example_output.csv')
|
|
|
|
remove_file('test_example_output.json')
|