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)
35 base::LogControl::TmpLineWriter shutUp( new zypp::log::FileLineWriter( "/tmp/YLOG" ) );
37 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
38 // do the test by trusting the SHA1SUMS file signature key
40 filesystem::TmpDir dest;
42 // add the key as trusted
43 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
45 fetcher.setOptions( Fetcher::AutoAddIndexes );
46 fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
47 fetcher.start( dest.path(), media );
49 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
50 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
51 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
52 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
58 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digested_dir_autoindex)
60 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
61 // do the test by trusting the SHA1SUMS file signature key but with a broken file
63 filesystem::TmpDir dest;
65 // add the key as trusted
66 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
67 fetcher.setOptions( Fetcher::AutoAddIndexes );
68 fetcher.enqueueDigestedDir(OnMediaLocation("/complexdir-broken"), true);
69 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
74 BOOST_AUTO_TEST_CASE(fetcher_enqueuebrokendir_noindex)
76 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
77 // do the test by trusting the SHA1SUMS file signature key but with a broken file
79 filesystem::TmpDir dest;
81 // add the key as trusted
82 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
83 fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
84 // this should not throw as we provided no indexes and the
85 // enqueue is not digested
86 fetcher.start( dest.path(), media );
89 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir2").isExist() );
90 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir2/subdir2-file1.txt").isExist() );
91 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file1.txt").isExist() );
92 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file2.txt").isExist() );
97 BOOST_AUTO_TEST_CASE(fetcher_enqueuebrokendir_index)
99 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
100 // do the test by trusting the SHA1SUMS file signature key but with a broken file
102 filesystem::TmpDir dest;
104 // add the key as trusted
105 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
106 fetcher.setOptions( Fetcher::AutoAddIndexes );
107 fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
108 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
114 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digesteddir_brokendir_with_index)
116 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
117 // do the test by trusting the SHA1SUMS file signature key but with a broken file
119 filesystem::TmpDir dest;
121 // add the key as trusted
122 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
123 fetcher.setOptions( Fetcher::AutoAddIndexes );
124 fetcher.enqueueDigestedDir(OnMediaLocation("/complexdir-broken"), true);
125 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
130 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digested_broken_with_autoindex)
132 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
133 // do the test by trusting the SHA1SUMS file signature key but with a broken file
135 filesystem::TmpDir dest;
137 // add the key as trusted
138 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
139 fetcher.setOptions( Fetcher::AutoAddIndexes );
140 fetcher.enqueueDigested(OnMediaLocation("/complexdir-broken/subdir1/subdir1-file1.txt"));
141 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
146 BOOST_AUTO_TEST_CASE(fetcher_enqueue_digested_with_autoindex)
148 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
149 // do the test by trusting the SHA1SUMS file signature key with a good file
150 // checksum in auto discovered index
152 filesystem::TmpDir dest;
154 // add the key as trusted
155 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
156 fetcher.setOptions( Fetcher::AutoAddIndexes );
157 fetcher.enqueueDigested(OnMediaLocation("/complexdir/subdir1/subdir1-file1.txt"));
158 fetcher.start( dest.path(), media );
164 BOOST_AUTO_TEST_CASE(fetcher_enqueuefile_noindex)
166 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
168 filesystem::TmpDir dest;
170 fetcher.enqueue(OnMediaLocation("/file-1.txt"));
171 fetcher.start( dest.path(), media );
172 BOOST_CHECK( PathInfo(dest.path() + "/file-1.txt").isExist() );
178 BOOST_AUTO_TEST_CASE(fetcher_simple)
180 MediaSetAccess media( (DATADIR).asUrl(), "/" );
184 filesystem::TmpDir dest;
185 OnMediaLocation loc("/complexdir/subdir1/subdir1-file1.txt");
186 loc.setChecksum(CheckSum::sha1("f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"));
187 fetcher.enqueueDigested(loc);
188 fetcher.start(dest.path(), media);
190 // now we break the checksum and it should fail
191 loc.setChecksum(CheckSum::sha1("f1d2d2f924e986ac86fdf7b36c94bcdf32beec16"));
192 fetcher.enqueueDigested(loc);
193 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
199 BOOST_AUTO_TEST_CASE(content_index)
201 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
204 // test transfering one file by setting the index
206 filesystem::TmpDir dest;
207 OnMediaLocation loc("/contentindex/subdir1/subdir1-file1.txt");
208 // trust the key manually
209 getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/contentindex/content.key"), true);
210 fetcher.addIndex(OnMediaLocation("/contentindex/content", 1));
211 fetcher.enqueue(loc);
212 fetcher.start(dest.path(), media);
214 BOOST_CHECK( PathInfo(dest.path() + "/contentindex/subdir1/subdir1-file1.txt").isExist() );
219 BOOST_AUTO_TEST_CASE(enqueue_broken_content_index)
221 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
223 filesystem::TmpDir dest;
225 OnMediaLocation loc("/contentindex-broken-digest/subdir1/subdir1-file1.txt",1);
226 // key was already imported as trusted
227 fetcher.addIndex(OnMediaLocation("/contentindex-broken-digest/content", 1));
228 fetcher.enqueue(loc);
229 fetcher.start(dest.path(), media);
231 BOOST_CHECK( PathInfo(dest.path() + "/contentindex-broken-digest/subdir1/subdir1-file1.txt").isExist() );
233 // now retrieve a file that is modified, so the checksum has to fail
234 loc = OnMediaLocation("/contentindex-broken-digest/subdir1/subdir1-file2.txt",1);
235 fetcher.addIndex(OnMediaLocation("/contentindex-broken-digest/content", 1));
236 fetcher.enqueue(loc);
237 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
242 BOOST_AUTO_TEST_CASE(enqueue_digested_images_file_content_autoindex)
244 MediaSetAccess media( ( DATADIR + "/images-file").asUrl(), "/" );
246 filesystem::TmpDir dest;
248 OnMediaLocation loc("/images/images.xml",1);
249 fetcher.setOptions( Fetcher::AutoAddIndexes );
250 fetcher.enqueueDigested(loc);
251 fetcher.start(dest.path(), media);
253 BOOST_CHECK( PathInfo(dest.path() + "/images/images.xml").isExist() );
258 BOOST_AUTO_TEST_CASE(enqueue_digested_images_file_content_autoindex_unsigned)
260 MediaSetAccess media( ( DATADIR + "/images-file-unsigned").asUrl(), "/" );
262 filesystem::TmpDir dest;
264 OnMediaLocation loc("/images/images.xml",1);
265 fetcher.setOptions( Fetcher::AutoAddIndexes );
266 fetcher.enqueueDigested(loc);
267 // it should throw because unsigned file throws
268 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
270 // the target file was NOT transfered
271 BOOST_CHECK( ! PathInfo(dest.path() + "/images/images.xml").isExist() );
276 BOOST_AUTO_TEST_CASE(enqueue_broken_content_noindex)
278 MediaSetAccess media( ( DATADIR).asUrl(), "/" );
282 filesystem::TmpDir dest;
283 OnMediaLocation loc("/contentindex-broken-digest/subdir1/subdir1-file1.txt",1);
284 // key was already imported as trusted
285 fetcher.enqueue(loc);
286 fetcher.start(dest.path(), media);
288 // now retrieve a file that is modified, so the checksum has to fail
289 loc = OnMediaLocation("/contentindex-broken-digest/subdir1/subdir1-file2.txt",1);
290 fetcher.enqueue(loc);
291 fetcher.start( dest.path(), media );
293 BOOST_CHECK( PathInfo(dest.path() + "/contentindex-broken-digest/subdir1/subdir1-file2.txt").isExist() );
299 BOOST_AUTO_TEST_CASE(enqueuedir_http)
301 // at this point the key is already trusted
303 // add the key as trusted
304 //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
306 WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() );
309 MediaSetAccess media( Url("http://localhost:9099"), "/" );
311 filesystem::TmpDir dest;
313 // auto add the SHA1SUMS
314 fetcher.setOptions( Fetcher::AutoAddIndexes );
315 fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
316 fetcher.start( dest.path(), media );
320 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
321 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
322 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
323 BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
329 BOOST_AUTO_TEST_CASE(enqueuedir_http_broken)
331 // at this point the key is already trusted
333 // add the key as trusted
334 //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
336 WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() );
339 MediaSetAccess media( Url("http://localhost:9099"), "/" );
341 filesystem::TmpDir dest;
343 // auto add the SHA1SUMS
344 fetcher.setOptions( Fetcher::AutoAddIndexes );
345 fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
346 // should throw because wrong checksum
347 BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
350 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir2").isExist() );
352 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir2/subdir2-file1.txt").isExist() );
354 // this one got transfered before the failure, so it is there
355 BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file1.txt").isExist() );
356 BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file2.txt").isExist() );
365 BOOST_AUTO_TEST_SUITE_END();
367 // vim: set ts=2 sts=2 sw=2 ai et: