- fixed password handling in URLs (bug #347273)
authorArvin Schnell <aschnell@suse.de>
Tue, 18 Dec 2007 11:34:31 +0000 (11:34 +0000)
committerArvin Schnell <aschnell@suse.de>
Tue, 18 Dec 2007 11:34:31 +0000 (11:34 +0000)
package/libzypp.changes
tests/repo/RepoVariables_test.cc
zypp/RepoInfo.cc
zypp/RepoManager.cc
zypp/Url.cc
zypp/repo/RepoType.h
zypp/repo/RepoVariables.cc
zypp/repo/RepoVariables.h
zypp/url/UrlBase.cc

index 6e253e9..71456f8 100644 (file)
@@ -1,4 +1,9 @@
 -------------------------------------------------------------------
+Tue Dec 18 12:28:22 CET 2007 - aschnell@suse.de
+
+- fixed password handling in URLs (bug #347273)
+
+-------------------------------------------------------------------
 Mon Dec 17 13:47:44 CET 2007 - ma@suse.de
 
 - Fixed default text locale detection not to use static variables. (#346872)
index 44289a5..c5b1e7e 100644 (file)
@@ -24,14 +24,29 @@ using namespace zypp::repo;
 
 void replace_test(const string &dir)
 {
-  RepoVariablesStringReplacer replacer;
-  
-  BOOST_CHECK_EQUAL(replacer("http://foo/$arch/bar"),
+  /* check RepoVariablesStringReplacer */
+
+  RepoVariablesStringReplacer replacer1;
+
+  BOOST_CHECK_EQUAL(replacer1("http://foo/$arch/bar"),
                     "http://foo/"+ ZConfig::instance().systemArchitecture().asString() + "/bar");
 
   getZYpp()->setArchitecture(Arch("i686"));
-  BOOST_CHECK_EQUAL(replacer("http://foo/$arch/bar/$basearch"),
+  BOOST_CHECK_EQUAL(replacer1("http://foo/$arch/bar/$basearch"),
                     "http://foo/i686/bar/i386");
+
+  /* check RepoVariablesUrlReplacer */
+
+  RepoVariablesUrlReplacer replacer2;
+
+  BOOST_CHECK_EQUAL(replacer2(Url("ftp://user:secret@site.org/$arch/")).asCompleteString(),
+                   "ftp://user:secret@site.org/i686/");
+
+  BOOST_CHECK_EQUAL(replacer2(Url("http://user:my$arch@site.org/$basearch/")).asCompleteString(),
+                   "http://user:my$arch@site.org/i386/");
+
+  BOOST_CHECK_EQUAL(replacer2(Url("http://site.org/update/?arch=$arch")).asCompleteString(),
+                   "http://site.org/update/?arch=i686");
 }
 
 test_suite*
@@ -45,15 +60,15 @@ init_unit_test_suite( int argc, char *argv[] )
     cout << "RepoVariables_test:"
       " path to directory with test data required as parameter. Using " << datadir  << endl;
     //return (test_suite *)0;
-    
+
   }
   else
   {
     datadir = argv[1];
   }
-  
+
   test_suite* test= BOOST_TEST_SUITE("RepoVariables");
-  
+
   std::string const params[] = { datadir };
   test->add(BOOST_PARAM_TEST_CASE(&replace_test,
                                  (std::string const*)params, params+1));
index 82cf94a..843ce82 100644 (file)
@@ -191,7 +191,7 @@ namespace zypp
     {
       return alias();
     }
-    
+
     repo::RepoVariablesStringReplacer replacer;
     return replacer(_pimpl->name);
   }
index 2d9a575..9bab4e6 100644 (file)
@@ -117,17 +117,17 @@ namespace zypp
 
     if ( !store.isCached(info.alias()) )
       return;
-   
+
     MIL << info.alias() << " cleaning cache..." << endl;
     data::RecordId id = store.lookupRepository(info.alias());
-    
+
     CombinedProgressData subprogrcv(progress);
-    
+
     store.cleanRepository(id, subprogrcv);
   }
-  
+
   ////////////////////////////////////////////////////////////////////////////
-  
+
   /**
    * Reads RepoInfo's from a repo file.
    *
@@ -249,7 +249,7 @@ namespace zypp
       static shared_ptr<Impl> _nullimpl( new Impl );
       return _nullimpl;
     }
-    
+
   private:
     friend Impl * rwcowClone<Impl>( const Impl * rhs );
     /** clone for RWCOW_pointer */
@@ -312,7 +312,7 @@ namespace zypp
   }
 
   ////////////////////////////////////////////////////////////////////////////
-      
+
   RepoStatus RepoManager::metadataStatus( const RepoInfo &info ) const
   {
     Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
@@ -519,7 +519,7 @@ namespace zypp
       ERR << "refresh check failed for " << url << endl;
       ZYPP_RETHROW(e);
     }
-    
+
     return true; // default
   }
 
@@ -624,7 +624,7 @@ namespace zypp
       {
         ZYPP_CAUGHT(e);
         ERR << "Trying another url..." << endl;
-        
+
         // remember the exception caught for the *first URL*
         // if all other URLs fail, the rexception will be thrown with the
         // cause of the problem of the first URL remembered
@@ -680,7 +680,7 @@ namespace zypp
           MIL << info.alias() << " cache rebuild is forced" << endl;
         }
       }
-      
+
       needs_cleaning = true;
     }
 
@@ -709,7 +709,7 @@ namespace zypp
       break;
     }
 
