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