- split the gpgkey line and take the first one as url to avoid
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 21 Dec 2010 16:20:16 +0000 (17:20 +0100)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 21 Dec 2010 16:20:16 +0000 (17:20 +0100)
  crash when creating an url from the line, as Fedora hat the
  *BRILLIANT* idea of using more than one url per line.

tests/parser/CMakeLists.txt
tests/parser/RepoFileReader_test.cc [new file with mode: 0644]
zypp/parser/RepoFileReader.cc

index 62aba6c..3c36965 100644 (file)
@@ -3,4 +3,5 @@ ADD_SUBDIRECTORY( inifile )
 ADD_SUBDIRECTORY(ws)
 
 ADD_TESTS( ProductFileReader )
+ADD_TESTS( RepoFileReader )
 
diff --git a/tests/parser/RepoFileReader_test.cc b/tests/parser/RepoFileReader_test.cc
new file mode 100644 (file)
index 0000000..8a5c4e4
--- /dev/null
@@ -0,0 +1,58 @@
+#include <sstream>
+#include <string>
+#include <zypp/parser/RepoFileReader.h>
+
+using std::stringstream;
+using std::string;
+
+static string suse_repo = "[factory-oss]\n"
+"name=factory-oss\n"
+"enabled=1\n"
+"autorefresh=0\n"
+"baseurl=http://download.opensuse.org/factory-tested/repo/oss/\n"
+"type=yast2\n"
+"keeppackages=0\n";
+
+static string fedora_repo = "[fedora]\n"
+"name=Fedora $releasever - $basearch\n"
+"failovermethod=priority\n"
+"#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/\n"
+"#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch\n"
+"mirrorlist=file:///etc/yum.repos.d/local.mirror\n"
+"enabled=1\n"
+"gpgcheck=1\n"
+"gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY\n";
+
+struct RepoCollector : private base::NonCopyable
+{
+  bool collect( const RepoInfo &repo )
+  {
+    repos.push_back(repo);
+    return true;
+  }
+
+  RepoInfoList repos;
+};
+
+// Must be the first test!
+BOOST_AUTO_TEST_CASE(read_repo_file)
+{
+  {
+    stringstream input(suse_repo);
+    RepoCollector collector;
+    parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );
+    BOOST_CHECK_EQUAL(1, collector.repos.size());
+  }
+  // fedora
+  {
+    stringstream input(fedora_repo);
+    RepoCollector collector;
+    parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );
+    BOOST_REQUIRE_EQUAL(1, collector.repos.size());
+
+    RepoInfo repo = *collector.repos.begin();
+    // should have taken the first url if more are present
+    BOOST_CHECK_EQUAL(Url("file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora"), repo.gpgKeyUrl());
+  }
+
+}
index 9e6ae21..eefacc5 100644 (file)
@@ -68,7 +68,12 @@ namespace zypp
           else if ( it->first == "mirrorlist" && !it->second.empty())
             info.setMirrorListUrl(Url(it->second));
           else if ( it->first == "gpgkey" && !it->second.empty())
-            info.setGpgKeyUrl( Url(it->second) );
+          {
+            std::vector<std::string> keys;
+            str::split( it->second, std::back_inserter(keys) );
+            if ( ! keys.empty() ) 
+              info.setGpgKeyUrl( Url(*keys.begin()) );
+          }
           else if ( it->first == "gpgcheck" )
             info.setGpgCheck( str::strToTrue( it->second ) );
          else if ( it->first == "keeppackages" )