Removing tests that test things that no longer exist.

pull/157/head
jMyles 2018-02-07 10:52:38 -08:00
parent f1a6689b7a
commit f420a02ad7
2 changed files with 0 additions and 204 deletions

View File

@ -1,43 +0,0 @@
from nkms.crypto import default_algorithm
from nkms.crypto import symmetric_from_algorithm
from nkms.crypto import pre_from_algorithm
from nkms.crypto import api
def test_symmetric():
Cipher = symmetric_from_algorithm(default_algorithm)
key = api.secure_random(Cipher.KEY_SIZE)
cipher = Cipher(key)
data = b'Hello world' * 10
edata = cipher.encrypt(data)
assert edata != data
assert cipher.decrypt(edata) == data
def test_pre():
pre = pre_from_algorithm(default_algorithm)
sk_alice = b'a' * 32
sk_bob = b'b' * 32
pk_alice = pre.priv2pub(sk_alice)
pk_bob = pre.priv2pub(sk_bob)
assert len(pk_alice) == 34
assert len(pk_bob) == 34
assert pk_alice[0] == 1
assert pk_bob[0] == 1
cleartext = b'Hello world'
cyphertext_for_alice = pre.encrypt(pk_alice, cleartext)
assert pre.decrypt(sk_alice, cyphertext_for_alice) == cleartext # Alice can read her message.
assert pre.decrypt(sk_bob, cyphertext_for_alice) != cleartext # But Bob can't!
# Now we make a re-encryption key from Alice to Bob
rk_alice_bob = pre.rekey(sk_alice, pk_bob)
# Use the key on Alice's cyphertext...
cyphertext_for_bob = pre.reencrypt(rk_alice_bob, cyphertext_for_alice)
# ...and sure enough, Bob can read it!
assert pre.decrypt(sk_bob, cyphertext_for_bob) == cleartext

View File

@ -1,161 +0,0 @@
import unittest
import msgpack
from nacl.utils import random
from nkms.client import Client
from nkms.crypto import (default_algorithm, pre_from_algorithm,
symmetric_from_algorithm)
@unittest.skip(reason="Revisit this later")
class TestClient(unittest.TestCase):
def setUp(self):
self.pre = pre_from_algorithm(default_algorithm)
self.symm = symmetric_from_algorithm(default_algorithm)
self.priv_key = self.pre.gen_priv(dtype='bytes')
self.pub_key = self.pre.priv2pub(self.priv_key)
self.client = Client()
@unittest.skip(reason="Tux is going to revisit this.")
def test_derive_path_key(self):
path = b'/foo/bar'
pub_path_key = self.client._derive_path_key(path, is_pub=True)
self.assertEqual(bytes, type(pub_path_key))
priv_path_key = self.client._derive_path_key(path, is_pub=False)
self.assertEqual(bytes, type(priv_path_key))
self.assertNotEqual(pub_path_key, priv_path_key)
def test_split_path_with_path(self):
path = b'/foo/bar/test.jpg'
subdirs = self.client._split_path(path)
self.assertEqual(4, len(subdirs))
self.assertEqual(subdirs[0], b'')
self.assertEqual(subdirs[1], b'/foo')
self.assertEqual(subdirs[2], b'/foo/bar')
self.assertEqual(subdirs[3], b'/foo/bar/test.jpg')
@unittest.skip(reason="Tux is going to revisit this.")
def test_build_header_prealpha(self):
enc_keys = [random(148), random(148), random(148)]
version = 100
header, length = self.client._build_header(enc_keys, version=version)
self.assertEqual(len(header), length)
try:
msgpack.loads(header)
except Exception as E:
self.fail("Failed to unpack header:\n{}".format(E))
self.assertIn((3).to_bytes(4, byteorder='big'), header)
for key in enc_keys:
self.assertIn(key, header)
self.assertIn(version.to_bytes(4, byteorder='big'), header)
@unittest.skip(reason="Tux is going to revisit this.")
def test_read_header_prealpha(self):
enc_keys = [random(148), random(148), random(148)]
version = 100
header, length = self.client._build_header(enc_keys, version=version)
self.assertEqual(len(header), length)
try:
msgpack.loads(header)
except Exception as E:
self.fail("Failed to unpack header: {}".format(E))
for key in enc_keys:
self.assertIn(key, header)
self.assertIn(version.to_bytes(4, byteorder='big'), header)
header = self.client._read_header(header)
self.assertEqual(int, type(header[0]))
self.assertEqual(100, header[0])
self.assertEqual(list, type(header[1]))
self.assertEqual(3, len(header[1]))
for key in header[1]:
self.assertIn(key, enc_keys)
@unittest.skip(reason="Tux is going to revisit this.")
def test_encrypt_key_with_path_tuple(self):
key = random(32)
path = b'/foo/bar'
enc_keys = self.client.encrypt_key(key, path=path)
self.assertEqual(3, len(enc_keys))
self.assertTrue(key not in enc_keys)
@unittest.skip(reason="Tux is going to revisit this.")
def test_encrypt_key_with_path_string(self):
key = random(32)
path = b'foobar'
enc_key = self.client.encrypt_key(key, path=path)
self.assertNotEqual(key, enc_key)
@unittest.skip(reason="Tux is going to revisit this.")
def test_encrypt_key_no_path(self):
key = random(32)
# Use client's pubkey (implict)
enc_key_1 = self.client.encrypt_key(key)
self.assertNotEqual(key, enc_key_1)
# Use provided pubkey (explicit)
enc_key_2 = self.client.encrypt_key(key, pubkey=self.pub_key)
self.assertNotEqual(key, enc_key_2)
self.assertNotEqual(enc_key_1, enc_key_2)
@unittest.skip(reason="Tux is going to revisit this.")
def test_decrypt_key_with_path(self):
key = random(32)
path = b'/foo/bar'
enc_keys = self.client.encrypt_key(key, path=path)
self.assertEqual(3, len(enc_keys))
self.assertTrue(key not in enc_keys)
subpaths = self.client._split_path(path)
self.assertEqual(3, len(subpaths))
# Check each path key works for decryption
for idx, enc_key in enumerate(enc_keys):
dec_key = self.client.decrypt_key(enc_key, path=subpaths[idx])
self.assertEqual(key, dec_key)
@unittest.skip(reason="Tux is going to revisit this.")
def test_decrypt_key_no_path(self):
key = random(32)
enc_key = self.client.encrypt_key(key)
self.assertNotEqual(key, enc_key)
dec_key = self.client.decrypt_key(enc_key)
self.assertEqual(key, dec_key)
@unittest.skip(reason="Tux is going to revisit this.")
def test_encrypt_bulk(self):
test_data = b'hello world!'
key = random(32)
enc_data = self.client.encrypt_bulk(test_data, key)
self.assertNotEqual(test_data, enc_data)
@unittest.skip(reason="Tux is going to revisit this.")
def test_decrypt_bulk(self):
test_data = b'hello world!'
nonce_size_bytes = 24
key = random(32)
enc_data = self.client.encrypt_bulk(test_data, key)
self.assertNotEqual(test_data, enc_data)
# Test that the ciphertext is >24 bytes for nonce
self.assertTrue(len(enc_data) > nonce_size_bytes)
dec_data = self.client.decrypt_bulk(enc_data, key)
self.assertEqual(test_data, dec_data)