diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-01-13 14:05:56 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-01-13 14:05:56 -0500 |
commit | 8d68bf0c360161e8813b3a7187628274d2d9ed3f (patch) | |
tree | 309ae9fb69c68eb71fb91188149ec17fd4706f0b /tests | |
parent | 60fe856e6fd0aeb4c8b8936c59bdf7434adf4b41 (diff) |
rewrote the read_shards() and write_shards() function in combox/file.py.
Tests were accordingly modded and now use the test config.yaml to
split and write shards to dirs.
modified: combox/file.py
modified: tests/crypto_test.py
modified: tests/file_test.py
Diffstat (limited to 'tests')
-rw-r--r-- | tests/crypto_test.py | 30 | ||||
-rw-r--r-- | tests/file_test.py | 35 |
2 files changed, 43 insertions, 22 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) diff --git a/tests/file_test.py b/tests/file_test.py index e418dfc..321533b 100644 --- a/tests/file_test.py +++ b/tests/file_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 @@ -23,7 +25,16 @@ from os import path, remove from combox.file import (split_data, glue_data, write_file, read_file, write_shards, read_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') def test_split(): @@ -47,26 +58,26 @@ def test_shards(): and check if they're the same as the orginal file. """ - SHARDS = 5 + # 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, SHARDS) - f_path = FILES_DIR + f_basename = path.basename(f) - write_shards(f_shards, f_path, f_basename) + nodes = [path.abspath(node['path']) for node in config['nodes_info'].itervalues()] + write_shards(f_shards, nodes, f_basename) # check if the shards have been created. - for i in range(0,SHARDS): - shard = "%s.shard%s" % (TEST_FILE, i) + i = 0 + for node in nodes: + shard = "%s.shard%s" % (path.join(node, f_basename), i) + i += 1 assert path.isfile(shard) - f_shards = read_shards(f_path, f_basename) + f_shards = read_shards(nodes, f_basename) f_content_glued = glue_data(f_shards) assert f_content == f_content_glued - - # remove shards from disk. - shards = glob("%s.shard*" % TEST_FILE) - for shard in shards: - remove(shard) |