def test_push_sshfs_encfs(self): self._populate(self.local1_base) remote = Remote("remote", self.remote_host, self.local1_ms, key=self.key) remote.mount() Diff(Repo(self.local1_base), Repo(remote)).push() self.assertEqual(3, len(os.listdir(self.remote))) remote.umount()
def _main_push_delta_key(self, path=None): self._populate(self.local3_base) os.chdir(self.local3_base) # push files to remote sys.argv[1:] = ["push", "remote", "-u"] synkrotron.main() os.makedirs(os.path.join(self.local3_base, "dir", "new")) # push changes to delta sys.argv[1:] = ["push", "remote", "-u", "--delta=%s" % self.delta] if path: sys.argv.append("--path=" + path) synkrotron.main() # check delta files r = Remote("remote", self.remote_host, self.local3_ms, key=self.key, mount_point=self.mount_point) r.mount() files = [f for f in os.listdir(self.delta) if f != ".encfs6.xml" and f != ".synkrotron"] self.assertListEqual(["dir"], r.decrypt_names(files)) path = os.path.join(self.delta, files[0]) self.assertListEqual(["new"], r.decrypt_names(os.listdir(path))) # push delta to remote os.chdir(self.delta) sys.argv[1:] = ["push", "remote", "-u"] synkrotron.main() # check remote files (should be the same now (encrypted of course) as the ones in self.local3_base) self.assertEqual(0, len(Diff(Repo(self.local3_base), Repo(r)).compute())) r.umount()
def test_name_encryption(self): remote = Remote("remote", self.remote, self.local1_ms, key=self.key) remote.mount() clear = ["a/b", "/c", "x/y/ ä"] encrypted = remote.encrypt_names(clear) decrypted = remote.decrypt_names(encrypted) self.assertListEqual(clear, decrypted) remote.umount()
def test_push_delta(self): self._populate(self.local1_base) self._populate(self.remote) os.remove(os.path.join(self.remote, "file_ä")) remote = Remote("remote", self.remote, self.local1_ms) remote.mount() Diff(Repo(self.local1_base), Repo(remote)).push(delta=self.delta) remote.umount() self.assertListEqual([".synkrotron", "file_ä"], os.listdir(self.delta))
def test_mount_sshfs(self): remote = Remote("remote", self.remote_host, self.local1_ms) path = remote.mount() self.assertEqual(remote._sync_path("sshfs"), path) self.assertTrue(os.path.ismount(path)) self._populate(path) remote.umount() self.assertFalse(os.path.exists(path)) self.assertEqual(2, len(os.listdir(self.remote))) with self.assertRaises(Exception): Remote("remote", self.remote_host + "x", self.local2_ms).mount()
def test_collect_remote_key(self): remote = Remote("remote", self.remote_host, self.local1_ms, key=self.key) remote.mount() self._populate(remote.encfs_destination) files = Repo(remote).collect() self.assertEqual(4, len(files)) self.assertEqual("d", files["."][0]) self.assertEqual(("f", 8), files["dir/file_ä"][:2]) self.assertEqual(("f", 7), files["file_ä"][:2]) self.assertEqual("d", files["dir"][0]) remote.umount()
def test_collect_remote(self): self._populate(self.remote) remote = Remote("remote", self.remote_host, self.local1_ms) remote.mount() files = Repo(remote).collect() self.assertEqual(4, len(files)) self.assertEqual("d", files["."][0]) self.assertEqual(("f", 8), files["dir/file_ä"][:2]) self.assertEqual(("f", 7), files["file_ä"][:2]) self.assertEqual("d", files["dir"][0]) remote.umount()
def test_main_push_clear(self): self._populate(self.local4_base) os.chdir(self.local4_base) sys.argv[1:] = ["push", "remote", "-u"] synkrotron.main() # "dir/file_ä" should be unencrypted self.assertListEqual(["file_ä"], os.listdir(os.path.join(self.remote, "clear/dir"))) # "file_ä" should be encrypted r = Remote("remote", self.remote_host, self.local4_ms, key=self.key) r.mount() files = [f for f in os.listdir(self.remote) if f != ".encfs6.xml" and f != "clear"] self.assertListEqual(["file_ä"], r.decrypt_names(files)) r.umount()
def test_mount_sshfs_encfs_mp(self): remote = Remote("remote", self.remote_host, self.local1_ms, key=self.key, mount_point=self.mount_point) path = remote.mount() self.assertEqual(self.mount_point, path) self.assertTrue(os.path.islink(path)) target_sshfs = remote._sync_path("sshfs") target_encfs = remote._sync_path("encfs") self.assertTrue(os.path.ismount(target_sshfs)) self.assertTrue(os.path.ismount(target_encfs)) self._populate(path) remote.umount() self.assertFalse(os.path.exists(path)) self.assertFalse(os.path.exists(target_sshfs)) self.assertFalse(os.path.exists(target_encfs)) self.assertEqual(3, len(os.listdir(self.remote)))
def test_cache(self): remote = Remote("remote", self.remote, self.local1_ms, key=self.key) remote.mount() clear = ["a/b", "c", "x/y/ ä"] remote.encrypt_names(clear) self.assertEqual(6, len(remote._cache[0])) self.assertEqual(6, len(remote._cache[1])) self.assertTrue("y" in remote._cache[0].values()) self.assertTrue("y" in remote._cache[1].keys()) cache = remote._cache remote.save_cache() del remote._cache remote._load_cache() self.assertSameElements(cache[0], remote._cache[0]) self.assertSameElements(cache[1], remote._cache[1]) remote.umount()
def test_diff_content_sshfs(self): remote = Remote("remote", self.remote_host, self.local1_ms) remote.mount() self._populate(self.local1_base) self._populate(self.remote) self._fix_mtime(self.local1_base) self._fix_mtime(self.remote) diff = Diff(Repo(self.local1_base), Repo(remote), content=True) self.assertEqual((), self._filter(diff)) f_src = os.path.join(self.local1_base, "dir", "file_ä") f_dst = os.path.join(self.remote, "dir", "file_ä") with io.open(f_src, "w") as f: f.write("xontent2") os.utime(f_src, (os.path.getatime(f_dst), os.path.getmtime(f_dst))) diff = Diff(Repo(self.local1_base), Repo(remote), content=True) self.assertEqual((("dir/file_ä", "content"),), self._filter(diff)) remote.umount()
def test_reverse_mount(self): remote = Remote("remote", self.remote, self.local1_ms, key=self.key) remote.mount() remote.reverse_mount() self._populate(self.local1_base) self._populate(remote.encfs_destination) files_remote = os.listdir(self.remote) files_reverse = os.listdir(remote.encfs_reverse) self.assertEqual(3, len(files_reverse)) for name in files_remote: if name == ".encfs6.xml": continue self.assertTrue(name in files_remote) path_remote = os.path.join(self.remote, name) path_reverse = os.path.join(remote.encfs_reverse, name) if os.path.isfile(path_remote): self.assertEqual(Repo._file_hash(path_remote), Repo._file_hash(path_reverse)) remote.reverse_umount() remote.umount()
def test_diff_content_sshfs_encfs(self): remote = Remote("remote", self.remote_host, self.local1_ms, key=self.key) remote.mount() remote.reverse_mount() self._populate(self.local1_base) self._populate(remote.encfs_destination) self._fix_mtime(self.local1_base) self._fix_mtime(remote.encfs_destination) diff = Diff(Repo(self.local1_base), Repo(remote), content=True) self.assertEqual((), self._filter(diff)) f_local = os.path.join(self.local1_base, "dir", "file_ä") f_remote = os.path.join(remote.encfs_destination, "dir", "file_ä") with io.open(f_local, "w") as f: f.write("xontent2") os.utime(f_local, (os.path.getatime(f_remote), os.path.getmtime(f_remote))) diff = Diff(Repo(self.local1_base), Repo(remote), content=True) self.assertEqual((("dir/file_ä", "content"),), self._filter(diff)) remote.reverse_umount() remote.umount()
def test_mount_encfs(self): remote = Remote("remote", self.remote, self.local1_ms, key=self.key) path = remote.mount() self.assertEqual(remote._sync_path("encfs"), path) self.assertEqual(self.remote, remote.encfs_source) self.assertTrue(os.path.ismount(path)) self._populate(path) remote.umount() self.assertFalse(os.path.exists(path)) self.assertEqual(3, len(os.listdir(self.remote))) # inexistent location with self.assertRaises(Exception): Remote("remote", self.remote + "x", self.local1_ms, key=self.key).mount() # re-mount with wrong key remote = Remote("remote", self.remote, self.local2_ms, key=self.key) remote.mount() remote.umount() remote = Remote("remote", self.remote, self.local2_ms, key=self.key + "x") with self.assertRaises(Exception): remote.mount()