combox

split and encrypted files between online file storage providers
git clone git://git.ricketyspace.net/combox.git
Log | Files | Refs

commit 4321e9dcadf929b81b6528b7cb3174c80772b5aa
parent 94596f0913cfdc33ffc85aac1005ea745d6559f8
Author: Siddharth Ravikumar <sravik@bgsu.edu>
Date:   Tue, 20 Jan 2015 23:10:13 -0500

fleshed out the on_modified function in the ComboxEventHandler class + wrote tests for it.

modified:   combox/events.py
modified:   tests/events_test.py
new file:   tests/files/ipsum.txt
new file:   tests/files/lorem.txt

Diffstat:
combox/events.py | 8++++++++
tests/events_test.py | 36+++++++++++++++++++++++++++++++++++-
tests/files/ipsum.txt | 40++++++++++++++++++++++++++++++++++++++++
tests/files/lorem.txt | 15+++++++++++++++
4 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/combox/events.py b/combox/events.py @@ -96,5 +96,13 @@ class ComboxEventHandler(FileSystemEventHandler): def on_modified(self, event): super(ComboxEventHandler, self).on_modified(event) + if event.is_directory: + # do nothing + pass + else: + # file was modified + split_and_encrypt(event.src_path, self.config) + # TODO: code for updating file info in YAML silo. + type_ = 'directory' if event.is_directory else 'file' logging.info("Modified %s: %s", type_, event.src_path) diff --git a/tests/events_test.py b/tests/events_test.py @@ -29,7 +29,9 @@ from watchdog.observers import Observer from combox.events import ComboxEventHandler from combox.config import get_nodedirs -from combox.file import relative_path, purge_dir +from combox.crypto import decrypt_and_glue +from combox.file import (relative_path, purge_dir, + read_file, write_file) CONFIG_DIR = path.join('tests', 'test-config') @@ -178,5 +180,37 @@ def test_CEH(): path_deletedp(TEST_DIR_1, True) path_deletedp(TEST_DIR_0, True) + + # Test - file modification + lorem_file = path.join(FILES_DIR, 'lorem.txt') + lorem_file_copy = "%s.copy" % lorem_file + # this will shard lorem.txt.copy in the node directories. + copyfile(lorem_file, lorem_file_copy) + time.sleep(1) + shardedp(lorem_file_copy) + + ipsum_file = path.join(FILES_DIR, 'ipsum.txt') + ipsum_content = read_file(ipsum_file) + lorem_content = read_file(lorem_file_copy) + lorem_content = "%s\n%s" % (lorem_content, ipsum_content) + + # write lorem's new content to lorem_file_copy + write_file(lorem_file_copy, lorem_content) + time.sleep(1) + + # decrypt_and_glue will decrypt the file shards, glues them and + # writes it to the respective file + decrypt_and_glue(lorem_file_copy, config) + time.sleep(1) + + lorem_content_from_disk = read_file(lorem_file_copy) + assert lorem_content == lorem_content_from_disk + + # remove lorem_file_copy and confirm that its shards are deleted + # in the node directories. + remove(lorem_file_copy) + time.sleep(1) + path_deletedp(lorem_file_copy) + observer.stop() observer.join() diff --git a/tests/files/ipsum.txt b/tests/files/ipsum.txt @@ -0,0 +1,40 @@ +Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut +tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper +ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi +diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec +pretium volutpat, arcu ante placerat erat, non tristique elit urna et +turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et +orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, +elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis +pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod +ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo +sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at +massa ipsum. Quisque bibendum purus convallis nulla ultrices +ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit +laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat +elit. Nam sagittis nisi dui. + +- Suspendisse lectus leo, consectetur in tempor sit amet, placerat + quis neque. Etiam luctus porttitor lorem, sed suscipit est rutrum + non. Curabitur lobortis nisl a enim congue semper. Aenean commodo + ultrices imperdiet. Vestibulum ut justo vel sapien venenatis + tincidunt. Phasellus eget dolor sit amet ipsum dapibus condimentum + vitae quis lectus. Aliquam ut massa in turpis dapibus + convallis. Praesent elit lacus, vestibulum at malesuada et, ornare + et est. Ut augue nunc, sodales ut euismod non, adipiscing vitae + orci. Mauris ut placerat justo. Mauris in ultricies enim. Quisque + nec est eleifend nulla ultrices egestas quis ut quam. Donec + sollicitudin lectus a mauris pulvinar id aliquam urna cursus. Cras + quis ligula sem, vel elementum mi. Phasellus non ullamcorper urna. + +- Class aptent taciti sociosqu ad litora torquent per conubia nostra, + per inceptos himenaeos. In euismod ultrices facilisis. Vestibulum + porta sapien adipiscing augue congue id pretium lectus + molestie. Proin quis dictum nisl. Morbi id quam sapien, sed + vestibulum sem. Duis elementum rutrum mauris sed convallis. Proin + vestibulum magna mi. Aenean tristique hendrerit magna, ac facilisis + nulla hendrerit ut. Sed non tortor sodales quam auctor + elementum. Donec hendrerit nunc eget elit pharetra + pulvinar. Suspendisse id tempus tortor. Aenean luctus, elit commodo + laoreet commodo, justo nisi consequat massa, sed vulputate quam urna + quis eros. Donec vel. diff --git a/tests/files/lorem.txt b/tests/files/lorem.txt @@ -0,0 +1,15 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam +lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam +viverra nec consectetur ante hendrerit. Donec et mollis +dolor. Praesent et diam eget libero egestas mattis sit amet vitae +augue. Nam tincidunt congue enim, ut porta lorem lacinia +consectetur. Donec ut libero sed arcu vehicula ultricies a non +tortor. Lorem ipsum dolor sit amet, consectetur adipiscing +elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, +adipiscing id dolor. Pellentesque auctor nisi id magna consequat +sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt +feugiat nisl imperdiet. Ut convallis libero in urna ultrices +accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at +malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis +parturient montes, nascetur ridiculus mus. In rutrum accumsan +ultricies. Mauris vitae nisi at sem facilisis semper ac in est.