Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / tests / zypp / Fetcher_test.cc
index 94bb360..48f4bd7 100644 (file)
@@ -30,10 +30,32 @@ BOOST_AUTO_TEST_CASE(fetcher_enqueuedir_noindex)
   }
 }
 
+BOOST_AUTO_TEST_CASE(fetcher_enqueuedir_autoindex_untrustedkey)
+{
+  MediaSetAccess media( ( DATADIR).asUrl(), "/" );
+  // do the test by trusting the SHA1SUMS file signature key
+  {
+      filesystem::TmpDir dest;
+
+      // add the key as untrusted, which is the same as not adding it and
+      // let autodiscovery to add it
+
+      Fetcher fetcher;
+      fetcher.setOptions( Fetcher::AutoAddIndexes );
+      fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
+      BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
+
+      BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
+      BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
+      BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
+      BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
+
+      fetcher.reset();
+  }
+}
+
 BOOST_AUTO_TEST_CASE(fetcher_enqueuedir_autoindex)
 {
-  base::LogControl::TmpLineWriter shutUp( new zypp::log::FileLineWriter( "/tmp/YLOG" ) );
-  MIL << "GO" << endl;
   MediaSetAccess media( ( DATADIR).asUrl(), "/" );
   // do the test by trusting the SHA1SUMS file signature key
   {
@@ -267,7 +289,7 @@ BOOST_AUTO_TEST_CASE(enqueue_digested_images_file_content_autoindex_unsigned)
         // it should throw because unsigned file throws
         BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), FileCheckException);
         fetcher.reset();
-        // the target file was NOT transfered
+        // the target file was NOT transferred
         BOOST_CHECK( ! PathInfo(dest.path() + "/images/images.xml").isExist() );
         fetcher.reset();
   }
@@ -298,15 +320,12 @@ BOOST_AUTO_TEST_CASE(enqueue_broken_content_noindex)
 
 BOOST_AUTO_TEST_CASE(enqueuedir_http)
 {
+    WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str(), 10001);
+    web.start();
+
   // at this point the key is already trusted
   {
-      // add the key as trusted
-      //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
-
-      WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() );
-      web.start();
-
-      MediaSetAccess media( Url("http://localhost:9099"), "/" );
+      MediaSetAccess media( web.url(), "/" );
       Fetcher fetcher;
       filesystem::TmpDir dest;
 
@@ -321,22 +340,11 @@ BOOST_AUTO_TEST_CASE(enqueuedir_http)
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
-
-      web.stop();
   }
-}
 
-BOOST_AUTO_TEST_CASE(enqueuedir_http_broken)
-{
-  // at this point the key is already trusted
+  // test broken tree
   {
-      // add the key as trusted
-      //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
-
-      WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() );
-      web.start();
-
-      MediaSetAccess media( Url("http://localhost:9099"), "/" );
+      MediaSetAccess media( web.url(), "/" );
       Fetcher fetcher;
       filesystem::TmpDir dest;
 
@@ -351,17 +359,16 @@ BOOST_AUTO_TEST_CASE(enqueuedir_http_broken)
 
       BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir2/subdir2-file1.txt").isExist() );
 
-      // this one got transfered before the failure, so it is there
+      // this one got transferred before the failure, so it is there
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file1.txt").isExist() );
       BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file2.txt").isExist() );
 
       fetcher.reset();
-
-      web.stop();
   }
+  
+  web.stop();
 }
 
-
 BOOST_AUTO_TEST_SUITE_END();
 
 // vim: set ts=2 sts=2 sw=2 ai et: