3 #include "zypp/MediaSetAccess.h"
4 #include "zypp/Fetcher.h"
8 #define BOOST_TEST_MODULE fetcher_test
10 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site")
12 BOOST_AUTO_TEST_SUITE( fetcher_test );
14 BOOST_AUTO_TEST_CASE(fetcher_enqueuedir_noindex)
16 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
17 // Now test that without trusting it, it should throw
18 // do the test by trusting the SHA1SUMS file signature key
20 filesystem::TmpDir dest;
22 fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
23 fetcher.start( dest.path(), media );
26 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
27 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
28 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
29 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
33 BOOST_AUTO_TEST_CASE(fetcher_enqueuedir_autoindex_untrustedkey)
35 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
36 // do the test by trusting the SHA1SUMS file signature key
38 filesystem::TmpDir dest;
40 // add the key as untrusted, which is the same as not adding it and
41 // let autodiscovery to add it
44 fetcher.setOptions( Fetcher::AutoAddIndexes );
45 fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
46 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
48 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
49 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
50 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
51 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
57 BOOST_AUTO_TEST_CASE(fetcher_enqueuedir_autoindex)
59 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
60 // do the test by trusting the SHA1SUMS file signature key
62 filesystem::TmpDir dest;
64 // add the key as trusted
65 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
67 fetcher.setOptions( Fetcher::AutoAddIndexes );
68 fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
69 fetcher.start( dest.path(), media );
71 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
72 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
73 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
74 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
80 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digested_dir_autoindex)
82 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
83 // do the test by trusting the SHA1SUMS file signature key but with a broken file
85 filesystem::TmpDir dest;
87 // add the key as trusted
88 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
89 fetcher.setOptions( Fetcher::AutoAddIndexes );
90 fetcher.enqueueDigestedDir(OnMediaLocation("/complexdir-broken"), true);
91 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
96 BOOST_AUTO_TEST_CASE(fetcher_enqueuebrokendir_noindex)
98 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
99 // do the test by trusting the SHA1SUMS file signature key but with a broken file
101 filesystem::TmpDir dest;
103 // add the key as trusted
104 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
105 fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
106 // this should not throw as we provided no indexes and the
107 // enqueue is not digested
108 fetcher.start( dest.path(), media );
111 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir2").isExist() );
112 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir2/subdir2-file1.txt").isExist() );
113 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file1.txt").isExist() );
114 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file2.txt").isExist() );
119 BOOST_AUTO_TEST_CASE(fetcher_enqueuebrokendir_index)
121 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
122 // do the test by trusting the SHA1SUMS file signature key but with a broken file
124 filesystem::TmpDir dest;
126 // add the key as trusted
127 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
128 fetcher.setOptions( Fetcher::AutoAddIndexes );
129 fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
130 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
136 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digesteddir_brokendir_with_index)
138 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
139 // do the test by trusting the SHA1SUMS file signature key but with a broken file
141 filesystem::TmpDir dest;
143 // add the key as trusted
144 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
145 fetcher.setOptions( Fetcher::AutoAddIndexes );
146 fetcher.enqueueDigestedDir(OnMediaLocation("/complexdir-broken"), true);
147 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
152 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digested_broken_with_autoindex)
154 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
155 // do the test by trusting the SHA1SUMS file signature key but with a broken file
157 filesystem::TmpDir dest;
159 // add the key as trusted
160 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
161 fetcher.setOptions( Fetcher::AutoAddIndexes );
162 fetcher.enqueueDigested(OnMediaLocation("/complexdir-broken/subdir1/subdir1-file2.txt"));
163 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
168 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digested_with_autoindex)
170 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
171 // do the test by trusting the SHA1SUMS file signature key with a good file
172 // checksum in auto discovered index
174 filesystem::TmpDir dest;
176 // add the key as trusted
177 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
178 fetcher.setOptions( Fetcher::AutoAddIndexes );
179 fetcher.enqueueDigested(OnMediaLocation("/complexdir/subdir1/subdir1-file1.txt"));
180 fetcher.start( dest.path(), media );
186 BOOST_AUTO_TEST_CASE(fetcher_enqueuefile_noindex)
188 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
190 filesystem::TmpDir dest;
192 fetcher.enqueue(OnMediaLocation("/file-1.txt"));
193 fetcher.start( dest.path(), media );
194 BOOST_CHECK( PathInfo(dest.path() + "/file-1.txt").isExist() );
200 BOOST_AUTO_TEST_CASE(fetcher_simple)
202 MediaSetAccess media( (DATADIR).asUrl(), "/" );
206 filesystem::TmpDir dest;
207 OnMediaLocation loc("/complexdir/subdir1/subdir1-file1.txt");
208 loc.setChecksum(CheckSum::sha1("f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"));
209 fetcher.enqueueDigested(loc);
210 fetcher.start(dest.path(), media);
212 // now we break the checksum and it should fail
213 loc.setChecksum(CheckSum::sha1("f1d2d2f924e986ac86fdf7b36c94bcdf32beec16"));
214 fetcher.enqueueDigested(loc);
215 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
221 BOOST_AUTO_TEST_CASE(content_index)
223 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
226 // test transfering one file by setting the index
228 filesystem::TmpDir dest;
229 OnMediaLocation loc("/contentindex/subdir1/subdir1-file1.txt");
230 // trust the key manually
231 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/contentindex/content.key"), true);
232 fetcher.addIndex(OnMediaLocation("/contentindex/content", 1));
233 fetcher.enqueue(loc);
234 fetcher.start(dest.path(), media);
236 BOOST_CHECK( PathInfo(dest.path() + "/contentindex/subdir1/subdir1-file1.txt").isExist() );
241 BOOST_AUTO_TEST_CASE(enqueue_broken_content_index)
243 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
245 filesystem::TmpDir dest;
247 OnMediaLocation loc("/contentindex-broken-digest/subdir1/subdir1-file1.txt",1);
248 // key was already imported as trusted
249 fetcher.addIndex(OnMediaLocation("/contentindex-broken-digest/content", 1));
250 fetcher.enqueue(loc);
251 fetcher.start(dest.path(), media);
253 BOOST_CHECK( PathInfo(dest.path() + "/contentindex-broken-digest/subdir1/subdir1-file1.txt").isExist() );
255 // now retrieve a file that is modified, so the checksum has to fail
256 loc = OnMediaLocation("/contentindex-broken-digest/subdir1/subdir1-file2.txt",1);
257 fetcher.addIndex(OnMediaLocation("/contentindex-broken-digest/content", 1));
258 fetcher.enqueue(loc);
259 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
264 BOOST_AUTO_TEST_CASE(enqueue_digested_images_file_content_autoindex)
266 MediaSetAccess media( ( DATADIR + "/images-file").asUrl(), "/" );
268 filesystem::TmpDir dest;
270 OnMediaLocation loc("/images/images.xml",1);
271 fetcher.setOptions( Fetcher::AutoAddIndexes );
272 fetcher.enqueueDigested(loc);
273 fetcher.start(dest.path(), media);
275 BOOST_CHECK( PathInfo(dest.path() + "/images/images.xml").isExist() );
280 BOOST_AUTO_TEST_CASE(enqueue_digested_images_file_content_autoindex_unsigned)
282 MediaSetAccess media( ( DATADIR + "/images-file-unsigned").asUrl(), "/" );
284 filesystem::TmpDir dest;
286 OnMediaLocation loc("/images/images.xml",1);
287 fetcher.setOptions( Fetcher::AutoAddIndexes );
288 fetcher.enqueueDigested(loc);
289 // it should throw because unsigned file throws
290 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
292 // the target file was NOT transferred
293 BOOST_CHECK( ! PathInfo(dest.path() + "/images/images.xml").isExist() );
298 BOOST_AUTO_TEST_CASE(enqueue_broken_content_noindex)
300 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
304 filesystem::TmpDir dest;
305 OnMediaLocation loc("/contentindex-broken-digest/subdir1/subdir1-file1.txt",1);
306 // key was already imported as trusted
307 fetcher.enqueue(loc);
308 fetcher.start(dest.path(), media);
310 // now retrieve a file that is modified, so the checksum has to fail
311 loc = OnMediaLocation("/contentindex-broken-digest/subdir1/subdir1-file2.txt",1);
312 fetcher.enqueue(loc);
313 fetcher.start( dest.path(), media );
315 BOOST_CHECK( PathInfo(dest.path() + "/contentindex-broken-digest/subdir1/subdir1-file2.txt").isExist() );
321 BOOST_AUTO_TEST_CASE(enqueuedir_http)
323 WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str(), 10001);
326 // at this point the key is already trusted
328 MediaSetAccess media( web.url(), "/" );
330 filesystem::TmpDir dest;
332 // auto add the SHA1SUMS
333 fetcher.setOptions( Fetcher::AutoAddIndexes );
334 fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
335 fetcher.start( dest.path(), media );
339 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
340 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
341 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
342 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
347 MediaSetAccess media( web.url(), "/" );
349 filesystem::TmpDir dest;
351 // auto add the SHA1SUMS
352 fetcher.setOptions( Fetcher::AutoAddIndexes );
353 fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
354 // should throw because wrong checksum
355 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
358 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir2").isExist() );
360 // unprocessed after failure:
361 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir2/subdir2-file1.txt").isExist() );
363 // this one got transferred before the failure, so it is there
364 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file1.txt").isExist() );
366 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file2.txt").isExist() );
374 BOOST_AUTO_TEST_SUITE_END();
376 // vim: set ts=2 sts=2 sw=2 ai et: