First working version
This commit is contained in:
0
otpauth_migration_decoder/tests/__init__.py
Normal file
0
otpauth_migration_decoder/tests/__init__.py
Normal file
19
otpauth_migration_decoder/tests/test_decode_secret.py
Normal file
19
otpauth_migration_decoder/tests/test_decode_secret.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
|
||||
from src.decoder import decode_secret
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'secret,expected_result',
|
||||
[
|
||||
(b'Hello!\xde\xad\xbe\xef', 'JBSWY3DPEHPK3PXP', ),
|
||||
(b'Hello!', 'JBSWY3DPEE',),
|
||||
(b'\xde\xad\xbe\xef', '32W353Y',),
|
||||
],
|
||||
)
|
||||
def test_decode_secret(secret, expected_result):
|
||||
# act
|
||||
result = decode_secret(secret)
|
||||
|
||||
# assert
|
||||
assert result == expected_result
|
||||
31
otpauth_migration_decoder/tests/test_decoded_data.py
Normal file
31
otpauth_migration_decoder/tests/test_decoded_data.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from src.decoder import decoded_data
|
||||
|
||||
|
||||
def test_decoded_data__expected():
|
||||
# arrange
|
||||
data = ['CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC', ]
|
||||
|
||||
# act
|
||||
generator = decoded_data(data)
|
||||
result = list(generator)
|
||||
|
||||
# assert
|
||||
assert result == [b'\n1\n\nHello!\xde\xad\xbe\xef\x12\x18Example:alice@google.com\x1a\x07Example0\x02', ]
|
||||
|
||||
|
||||
def test_decoded_data__list__expected():
|
||||
# arrange
|
||||
data = [
|
||||
'CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
'CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
]
|
||||
|
||||
# act
|
||||
generator = decoded_data(data)
|
||||
result = list(generator)
|
||||
|
||||
# assert
|
||||
assert result == [
|
||||
b'\n1\n\nHello!\xde\xad\xbe\xef\x12\x18Example:alice@google.com\x1a\x07Example0\x02',
|
||||
b'\n1\n\nHello!\xde\xad\xbe\xef\x12\x18Example:alice@google.com\x1a\x07Example0\x02',
|
||||
]
|
||||
18
otpauth_migration_decoder/tests/test_get_otpauth_url.py
Normal file
18
otpauth_migration_decoder/tests/test_get_otpauth_url.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from src.decoder import get_otpauth_url
|
||||
from src.otpauth_migration_pb2 import Payload
|
||||
|
||||
|
||||
def test_get_otpauth_url():
|
||||
# arrange
|
||||
otp = Payload.OtpParameters(
|
||||
secret=b'Hello!\336\255\276\357',
|
||||
name='Example:alice@google.com',
|
||||
issuer='Example',
|
||||
type=2
|
||||
)
|
||||
|
||||
# act
|
||||
result = get_otpauth_url(otp)
|
||||
|
||||
# assert
|
||||
assert result == 'otpauth://totp/Example%3Aalice%40google.com?issuer=Example&secret=JBSWY3DPEHPK3PXP'
|
||||
18
otpauth_migration_decoder/tests/test_get_url_params.py
Normal file
18
otpauth_migration_decoder/tests/test_get_url_params.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from src.decoder import get_url_params
|
||||
from src.otpauth_migration_pb2 import Payload
|
||||
|
||||
|
||||
def test_get_url_params():
|
||||
# arrange
|
||||
otp = Payload.OtpParameters(
|
||||
secret=b'Hello!\336\255\276\357',
|
||||
name='Example:alice@google.com',
|
||||
issuer='Example',
|
||||
type=2
|
||||
)
|
||||
|
||||
# act
|
||||
result = get_url_params(otp)
|
||||
|
||||
# assert
|
||||
assert result == 'issuer=Example&secret=JBSWY3DPEHPK3PXP'
|
||||
31
otpauth_migration_decoder/tests/test_validate_migration.py
Normal file
31
otpauth_migration_decoder/tests/test_validate_migration.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import pytest
|
||||
from click import BadParameter
|
||||
|
||||
from src.decoder import validate_migration
|
||||
|
||||
|
||||
def test_validate_migration__migration__ok():
|
||||
# arrange
|
||||
migration = 'otpauth-migration://offline?data=CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC'
|
||||
|
||||
# act
|
||||
result = validate_migration(None, None, migration)
|
||||
|
||||
# assert
|
||||
assert result == ['CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC']
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'broken_migration',
|
||||
[
|
||||
'otpauth-migration://online?data=CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
'CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
'offline?data=CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
'otpauth-migration://online?data=Cu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
'data=CjEKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZTAC',
|
||||
]
|
||||
)
|
||||
def test_validate_migration__broken_migration__raise(broken_migration):
|
||||
# act & assert
|
||||
with pytest.raises(BadParameter):
|
||||
validate_migration(None, None, broken_migration)
|
||||
Reference in New Issue
Block a user