]> git.saurik.com Git - apt.git/blame - test/libapt/uri_test.cc
show the conflicting distribution warning again
[apt.git] / test / libapt / uri_test.cc
CommitLineData
453b82a3 1#include <config.h>
0ecceb5b
JAK
2#include <apt-pkg/configuration.h>
3#include <apt-pkg/proxy.h>
bf5438c1 4#include <apt-pkg/strutl.h>
453b82a3 5#include <string>
f00832cc 6#include <gtest/gtest.h>
453b82a3 7
f00832cc
DK
8TEST(URITest, BasicHTTP)
9{
10 URI U("http://www.debian.org:90/temp/test");
11 EXPECT_EQ("http", U.Access);
12 EXPECT_EQ("", U.User);
13 EXPECT_EQ("", U.Password);
14 EXPECT_EQ(90, U.Port);
15 EXPECT_EQ("www.debian.org", U.Host);
16 EXPECT_EQ("/temp/test", U.Path);
b8eba208 17 EXPECT_EQ("http://www.debian.org:90/temp/test", (std::string)U);
1da3b7b8
DK
18 EXPECT_EQ("http://www.debian.org:90", URI::SiteOnly(U));
19 EXPECT_EQ("http://www.debian.org:90/temp/test", URI::ArchiveOnly(U));
20 EXPECT_EQ("http://www.debian.org:90/temp/test", URI::NoUserPassword(U));
f00832cc
DK
21 // Login data
22 U = URI("http://jgg:foo@ualberta.ca/blah");
23 EXPECT_EQ("http", U.Access);
24 EXPECT_EQ("jgg", U.User);
25 EXPECT_EQ("foo", U.Password);
26 EXPECT_EQ(0, U.Port);
27 EXPECT_EQ("ualberta.ca", U.Host);
28 EXPECT_EQ("/blah", U.Path);
b8eba208 29 EXPECT_EQ("http://jgg:foo@ualberta.ca/blah", (std::string)U);
1da3b7b8
DK
30 EXPECT_EQ("http://ualberta.ca", URI::SiteOnly(U));
31 EXPECT_EQ("http://ualberta.ca/blah", URI::ArchiveOnly(U));
32 EXPECT_EQ("http://ualberta.ca/blah", URI::NoUserPassword(U));
a1f3ac8a
DK
33 // just a user
34 U = URI("https://apt@example.org/blah");
35 EXPECT_EQ("https", U.Access);
36 EXPECT_EQ("apt", U.User);
37 EXPECT_EQ("", U.Password);
38 EXPECT_EQ(0, U.Port);
39 EXPECT_EQ("example.org", U.Host);
40 EXPECT_EQ("/blah", U.Path);
41 EXPECT_EQ("https://apt@example.org/blah", (std::string)U);
42 EXPECT_EQ("https://example.org", URI::SiteOnly(U));
43 EXPECT_EQ("https://example.org/blah", URI::ArchiveOnly(U));
44 EXPECT_EQ("https://example.org/blah", URI::NoUserPassword(U));
f00832cc
DK
45}
46TEST(URITest, SingeSlashFile)
47{
48 URI U("file:/usr/bin/foo");
49 EXPECT_EQ("file", U.Access);
50 EXPECT_EQ("", U.User);
51 EXPECT_EQ("", U.Password);
52 EXPECT_EQ(0, U.Port);
53 EXPECT_EQ("", U.Host);
54 EXPECT_EQ("/usr/bin/foo", U.Path);
b8eba208 55 EXPECT_EQ("file:/usr/bin/foo", (std::string)U);
1da3b7b8
DK
56 EXPECT_EQ("file:", URI::SiteOnly(U));
57 EXPECT_EQ("file:/usr/bin/foo", URI::ArchiveOnly(U));
58 EXPECT_EQ("file:/usr/bin/foo", URI::NoUserPassword(U));
f00832cc
DK
59}
60TEST(URITest, BasicCDROM)
61{
62 URI U("cdrom:Moo Cow Rom:/debian");
63 EXPECT_EQ("cdrom", U.Access);
64 EXPECT_EQ("", U.User);
65 EXPECT_EQ("", U.Password);
66 EXPECT_EQ(0, U.Port);
67 EXPECT_EQ("Moo Cow Rom", U.Host);
68 EXPECT_EQ("/debian", U.Path);
b8eba208 69 EXPECT_EQ("cdrom://Moo Cow Rom/debian", (std::string)U);
1da3b7b8
DK
70 EXPECT_EQ("cdrom://Moo Cow Rom", URI::SiteOnly(U));
71 EXPECT_EQ("cdrom://Moo Cow Rom/debian", URI::ArchiveOnly(U));
72 EXPECT_EQ("cdrom://Moo Cow Rom/debian", URI::NoUserPassword(U));
f00832cc
DK
73}
74TEST(URITest, RelativeGzip)
75{
76 URI U("gzip:./bar/cow");
77 EXPECT_EQ("gzip", U.Access);
78 EXPECT_EQ("", U.User);
79 EXPECT_EQ("", U.Password);
80 EXPECT_EQ(0, U.Port);
81 EXPECT_EQ(".", U.Host);
82 EXPECT_EQ("/bar/cow", U.Path);
b8eba208 83 EXPECT_EQ("gzip://./bar/cow", (std::string)U);
1da3b7b8
DK
84 EXPECT_EQ("gzip://.", URI::SiteOnly(U));
85 EXPECT_EQ("gzip://./bar/cow", URI::ArchiveOnly(U));
86 EXPECT_EQ("gzip://./bar/cow", URI::NoUserPassword(U));
f00832cc
DK
87}
88TEST(URITest, NoSlashFTP)
89{
90 URI U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
91 EXPECT_EQ("ftp", U.Access);
92 EXPECT_EQ("", U.User);
93 EXPECT_EQ("", U.Password);
94 EXPECT_EQ(0, U.Port);
95 EXPECT_EQ("ftp.fr.debian.org", U.Host);
96 EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path);
b8eba208 97 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", (std::string)U);
1da3b7b8
DK
98 EXPECT_EQ("ftp://ftp.fr.debian.org", URI::SiteOnly(U));
99 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", URI::ArchiveOnly(U));
100 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", URI::NoUserPassword(U));
f00832cc
DK
101}
102TEST(URITest, RFC2732)
103{
104 URI U("http://[1080::8:800:200C:417A]/foo");
105 EXPECT_EQ("http", U.Access);
106 EXPECT_EQ("", U.User);
107 EXPECT_EQ("", U.Password);
108 EXPECT_EQ(0, U.Port);
109 EXPECT_EQ("1080::8:800:200C:417A", U.Host);
110 EXPECT_EQ("/foo", U.Path);
b8eba208 111 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", (std::string)U);
1da3b7b8
DK
112 EXPECT_EQ("http://[1080::8:800:200C:417A]", URI::SiteOnly(U));
113 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", URI::ArchiveOnly(U));
114 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", URI::NoUserPassword(U));
f00832cc
DK
115 // with port
116 U = URI("http://[::FFFF:129.144.52.38]:80/index.html");
117 EXPECT_EQ("http", U.Access);
118 EXPECT_EQ("", U.User);
119 EXPECT_EQ("", U.Password);
120 EXPECT_EQ(80, U.Port);
121 EXPECT_EQ("::FFFF:129.144.52.38", U.Host);
122 EXPECT_EQ("/index.html", U.Path);
b8eba208 123 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", (std::string)U);
1da3b7b8
DK
124 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80", URI::SiteOnly(U));
125 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", URI::ArchiveOnly(U));
126 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", URI::NoUserPassword(U));
f00832cc
DK
127 // extra colon
128 U = URI("http://[::FFFF:129.144.52.38:]:80/index.html");
129 EXPECT_EQ("http", U.Access);
130 EXPECT_EQ("", U.User);
131 EXPECT_EQ("", U.Password);
132 EXPECT_EQ(80, U.Port);
133 EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
134 EXPECT_EQ("/index.html", U.Path);
b8eba208 135 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", (std::string)U);
1da3b7b8
DK
136 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80", URI::SiteOnly(U));
137 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", URI::ArchiveOnly(U));
138 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", URI::NoUserPassword(U));
f00832cc
DK
139 // extra colon port
140 U = URI("http://[::FFFF:129.144.52.38:]/index.html");
141 EXPECT_EQ("http", U.Access);
142 EXPECT_EQ("", U.User);
143 EXPECT_EQ("", U.Password);
144 EXPECT_EQ(0, U.Port);
145 EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
146 EXPECT_EQ("/index.html", U.Path);
b8eba208 147 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", (std::string)U);
1da3b7b8
DK
148 EXPECT_EQ("http://[::FFFF:129.144.52.38:]", URI::SiteOnly(U));
149 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", URI::ArchiveOnly(U));
150 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", URI::NoUserPassword(U));
f00832cc
DK
151 // My Evil Corruption of RFC 2732 to handle CDROM names!
152 // Fun for the whole family! */
153 U = URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
154 EXPECT_EQ("cdrom", U.Access);
155 EXPECT_EQ("", U.User);
156 EXPECT_EQ("", U.Password);
157 EXPECT_EQ(0, U.Port);
158 EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U.Host);
159 EXPECT_EQ("/debian/", U.Path);
b8eba208 160 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", (std::string)U);
1da3b7b8
DK
161 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]", URI::SiteOnly(U));
162 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian", URI::ArchiveOnly(U));
163 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", URI::NoUserPassword(U));
f00832cc
DK
164 // no brackets
165 U = URI("cdrom:Foo Bar Cow/debian/");
166 EXPECT_EQ("cdrom", U.Access);
167 EXPECT_EQ("", U.User);
168 EXPECT_EQ("", U.Password);
169 EXPECT_EQ(0, U.Port);
170 EXPECT_EQ("Foo Bar Cow", U.Host);
171 EXPECT_EQ("/debian/", U.Path);
b8eba208 172 EXPECT_EQ("cdrom://Foo Bar Cow/debian/", (std::string)U);
1da3b7b8
DK
173 EXPECT_EQ("cdrom://Foo Bar Cow", URI::SiteOnly(U));
174 EXPECT_EQ("cdrom://Foo Bar Cow/debian", URI::ArchiveOnly(U));
175 EXPECT_EQ("cdrom://Foo Bar Cow/debian/", URI::NoUserPassword(U));
28b2efcb 176 // percent encoded password
f00832cc
DK
177 U = URI("ftp://foo:b%40r@example.org");
178 EXPECT_EQ("foo", U.User);
179 EXPECT_EQ("b@r", U.Password);
180 EXPECT_EQ("ftp://foo:b%40r@example.org/", (std::string) U);
1da3b7b8
DK
181 EXPECT_EQ("ftp://example.org", URI::SiteOnly(U));
182 EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U));
183 EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U));
28b2efcb
DK
184 // percent encoded user
185 U = URI("ftp://f%40o:bar@example.org");
186 EXPECT_EQ("f@o", U.User);
187 EXPECT_EQ("bar", U.Password);
188 EXPECT_EQ("ftp://f%40o:bar@example.org/", (std::string) U);
189 EXPECT_EQ("ftp://example.org", URI::SiteOnly(U));
190 EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U));
191 EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U));
bf5438c1 192}
0ecceb5b
JAK
193TEST(URITest, AutoProxyTest)
194{
195 URI u0("http://www.debian.org:90/temp/test");
196 URI u1("http://www.debian.org:91/temp/test");
197
198 _config->Set("Acquire::http::Proxy-Auto-Detect", "./apt-proxy-script");
199
200 // Scenario 0: Autodetecting a simple proxy
201 AutoDetectProxy(u0);
202 EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com");
203
204 // Scenario 1: Proxy stays the same if it is already set
205 AutoDetectProxy(u1);
206 EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com");
207
208 // Scenario 2: Reading with stderr output works fine
209 _config->Clear("Acquire::http::proxy::www.debian.org");
210 AutoDetectProxy(u1);
211 EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com/foo");
212
213 // Scenario 1 again: Proxy stays the same if it is already set
214 AutoDetectProxy(u0);
215 EXPECT_EQ(_config->Find("Acquire::http::proxy::www.debian.org", ""), "http://example.com/foo");
216}