]> git.saurik.com Git - apt.git/blobdiff - test/libapt/uri_test.cc
For ReMap to work, S has to be marked volatile :/.
[apt.git] / test / libapt / uri_test.cc
index fe6015e65c0322eb0b3b35c91fc15d111acaba7a..09d0180493429547548f1841d752c63b167b2ace 100644 (file)
@@ -1,4 +1,6 @@
 #include <config.h>
 #include <config.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/proxy.h>
 #include <apt-pkg/strutl.h>
 #include <string>
 #include <gtest/gtest.h>
 #include <apt-pkg/strutl.h>
 #include <string>
 #include <gtest/gtest.h>
@@ -28,6 +30,18 @@ TEST(URITest, BasicHTTP)
    EXPECT_EQ("http://ualberta.ca", URI::SiteOnly(U));
    EXPECT_EQ("http://ualberta.ca/blah", URI::ArchiveOnly(U));
    EXPECT_EQ("http://ualberta.ca/blah", URI::NoUserPassword(U));
    EXPECT_EQ("http://ualberta.ca", URI::SiteOnly(U));
    EXPECT_EQ("http://ualberta.ca/blah", URI::ArchiveOnly(U));
    EXPECT_EQ("http://ualberta.ca/blah", URI::NoUserPassword(U));
+   // just a user
+   U = URI("https://apt@example.org/blah");
+   EXPECT_EQ("https", U.Access);
+   EXPECT_EQ("apt", U.User);
+   EXPECT_EQ("", U.Password);
+   EXPECT_EQ(0, U.Port);
+   EXPECT_EQ("example.org", U.Host);
+   EXPECT_EQ("/blah", U.Path);
+   EXPECT_EQ("https://apt@example.org/blah", (std::string)U);
+   EXPECT_EQ("https://example.org", URI::SiteOnly(U));
+   EXPECT_EQ("https://example.org/blah", URI::ArchiveOnly(U));
+   EXPECT_EQ("https://example.org/blah", URI::NoUserPassword(U));
 }
 TEST(URITest, SingeSlashFile)
 {
 }
 TEST(URITest, SingeSlashFile)
 {
@@ -159,7 +173,7 @@ TEST(URITest, RFC2732)
    EXPECT_EQ("cdrom://Foo Bar Cow", URI::SiteOnly(U));
    EXPECT_EQ("cdrom://Foo Bar Cow/debian", URI::ArchiveOnly(U));
    EXPECT_EQ("cdrom://Foo Bar Cow/debian/", URI::NoUserPassword(U));
    EXPECT_EQ("cdrom://Foo Bar Cow", URI::SiteOnly(U));
    EXPECT_EQ("cdrom://Foo Bar Cow/debian", URI::ArchiveOnly(U));
    EXPECT_EQ("cdrom://Foo Bar Cow/debian/", URI::NoUserPassword(U));
-   // percent encoded
+   // percent encoded password
    U = URI("ftp://foo:b%40r@example.org");
    EXPECT_EQ("foo", U.User);
    EXPECT_EQ("b@r", U.Password);
    U = URI("ftp://foo:b%40r@example.org");
    EXPECT_EQ("foo", U.User);
    EXPECT_EQ("b@r", U.Password);
@@ -167,4 +181,36 @@ TEST(URITest, RFC2732)
    EXPECT_EQ("ftp://example.org", URI::SiteOnly(U));
    EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U));
    EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U));
    EXPECT_EQ("ftp://example.org", URI::SiteOnly(U));
    EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U));
    EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U));
+   // percent encoded user
+   U = URI("ftp://f%40o:bar@example.org");
+   EXPECT_EQ("f@o", U.User);
+   EXPECT_EQ("bar", U.Password);
+   EXPECT_EQ("ftp://f%40o:bar@example.org/", (std::string) U);
+   EXPECT_EQ("ftp://example.org", URI::SiteOnly(U));
+   EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U));
+   EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U));
+}
+TEST(URITest, AutoProxyTest)
+{
+   URI u0("http://www.debian.org:90/temp/test");
+   URI u1("http://www.debian.org:91/temp/test");
+
+   _config->Set("Acquire::http::Proxy-Auto-Detect", "./apt-proxy-script");
+
+   // Scenario 0: Autodetecting a simple proxy
+   AutoDetectProxy(u0);
+   EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com");
+
+   // Scenario 1: Proxy stays the same if it is already set
+   AutoDetectProxy(u1);
+   EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com");
+
+   // Scenario 2: Reading with stderr output works fine
+   _config->Clear("Acquire::http::proxy::www.debian.org");
+   AutoDetectProxy(u1);
+   EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com/foo");
+
+   // Scenario 1 again: Proxy stays the same if it is already set
+   AutoDetectProxy(u0);
+   EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com/foo");
 }
 }