Пример #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--uninstall", help=argparse.SUPPRESS, action="store_true")
    parser.add_argument("--cli", help="Invoke a REPL", action="store_true")
    args = parser.parse_args()

    if args.uninstall:
        uninstall()
    else:
        try:
            if args.cli:
                man = Manager()
                repl = Repl(man)
                repl.start()
            else:
                man = Manager()
                if man.cuentas == []:
                    account_type = "dropbox"
                    print("Select the account type: ", account_type)
                    user = input("Enter a name for the new account: ")
                    man.newAccount(account_type, user)
                man.updateLocalSyncFolder()
        except Exception as e:
            logger = Logger(__name__)
            logger.critical(str(e))
            sys.exit(1)
        finally:
            input("Press ENTER to quit.")
Пример #2
0
class TestSecuritySelective(object):
    """docstring for TestSecuritySelective"""
    def __init__(self):
        super(TestSecuritySelective, self).__init__()
        self.config_default = {"sync_folder_name": "./test/sync_folder", "database": ":memory:"}
        self.man = None

    @classmethod
    def setup_class(klass):
        """This method is run once for each class before any tests are run"""

    @classmethod
    def teardown_class(klass):
        """This method is run once for each class _after_ all tests are run"""

    def setUp(self):
        """This method is run once before _each_ test method is executed"""
        self.man = Manager('user', 'password', config=self.config_default)
        self.man.fileSystemModule = FileSystemModuleStub()

    def teardown(self):
        """This method is run once after _each_ test method is executed"""
        self.man.databaseManager.cleanDatabase()

        self.man = None

    def test_manager(self):
        assert_true(self.man)

    def test_markEncryption(self):
        self.man.newAccount('dropbox_stub', 'user')
        filename = 'test_file.txt'
        self.man.fileSystemModule.createFile(filename)  # create a file
        self.man.updateLocalSyncFolder()

        self.man.markForEncription(filename)
        self.man.fileSystemModule.createFile(filename)  # modify the file

        self.man.updateLocalSyncFolder()  # it should try to encrypt

        remoteFile = self.man.cuentas[0].getFile(filename)
        localFile = self.man.fileSystemModule.openFile(filename)
        assert_equal(localFile.read(), b'text')
        assert_not_equal(remoteFile.read(), b'text')

    def test_unmarkEncryption(self):
        self.man.newAccount('dropbox_stub', 'user')
        filename = 'test_file.txt'
        self.man.fileSystemModule.createFile(filename)  # create a file
        self.man.updateLocalSyncFolder()

        self.man.unmarkForEncription(filename)
        self.man.fileSystemModule.createFile(filename)  # modify the file

        self.man.updateLocalSyncFolder()  # it should try to encrypt

        remoteFile = self.man.cuentas[0].getFile(filename)
        localFile = self.man.fileSystemModule.openFile(filename)
        assert_equal(remoteFile.read(), b'text')
        assert_equal(localFile.read(), b'text')

    def test_unmarked_decryption(self):
        self.man.newAccount('dropbox_stub', 'user')
        filename = 'test_file.txt'

        self.man.fileSystemModule.createFile(filename)  # temporally create a file
        # "text" -('user', 'password')->
        ctext = simplecrypt.encrypt(self.man.securityModule.hashPassword('user', 'password'), b'text')
        stream = tempfile.TemporaryFile()
        stream.write(ctext)
        stream.seek(0)
        self.man.cuentas[0].uploadFile(filename, 'different_revision', stream)  # we upload it to the second account
        self.man.fileSystemModule.remove(filename)  # we have the file only in the remote

        self.man.updateLocalSyncFolder()  # it should try to decrypt, and the file get marked to encrypt

        assert_true(self.man.databaseManager.shouldEncrypt(filename))

        remoteFile = self.man.cuentas[0].getFile(filename)
        localFile = self.man.fileSystemModule.openFile(filename)
        assert_equal(remoteFile.read(), ctext)
        assert_equal(localFile.read(), b'text')

    def test_deleteAccount_decrypt(self):
        self.test_markEncryption()
        filename = 'test_file.txt'

        account = self.man.cuentas[0]
        self.man.deleteAccount(account)

        remoteFile = account.getFile(filename)
        fileList = self.man.fileSystemModule.getFileList()

        expected_fileList = []

        compareFileLists(fileList, expected_fileList)
        assert_equal(remoteFile.read(), b'text')