refactor; rename classes and methods

This commit is contained in:
2025-03-10 09:26:55 -05:00
parent c1ca01eb93
commit 571268b86a
15 changed files with 160 additions and 160 deletions

View File

@@ -9,8 +9,8 @@ def nkode_api() -> NKodeAPI:
@pytest.mark.parametrize("keypad_size,passocode_len", [
(KeypadSize(numb_of_keys=10, attrs_per_key=11), 4),
(KeypadSize(numb_of_keys=10, attrs_per_key=12), 5),
(KeypadSize(numb_of_keys=10, props_per_key=11), 4),
(KeypadSize(numb_of_keys=10, props_per_key=12), 5),
])
def test_create_new_user_and_renew_keys(nkode_api, keypad_size, passocode_len):
username = "test_username"
@@ -32,7 +32,7 @@ def test_create_new_user_and_renew_keys(nkode_api, keypad_size, passocode_len):
)
assert successful_confirm
sign_in_key_selection = lambda keypad: [keypad.index(attr) // keypad_size.attrs_per_key for attr in user_passcode]
sign_in_key_selection = lambda keypad: [keypad.index(attr) // keypad_size.props_per_key for attr in user_passcode]
login_keypad = nkode_api.get_login_keypad(username, customer_id)
login_key_selection = sign_in_key_selection(login_keypad)
successful_login = nkode_api.login(customer_id, username, login_key_selection)

View File

@@ -5,11 +5,11 @@ from src.models import KeypadSize
@pytest.mark.parametrize(
"keypad_size",
[KeypadSize(numb_of_keys=10, attrs_per_key=11)]
[KeypadSize(numb_of_keys=10, props_per_key=11)]
)
def test_attr_set_idx(keypad_size):
user_keypad = UserKeypad.create(keypad_size)
for attr_idx in range(keypad_size.numb_of_attrs):
for attr_idx in range(keypad_size.numb_of_props):
user_keypad_idx = user_keypad.keypad[attr_idx]
assert (attr_idx % keypad_size.attrs_per_key == user_keypad_idx % keypad_size.attrs_per_key)
assert (attr_idx % keypad_size.props_per_key == user_keypad_idx % keypad_size.props_per_key)

View File

@@ -1,7 +1,7 @@
import pytest
from src.models import KeypadSize
from src.user_cipher_keys import UserCipherKeys, CustomerAttributes
from src.user_cipher_keys import UserCipher, CustomerCipher
from src.utils import generate_random_nonrepeating_list
@@ -13,8 +13,8 @@ from src.utils import generate_random_nonrepeating_list
)
def test_encode_decode_base64(passcode_len):
data = generate_random_nonrepeating_list(passcode_len)
encoded = UserCipherKeys.encode_base64_str(data)
decoded = UserCipherKeys.decode_base64_str(encoded)
encoded = UserCipher.encode_base64_str(data)
decoded = UserCipher.decode_base64_str(encoded)
assert (len(data) == len(decoded))
assert (all(data[idx] == decoded[idx] for idx in range(passcode_len)))
@@ -22,21 +22,21 @@ def test_encode_decode_base64(passcode_len):
@pytest.mark.parametrize(
"keypad_size,max_nkode_len",
[
(KeypadSize(numb_of_keys=10, attrs_per_key=11), 10),
(KeypadSize(numb_of_keys=9, attrs_per_key=11), 10),
(KeypadSize(numb_of_keys=8, attrs_per_key=11), 12),
(KeypadSize(numb_of_keys=10, props_per_key=11), 10),
(KeypadSize(numb_of_keys=9, props_per_key=11), 10),
(KeypadSize(numb_of_keys=8, props_per_key=11), 12),
])
def test_decode_mask(keypad_size, max_nkode_len):
customer = CustomerAttributes.create(keypad_size)
customer = CustomerCipher.create(keypad_size)
passcode_entry = generate_random_nonrepeating_list(
keypad_size.numb_of_attrs,
max_val=keypad_size.numb_of_attrs)[:4]
passcode_values = [customer.attr_vals[idx] for idx in passcode_entry]
set_vals = customer.set_vals
user_keys = UserCipherKeys.create(keypad_size, set_vals, max_nkode_len)
keypad_size.numb_of_props,
max_val=keypad_size.numb_of_props)[:4]
passcode_values = [customer.prop_key[idx] for idx in passcode_entry]
set_vals = customer.set_key
user_keys = UserCipher.create(keypad_size, set_vals, max_nkode_len)
passcode = user_keys.encipher_nkode(passcode_entry, customer)
orig_passcode_set_vals = [customer.get_attr_set_val(attr) for attr in passcode_values]
orig_passcode_set_vals = [customer.get_prop_set_val(attr) for attr in passcode_values]
passcode_set_vals = user_keys.decipher_mask(passcode.mask, set_vals, len(passcode_entry))
assert (len(passcode_set_vals) == len(orig_passcode_set_vals))
assert (all(orig_passcode_set_vals[idx] == passcode_set_vals[idx] for idx in range(len(passcode_set_vals))))

View File

@@ -5,7 +5,7 @@ from src.models import KeypadSize
@pytest.fixture()
def user_keypad():
return UserKeypad.create(keypad_size=KeypadSize(attrs_per_key=7, numb_of_keys=10))
return UserKeypad.create(keypad_size=KeypadSize(props_per_key=7, numb_of_keys=10))
def test_dispersion(user_keypad):
@@ -22,7 +22,7 @@ def test_shuffle_attrs(user_keypad):
expected statistical outcomes like:
- every attribute gets to every key with a uniform distribution
- every attribute is adjacent to every other attribute with uniform distribution
- the order in which the attributes move from key to key is random (i.e. the distance traveled is uniform)
- the order in which the customer_cipher move from key to key is random (i.e. the distance traveled is uniform)
"""
pre_shuffle_keypad = user_keypad.keypad
user_keypad.partial_keypad_shuffle()