2 # This file is part of GNUnet.
3 # (C) 2010 Christian Grothoff (and other contributing authors)
5 # GNUnet is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Affero General Public License as published
7 # by the Free Software Foundation, either version 3 of the License,
8 # or (at your option) any later version.
10 # GNUnet is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # SPDX-License-Identifier: AGPL3.0-or-later
20 # Testcase for file-sharing command-line tools (recursive publishing & download)
30 gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
31 if gnunet_pyexpect_dir not in sys.path:
32 sys.path.append(gnunet_pyexpect_dir)
34 from gnunet_pyexpect import pexpect
35 from pydiffer import dcdiff
37 if os.name == 'posix':
38 download = './gnunet-download'
39 gnunetarm = 'gnunet-arm'
40 publish = './gnunet-publish'
41 unindex = './gnunet-unindex'
42 search = './gnunet-search'
43 directory = './gnunet-directory'
45 download = './gnunet-download.exe'
46 gnunetarm = 'gnunet-arm.exe'
47 publish = './gnunet-publish.exe'
48 unindex = './gnunet-unindex.exe'
49 search = './gnunet-search.exe'
50 directory = './gnunet-directory.exe'
54 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True
57 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True)
59 arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf'])
62 # pray that `tar' is in PATH.
63 # FIXME: Actually we should check for that and output
64 # a message if it isn't found.
65 tar = tarfile.open('test_gnunet_fs_rec_data.tgz')
67 # first, basic publish-search-download run
72 publish, '-c', 'test_gnunet_fs_rec_data.conf', '-k', 'testdir',
75 stdout=subprocess.PIPE,
76 stderr=subprocess.STDOUT
78 # Can't say much for publishing, except that the last one is the toplevel directory
79 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
83 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
86 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
90 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
93 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
97 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
100 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
104 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
107 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
111 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
114 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
118 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
122 "stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")
124 m = pub.expect("stdout", re.compile(r".+\r?\n"))
128 url = output[output.find("`") + 1:output.find("'")]
133 download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o',
136 stdout=subprocess.PIPE,
137 stderr=subprocess.STDOUT
139 down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n"))
143 None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'],
144 stdout=subprocess.PIPE,
145 stderr=subprocess.STDOUT
147 d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n"))
148 d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n"))
149 d.expect("stdout", re.compile(r"COPYING (.*)\r?\n"))
150 d.expect("stdout", re.compile(r"INSTALL (.*)\r?\n"))
152 os.remove("rdir/b.gnd")
153 os.remove("rdir/a.gnd")
154 diff = dcdiff('dir', 'rdir')
157 "Unexpected difference between source directory and downloaded result:\n{}"
162 arm = subprocess.Popen([
163 gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf'
168 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True
171 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True)
172 shutil.rmtree("dir", True)
173 shutil.rmtree("rdir", True)
174 shutil.rmtree("rdir.gnd", True)