implement generate login interface and login
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def test_encipher_nkode():
|
||||
pass
|
||||
@@ -27,3 +27,8 @@ def test_create_new_user(pseudo_nkode_api, numb_keys, attrs_per_key, user_passco
|
||||
session_id
|
||||
)
|
||||
assert ("success" == response)
|
||||
|
||||
login_interface = pseudo_nkode_api.get_login_index_interface(username, customer.customer_id)
|
||||
login_key_selection = key_selection(login_interface)
|
||||
successful_login = pseudo_nkode_api.login(customer.customer_id, username, login_key_selection)
|
||||
assert (successful_login)
|
||||
|
||||
35
test/test_user_cipher_keys.py
Normal file
35
test/test_user_cipher_keys.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from src.user_cipher_keys import UserCipherKeys, CustomerInterface
|
||||
from src.utils import generate_random_nonrepeating_list
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"passcode_len",
|
||||
[
|
||||
6
|
||||
]
|
||||
)
|
||||
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)
|
||||
assert (len(data) == len(decoded))
|
||||
assert (all(data[idx] == decoded[idx] for idx in range(passcode_len)))
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"numb_of_keys,attrs_per_key",
|
||||
[
|
||||
(10, 7,)
|
||||
])
|
||||
def test_decode_mask(numb_of_keys, attrs_per_key):
|
||||
customer = CustomerInterface.new_interface(numb_of_keys, attrs_per_key)
|
||||
passcode_entry = generate_random_nonrepeating_list(numb_of_keys*attrs_per_key, max_val=70)[:4]
|
||||
passcode_values = [customer.customer_interface[idx] for idx in passcode_entry]
|
||||
set_vals = customer.set_vals
|
||||
user_keys = UserCipherKeys.new_user_encipher_keys(numb_of_keys, attrs_per_key, set_vals)
|
||||
passcode = user_keys.encipher_nkode(passcode_entry, customer)
|
||||
|
||||
orig_passcode_set_vals = [customer.get_attr_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))))
|
||||
@@ -1,11 +1,12 @@
|
||||
import pytest
|
||||
from src.user_interface import UserInterface
|
||||
|
||||
@pytest.mark.parametrize("user_interface", [
|
||||
(
|
||||
UserInterface.new_interface(7, 10)
|
||||
)
|
||||
])
|
||||
|
||||
@pytest.fixture()
|
||||
def user_interface():
|
||||
return UserInterface.new_interface(7, 10)
|
||||
|
||||
|
||||
def test_dispersion(user_interface):
|
||||
pre_dispersion_graph = user_interface.attribute_adjacency_graph()
|
||||
user_interface.disperse_interface()
|
||||
@@ -14,3 +15,22 @@ def test_dispersion(user_interface):
|
||||
for _ in range(10000):
|
||||
for attr, adj_graph in pre_dispersion_graph.items():
|
||||
assert (adj_graph.isdisjoint(post_dispersion_graph[attr]))
|
||||
|
||||
|
||||
def test_shuffle_attrs(user_interface):
|
||||
"""there's no easy way to test this. At some point we'll have to run this code thousands of time to see if we get
|
||||
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)
|
||||
"""
|
||||
pre_shuffle_interface = user_interface.interface_index
|
||||
user_interface.shuffle_interface()
|
||||
post_shuffle_interface = user_interface.interface_index
|
||||
for i in range(1000):
|
||||
assert (not all(
|
||||
post_shuffle_interface[idx] == pre_shuffle_interface[idx] for idx in range(len(post_shuffle_interface))
|
||||
))
|
||||
assert (not all(
|
||||
post_shuffle_interface[idx] != pre_shuffle_interface[idx] for idx in range(len(post_shuffle_interface))
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user