summaryrefslogtreecommitdiffstats
path: root/tests/crypto_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/crypto_test.py')
-rw-r--r--tests/crypto_test.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/crypto_test.py b/tests/crypto_test.py
index aaa3bd2..8de58e7 100644
--- a/tests/crypto_test.py
+++ b/tests/crypto_test.py
@@ -16,6 +16,8 @@
# along with Combox (see COPYING). If not, see
# <http://www.gnu.org/licenses/>.
+import yaml
+
from glob import glob
from nose.tools import *
from os import path, remove
@@ -25,10 +27,19 @@ from combox.file import (split_data, glue_data, write_file,
from combox.crypto import encrypt, decrypt, encrypt_shards, decrypt_shards
-FILES_DIR = path.join('tests','files')
+CONFIG_DIR = path.join('tests', 'test-config')
+
+config_file = path.join(CONFIG_DIR, 'config.yaml')
+try:
+ config = yaml.load(file(config_file, 'r'))
+except yaml.YAMLError, exc:
+ raise AssertionError("Error in configuration file:", exc)
+
+FILES_DIR = config['combox_dir']
TEST_FILE = path.join(FILES_DIR,'the-red-star.jpg')
PASS = 'topsecret'
+
def test_encryption():
""" Read file, encrypt it to a cipher, write cipher to file, read
encrypted file, decrypt it, write decrypted data to file.
@@ -51,20 +62,24 @@ def test_split_encryption():
glue the shards together, write glued data to file.
"""
+ # no. of shards = no. of nodes
+ SHARDS = len(config['nodes_info'].keys())
+
f = path.abspath(TEST_FILE)
f_content = read_file(f)
- f_shards = split_data(f_content, 5)
+ f_shards = split_data(f_content, SHARDS)
# encrypt shards
ciphered_shards = encrypt_shards(f_shards, PASS)
# write ciphered shards to disk
- f_path = FILES_DIR
f_basename = "%s.ciphered" % path.basename(f)
- write_shards(ciphered_shards, f_path, f_basename)
+ nodes = [path.abspath(node['path']) for node in config['nodes_info'].itervalues()]
+
+ write_shards(ciphered_shards, nodes, f_basename)
# read ciphered shards from disk
- ciphered_shards = read_shards(f_path, f_basename)
+ ciphered_shards = read_shards(nodes, f_basename)
# decrypt shards
f_parts = decrypt_shards(ciphered_shards, PASS)
@@ -72,8 +87,3 @@ def test_split_encryption():
f_content_glued = glue_data(f_parts)
assert f_content == f_content_glued
-
- # remove ciphered shards from disk
- c_shards = glob("%s.ciphered*" % TEST_FILE)
- for shard in c_shards:
- remove(shard)