-    
+
     switch ( repokind.toEnum() )
     {
       case RepoType::RPMMD_e :
@@ -769,7 +769,7 @@ namespace zypp
         return repo::RepoType::RPMMD;
       if ( access.doesFileExist("/content") )
         return repo::RepoType::YAST2;
-  
+
       // if it is a local url of type dir
       if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) )
       {
@@ -798,9 +798,9 @@ namespace zypp
 
     return repo::RepoType::NONE;
   }
-    
+
   ////////////////////////////////////////////////////////////////////////////
-  
+
   void RepoManager::cleanCache( const RepoInfo &info,
                                 const ProgressData::ReceiverFnc & progressrcv )
   {
@@ -833,7 +833,7 @@ namespace zypp
     progress.sendTo(ProgressReportAdaptor( progressrcv, report ));
     //progress.sendTo( progressrcv );
     progress.name(str::form(_("Reading repository '%s' cache"), info.name().c_str()));
-    
+
     cache::CacheStore store(_pimpl->options.repoCachePath);
 
     if ( ! store.isCached( info.alias() ) )
@@ -842,9 +842,9 @@ namespace zypp
     MIL << "Repository " << info.alias() << " is cached" << endl;
 
     data::RecordId id = store.lookupRepository(info.alias());
-    
+
     CombinedProgressData subprogrcv(progress);
-    
+
     repo::cached::RepoOptions opts( info, _pimpl->options.repoCachePath, id );
     opts.readingResolvablesProgress = subprogrcv;
     repo::cached::RepoImpl::Ptr repoimpl =
@@ -1031,7 +1031,7 @@ namespace zypp
     callback::SendReport<ProgressReport> report;
     progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
     progress.name(str::form(_("Removing repository '%s'"), info.name().c_str()));
-    
+
     MIL << "Going to delete repo " << info.alias() << endl;
 
     std::list<RepoInfo> repos = knownRepositories();
index aeb9cba..9c6b42f 100644 (file)
@@ -9,6 +9,7 @@
 /**
  * \file zypp/Url.cc
  */
+
 #include <zypp/Url.h>
 #include <zypp/base/Gettext.h>
 #include <zypp/base/String.h>
@@ -804,12 +805,12 @@ namespace zypp
   {
     return (lhs.asCompleteString() == rhs.asCompleteString());
   }
-  
+
   bool operator!=( const Url &lhs, const Url &rhs )
   {
     return (lhs.asCompleteString() != rhs.asCompleteString());
   }
-  
+
   ////////////////////////////////////////////////////////////////////
 } // namespace zypp
 //////////////////////////////////////////////////////////////////////
index 4926446..e4a6c53 100644 (file)
@@ -11,7 +11,7 @@
 #define ZYPP_REPO_TYPE_H_
 
 #include <iosfwd>
-#include<string>
+#include <string>
 
 namespace zypp
 {
index 8bf617f..415dfca 100644 (file)
@@ -21,7 +21,7 @@ namespace zypp
 {
 namespace repo
 {
-  
+
 RepoVariablesStringReplacer::RepoVariablesStringReplacer()
 {}
 
@@ -31,19 +31,19 @@ RepoVariablesStringReplacer::~RepoVariablesStringReplacer()
 std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const
 {
   string newvalue(value);
-  
+
   // $arch
   newvalue = str::gsub( newvalue,
                         "$arch",
                         ZConfig::instance().systemArchitecture().asString() );
   // $basearch
-  
+
   Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) );
   Arch::CompatSet::const_iterator it = cset.end();
   --it;
   // now at noarch
   --it;
-  
+
   Arch basearch = *it;
   if ( basearch == Arch_noarch )
   {
@@ -64,21 +64,20 @@ RepoVariablesUrlReplacer::RepoVariablesUrlReplacer()
 RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer()
 {}
 
-
+/*
+ * Replaces '$arch' and '$basearch' in the path and query part of the URL
+ * with the global ZYpp values. Examples:
+ *
+ * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/
+ * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386
+ */
 Url RepoVariablesUrlReplacer::operator()( const Url &value ) const
 {
+  Url newurl = value;
   RepoVariablesStringReplacer replacer;
-  string transformed = replacer(value.asString());
-  Url newurl;
-  try {
-    newurl = Url(transformed);
-  }
-  catch ( const Exception &e )
-  {
-    ZYPP_CAUGHT(e);
-    // just return what we got
-    return value;
-  }
+  newurl.setPathData(replacer(value.getPathData()));
+  newurl.setQueryString(replacer(value.getQueryString()));
+
   return newurl;
 }
 
index 6d2000b..0775f07 100644 (file)
@@ -11,7 +11,7 @@
 #define ZYPP_REPO_VARIABLES_H_
 
 #include <iosfwd>
-#include<string>
+#include <string>
 
 #include "zypp/Url.h"
 
@@ -28,7 +28,7 @@ namespace zypp
   struct RepoVariablesStringReplacer : public std::unary_function<std::string, std::string>
   {
     RepoVariablesStringReplacer();
-    
+
     std::string operator()( const std::string &value ) const;
 
     ~RepoVariablesStringReplacer();
@@ -42,12 +42,12 @@ namespace zypp
   struct RepoVariablesUrlReplacer : public std::unary_function<Url, Url>
   {
     RepoVariablesUrlReplacer();
-    
+
     Url operator()( const Url &url ) const;
-    
+
     ~RepoVariablesUrlReplacer();
   };
-  
+
   } // ns repo
 } // ns zypp
 
index 68ee0e0..c79cd5c 100644 (file)
@@ -1320,7 +1320,7 @@ namespace zypp
         {
           struct in6_addr ip;
           std::string temp( host.substr(1, host.size()-2));
-          
+
           return inet_pton(AF_INET6, temp.c_str(), &ip) > 0;
         }
         else