upgrade to protobuf 4.21.5, add quiet mode, refactor code, add unit test
- update README.txt - rename generated code directory - refactor code: - extract methods - make code testablepull/13/head
parent
c344c45e04
commit
c0d1cf6c51
@ -0,0 +1,5 @@
|
|||||||
|
name,secret,issuer,type,url
|
||||||
|
pi@raspberrypi,7KSQL2JTUDIS5EF65KLMRQIIGY,raspberrypi,OTP_TOTP,otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY&issuer=raspberrypi
|
||||||
|
pi@raspberrypi,7KSQL2JTUDIS5EF65KLMRQIIGY,,OTP_TOTP,otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY
|
||||||
|
pi@raspberrypi,7KSQL2JTUDIS5EF65KLMRQIIGY,,OTP_TOTP,otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY
|
||||||
|
pi@raspberrypi,7KSQL2JTUDIS5EF65KLMRQIIGY,raspberrypi,OTP_TOTP,otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY&issuer=raspberrypi
|
|
@ -0,0 +1,30 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "pi@raspberrypi",
|
||||||
|
"secret": "7KSQL2JTUDIS5EF65KLMRQIIGY",
|
||||||
|
"issuer": "raspberrypi",
|
||||||
|
"type": "OTP_TOTP",
|
||||||
|
"url": "otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY&issuer=raspberrypi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pi@raspberrypi",
|
||||||
|
"secret": "7KSQL2JTUDIS5EF65KLMRQIIGY",
|
||||||
|
"issuer": "",
|
||||||
|
"type": "OTP_TOTP",
|
||||||
|
"url": "otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pi@raspberrypi",
|
||||||
|
"secret": "7KSQL2JTUDIS5EF65KLMRQIIGY",
|
||||||
|
"issuer": "",
|
||||||
|
"type": "OTP_TOTP",
|
||||||
|
"url": "otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pi@raspberrypi",
|
||||||
|
"secret": "7KSQL2JTUDIS5EF65KLMRQIIGY",
|
||||||
|
"issuer": "raspberrypi",
|
||||||
|
"type": "OTP_TOTP",
|
||||||
|
"url": "otpauth://totp/pi%40raspberrypi?secret=7KSQL2JTUDIS5EF65KLMRQIIGY&issuer=raspberrypi"
|
||||||
|
}
|
||||||
|
]
|
@ -1,242 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
||||||
# source: google_auth.proto
|
|
||||||
"""Generated protocol buffer code."""
|
|
||||||
from google.protobuf import descriptor as _descriptor
|
|
||||||
from google.protobuf import message as _message
|
|
||||||
from google.protobuf import reflection as _reflection
|
|
||||||
from google.protobuf import symbol_database as _symbol_database
|
|
||||||
# @@protoc_insertion_point(imports)
|
|
||||||
|
|
||||||
_sym_db = _symbol_database.Default()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
|
||||||
name='google_auth.proto',
|
|
||||||
package='',
|
|
||||||
syntax='proto3',
|
|
||||||
serialized_options=None,
|
|
||||||
create_key=_descriptor._internal_create_key,
|
|
||||||
serialized_pb=b'\n\x11google_auth.proto\"\xb7\x03\n\x10MigrationPayload\x12\x37\n\x0eotp_parameters\x18\x01 \x03(\x0b\x32\x1f.MigrationPayload.OtpParameters\x12\x0f\n\x07version\x18\x02 \x01(\x05\x12\x12\n\nbatch_size\x18\x03 \x01(\x05\x12\x13\n\x0b\x62\x61tch_index\x18\x04 \x01(\x05\x12\x10\n\x08\x62\x61tch_id\x18\x05 \x01(\x05\x1a\xb7\x01\n\rOtpParameters\x12\x0e\n\x06secret\x18\x01 \x01(\x0c\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x0e\n\x06issuer\x18\x03 \x01(\t\x12.\n\talgorithm\x18\x04 \x01(\x0e\x32\x1b.MigrationPayload.Algorithm\x12\x0e\n\x06\x64igits\x18\x05 \x01(\x05\x12\'\n\x04type\x18\x06 \x01(\x0e\x32\x19.MigrationPayload.OtpType\x12\x0f\n\x07\x63ounter\x18\x07 \x01(\x03\",\n\tAlgorithm\x12\x10\n\x0c\x41LGO_INVALID\x10\x00\x12\r\n\tALGO_SHA1\x10\x01\"6\n\x07OtpType\x12\x0f\n\x0bOTP_INVALID\x10\x00\x12\x0c\n\x08OTP_HOTP\x10\x01\x12\x0c\n\x08OTP_TOTP\x10\x02\x62\x06proto3'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_MIGRATIONPAYLOAD_ALGORITHM = _descriptor.EnumDescriptor(
|
|
||||||
name='Algorithm',
|
|
||||||
full_name='MigrationPayload.Algorithm',
|
|
||||||
filename=None,
|
|
||||||
file=DESCRIPTOR,
|
|
||||||
create_key=_descriptor._internal_create_key,
|
|
||||||
values=[
|
|
||||||
_descriptor.EnumValueDescriptor(
|
|
||||||
name='ALGO_INVALID', index=0, number=0,
|
|
||||||
serialized_options=None,
|
|
||||||
type=None,
|
|
||||||
create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.EnumValueDescriptor(
|
|
||||||
name='ALGO_SHA1', index=1, number=1,
|
|
||||||
serialized_options=None,
|
|
||||||
type=None,
|
|
||||||
create_key=_descriptor._internal_create_key),
|
|
||||||
],
|
|
||||||
containing_type=None,
|
|
||||||
serialized_options=None,
|
|
||||||
serialized_start=361,
|
|
||||||
serialized_end=405,
|
|
||||||
)
|
|
||||||
_sym_db.RegisterEnumDescriptor(_MIGRATIONPAYLOAD_ALGORITHM)
|
|
||||||
|
|
||||||
_MIGRATIONPAYLOAD_OTPTYPE = _descriptor.EnumDescriptor(
|
|
||||||
name='OtpType',
|
|
||||||
full_name='MigrationPayload.OtpType',
|
|
||||||
filename=None,
|
|
||||||
file=DESCRIPTOR,
|
|
||||||
create_key=_descriptor._internal_create_key,
|
|
||||||
values=[
|
|
||||||
_descriptor.EnumValueDescriptor(
|
|
||||||
name='OTP_INVALID', index=0, number=0,
|
|
||||||
serialized_options=None,
|
|
||||||
type=None,
|
|
||||||
create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.EnumValueDescriptor(
|
|
||||||
name='OTP_HOTP', index=1, number=1,
|
|
||||||
serialized_options=None,
|
|
||||||
type=None,
|
|
||||||
create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.EnumValueDescriptor(
|
|
||||||
name='OTP_TOTP', index=2, number=2,
|
|
||||||
serialized_options=None,
|
|
||||||
type=None,
|
|
||||||
create_key=_descriptor._internal_create_key),
|
|
||||||
],
|
|
||||||
containing_type=None,
|
|
||||||
serialized_options=None,
|
|
||||||
serialized_start=407,
|
|
||||||
serialized_end=461,
|
|
||||||
)
|
|
||||||
_sym_db.RegisterEnumDescriptor(_MIGRATIONPAYLOAD_OTPTYPE)
|
|
||||||
|
|
||||||
|
|
||||||
_MIGRATIONPAYLOAD_OTPPARAMETERS = _descriptor.Descriptor(
|
|
||||||
name='OtpParameters',
|
|
||||||
full_name='MigrationPayload.OtpParameters',
|
|
||||||
filename=None,
|
|
||||||
file=DESCRIPTOR,
|
|
||||||
containing_type=None,
|
|
||||||
create_key=_descriptor._internal_create_key,
|
|
||||||
fields=[
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='secret', full_name='MigrationPayload.OtpParameters.secret', index=0,
|
|
||||||
number=1, type=12, cpp_type=9, label=1,
|
|
||||||
has_default_value=False, default_value=b"",
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='name', full_name='MigrationPayload.OtpParameters.name', index=1,
|
|
||||||
number=2, type=9, cpp_type=9, label=1,
|
|
||||||
has_default_value=False, default_value=b"".decode('utf-8'),
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='issuer', full_name='MigrationPayload.OtpParameters.issuer', index=2,
|
|
||||||
number=3, type=9, cpp_type=9, label=1,
|
|
||||||
has_default_value=False, default_value=b"".decode('utf-8'),
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='algorithm', full_name='MigrationPayload.OtpParameters.algorithm', index=3,
|
|
||||||
number=4, type=14, cpp_type=8, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='digits', full_name='MigrationPayload.OtpParameters.digits', index=4,
|
|
||||||
number=5, type=5, cpp_type=1, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='type', full_name='MigrationPayload.OtpParameters.type', index=5,
|
|
||||||
number=6, type=14, cpp_type=8, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='counter', full_name='MigrationPayload.OtpParameters.counter', index=6,
|
|
||||||
number=7, type=3, cpp_type=2, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
],
|
|
||||||
extensions=[
|
|
||||||
],
|
|
||||||
nested_types=[],
|
|
||||||
enum_types=[
|
|
||||||
],
|
|
||||||
serialized_options=None,
|
|
||||||
is_extendable=False,
|
|
||||||
syntax='proto3',
|
|
||||||
extension_ranges=[],
|
|
||||||
oneofs=[
|
|
||||||
],
|
|
||||||
serialized_start=176,
|
|
||||||
serialized_end=359,
|
|
||||||
)
|
|
||||||
|
|
||||||
_MIGRATIONPAYLOAD = _descriptor.Descriptor(
|
|
||||||
name='MigrationPayload',
|
|
||||||
full_name='MigrationPayload',
|
|
||||||
filename=None,
|
|
||||||
file=DESCRIPTOR,
|
|
||||||
containing_type=None,
|
|
||||||
create_key=_descriptor._internal_create_key,
|
|
||||||
fields=[
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='otp_parameters', full_name='MigrationPayload.otp_parameters', index=0,
|
|
||||||
number=1, type=11, cpp_type=10, label=3,
|
|
||||||
has_default_value=False, default_value=[],
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='version', full_name='MigrationPayload.version', index=1,
|
|
||||||
number=2, type=5, cpp_type=1, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='batch_size', full_name='MigrationPayload.batch_size', index=2,
|
|
||||||
number=3, type=5, cpp_type=1, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='batch_index', full_name='MigrationPayload.batch_index', index=3,
|
|
||||||
number=4, type=5, cpp_type=1, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='batch_id', full_name='MigrationPayload.batch_id', index=4,
|
|
||||||
number=5, type=5, cpp_type=1, label=1,
|
|
||||||
has_default_value=False, default_value=0,
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
|
|
||||||
],
|
|
||||||
extensions=[
|
|
||||||
],
|
|
||||||
nested_types=[_MIGRATIONPAYLOAD_OTPPARAMETERS, ],
|
|
||||||
enum_types=[
|
|
||||||
_MIGRATIONPAYLOAD_ALGORITHM,
|
|
||||||
_MIGRATIONPAYLOAD_OTPTYPE,
|
|
||||||
],
|
|
||||||
serialized_options=None,
|
|
||||||
is_extendable=False,
|
|
||||||
syntax='proto3',
|
|
||||||
extension_ranges=[],
|
|
||||||
oneofs=[
|
|
||||||
],
|
|
||||||
serialized_start=22,
|
|
||||||
serialized_end=461,
|
|
||||||
)
|
|
||||||
|
|
||||||
_MIGRATIONPAYLOAD_OTPPARAMETERS.fields_by_name['algorithm'].enum_type = _MIGRATIONPAYLOAD_ALGORITHM
|
|
||||||
_MIGRATIONPAYLOAD_OTPPARAMETERS.fields_by_name['type'].enum_type = _MIGRATIONPAYLOAD_OTPTYPE
|
|
||||||
_MIGRATIONPAYLOAD_OTPPARAMETERS.containing_type = _MIGRATIONPAYLOAD
|
|
||||||
_MIGRATIONPAYLOAD.fields_by_name['otp_parameters'].message_type = _MIGRATIONPAYLOAD_OTPPARAMETERS
|
|
||||||
_MIGRATIONPAYLOAD_ALGORITHM.containing_type = _MIGRATIONPAYLOAD
|
|
||||||
_MIGRATIONPAYLOAD_OTPTYPE.containing_type = _MIGRATIONPAYLOAD
|
|
||||||
DESCRIPTOR.message_types_by_name['MigrationPayload'] = _MIGRATIONPAYLOAD
|
|
||||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
|
||||||
|
|
||||||
MigrationPayload = _reflection.GeneratedProtocolMessageType('MigrationPayload', (_message.Message,), {
|
|
||||||
|
|
||||||
'OtpParameters' : _reflection.GeneratedProtocolMessageType('OtpParameters', (_message.Message,), {
|
|
||||||
'DESCRIPTOR' : _MIGRATIONPAYLOAD_OTPPARAMETERS,
|
|
||||||
'__module__' : 'google_auth_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:MigrationPayload.OtpParameters)
|
|
||||||
})
|
|
||||||
,
|
|
||||||
'DESCRIPTOR' : _MIGRATIONPAYLOAD,
|
|
||||||
'__module__' : 'google_auth_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:MigrationPayload)
|
|
||||||
})
|
|
||||||
_sym_db.RegisterMessage(MigrationPayload)
|
|
||||||
_sym_db.RegisterMessage(MigrationPayload.OtpParameters)
|
|
||||||
|
|
||||||
|
|
||||||
# @@protoc_insertion_point(module_scope)
|
|
@ -0,0 +1,31 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
# source: google_auth.proto
|
||||||
|
"""Generated protocol buffer code."""
|
||||||
|
from google.protobuf.internal import builder as _builder
|
||||||
|
from google.protobuf import descriptor as _descriptor
|
||||||
|
from google.protobuf import descriptor_pool as _descriptor_pool
|
||||||
|
from google.protobuf import symbol_database as _symbol_database
|
||||||
|
# @@protoc_insertion_point(imports)
|
||||||
|
|
||||||
|
_sym_db = _symbol_database.Default()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11google_auth.proto\"\xb7\x03\n\x10MigrationPayload\x12\x37\n\x0eotp_parameters\x18\x01 \x03(\x0b\x32\x1f.MigrationPayload.OtpParameters\x12\x0f\n\x07version\x18\x02 \x01(\x05\x12\x12\n\nbatch_size\x18\x03 \x01(\x05\x12\x13\n\x0b\x62\x61tch_index\x18\x04 \x01(\x05\x12\x10\n\x08\x62\x61tch_id\x18\x05 \x01(\x05\x1a\xb7\x01\n\rOtpParameters\x12\x0e\n\x06secret\x18\x01 \x01(\x0c\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x0e\n\x06issuer\x18\x03 \x01(\t\x12.\n\talgorithm\x18\x04 \x01(\x0e\x32\x1b.MigrationPayload.Algorithm\x12\x0e\n\x06\x64igits\x18\x05 \x01(\x05\x12\'\n\x04type\x18\x06 \x01(\x0e\x32\x19.MigrationPayload.OtpType\x12\x0f\n\x07\x63ounter\x18\x07 \x01(\x03\",\n\tAlgorithm\x12\x10\n\x0c\x41LGO_INVALID\x10\x00\x12\r\n\tALGO_SHA1\x10\x01\"6\n\x07OtpType\x12\x0f\n\x0bOTP_INVALID\x10\x00\x12\x0c\n\x08OTP_HOTP\x10\x01\x12\x0c\n\x08OTP_TOTP\x10\x02\x62\x06proto3')
|
||||||
|
|
||||||
|
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
|
||||||
|
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google_auth_pb2', globals())
|
||||||
|
if _descriptor._USE_C_DESCRIPTORS == False:
|
||||||
|
|
||||||
|
DESCRIPTOR._options = None
|
||||||
|
_MIGRATIONPAYLOAD._serialized_start=22
|
||||||
|
_MIGRATIONPAYLOAD._serialized_end=461
|
||||||
|
_MIGRATIONPAYLOAD_OTPPARAMETERS._serialized_start=176
|
||||||
|
_MIGRATIONPAYLOAD_OTPPARAMETERS._serialized_end=359
|
||||||
|
_MIGRATIONPAYLOAD_ALGORITHM._serialized_start=361
|
||||||
|
_MIGRATIONPAYLOAD_ALGORITHM._serialized_end=405
|
||||||
|
_MIGRATIONPAYLOAD_OTPTYPE._serialized_start=407
|
||||||
|
_MIGRATIONPAYLOAD_OTPTYPE._serialized_end=461
|
||||||
|
# @@protoc_insertion_point(module_scope)
|
@ -0,0 +1,75 @@
|
|||||||
|
# Unit test for extract_otp_secret_keys.py
|
||||||
|
|
||||||
|
# Run tests:
|
||||||
|
# python -m unittest
|
||||||
|
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import csv
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
import extract_otp_secret_keys
|
||||||
|
|
||||||
|
class TestExtract(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_extract_csv(self):
|
||||||
|
extract_otp_secret_keys.main(['-q', '-c', 'test_example_output.csv', 'example_export.txt'])
|
||||||
|
|
||||||
|
expected_csv = read_csv('example_output.csv')
|
||||||
|
actual_csv = read_csv('test_example_output.csv')
|
||||||
|
|
||||||
|
self.assertEqual(actual_csv, expected_csv)
|
||||||
|
|
||||||
|
def test_extract_json(self):
|
||||||
|
extract_otp_secret_keys.main(['-q', '-j', 'test_example_output.json', 'example_export.txt'])
|
||||||
|
|
||||||
|
expected_json = read_json('example_output.json')
|
||||||
|
actual_json = read_json('test_example_output.json')
|
||||||
|
|
||||||
|
self.assertEqual(actual_json, expected_json)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
remove_file('test_example_output.csv')
|
||||||
|
remove_file('test_example_output.json')
|
||||||
|
|
||||||
|
def remove_file(filename):
|
||||||
|
if os.path.exists(filename): os.remove(filename)
|
||||||
|
|
||||||
|
def read_csv(filename):
|
||||||
|
"""Returns a list of lines."""
|
||||||
|
with open(filename, "r") as infile:
|
||||||
|
lines = []
|
||||||
|
reader = csv.reader(infile)
|
||||||
|
for line in reader:
|
||||||
|
lines.append(line)
|
||||||
|
return lines
|
||||||
|
|
||||||
|
def read_json(filename):
|
||||||
|
"""Returns a list or a dictionary."""
|
||||||
|
with open(filename, "r") as infile:
|
||||||
|
return json.load(infile)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue