1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/**
* @file lluri_tut.cpp
* @brief LLURI unit tests
* @date September 2006
*
* Copyright (c) 2006-2007, Linden Research, Inc.
*
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#include <tut/tut.h>
#include "lltut.h"
#include "llsd.h"
#include "lluri.h"
#include "llhost.h"
namespace tut
{
struct URITestData {
void checkParts(const std::string& uriString,
const char* expectedScheme,
const char* expectedOpaque,
const char* expectedAuthority,
const char* expectedPath,
const char* expectedQuery)
{
LLURI u(uriString);
ensure_equals("scheme", u.scheme(), expectedScheme);
ensure_equals("opaque", u.opaque(), expectedOpaque);
ensure_equals("authority", u.authority(), expectedAuthority);
ensure_equals("path", u.path(), expectedPath);
ensure_equals("query", u.query(), expectedQuery);
}
void checkPartsHTTP(const char* host_and_port,
const LLSD& path,
const char* expectedOpaque,
const char* expectedAuthority,
const char* expectedPath)
{
LLURI u = LLURI::buildHTTP(host_and_port, path);
ensure_equals("scheme", u.scheme(), "HTTP");
ensure_equals("opaque", u.opaque(), expectedOpaque);
ensure_equals("authority", u.authority(), expectedAuthority);
ensure_equals("path", u.path(), expectedPath);
ensure_equals("query", u.query(), "");
}
void checkPartsHTTP(const char* host_and_port,
const LLSD& path,
const LLSD& args,
const char* expectedOpaque,
const char* expectedAuthority,
const char* expectedPath,
const char* expectedQuery)
{
LLURI u = LLURI::buildHTTP(host_and_port, path, args);
ensure_equals("scheme", u.scheme(), "HTTP");
ensure_equals("opaque", u.opaque(), expectedOpaque);
ensure_equals("authority", u.authority(), expectedAuthority);
ensure_equals("path", u.path(), expectedPath);
ensure_equals("query", u.query(), expectedQuery);
}
};
typedef test_group<URITestData> URITestGroup;
typedef URITestGroup::object URITestObject;
URITestGroup uriTestGroup("LLURI");
template<> template<>
void URITestObject::test<1>()
{
LLURI u("http://abc.com/def/ghi?x=37&y=hello");
ensure_equals("scheme", u.scheme(), "http");
ensure_equals("authority", u.authority(), "abc.com");
ensure_equals("path", u.path(), "/def/ghi");
ensure_equals("query", u.query(), "x=37&y=hello");
ensure_equals("host name", u.hostName(), "abc.com");
ensure_equals("host port", u.hostPort(), 80);
LLSD query = u.queryMap();
ensure_equals("query x", query["x"].asInteger(), 37);
ensure_equals("query y", query["y"].asString(), "hello");
query = LLURI::queryMap("x=22.23&y=https://lindenlab.com/");
ensure_equals("query x", query["x"].asReal(), 22.23);
ensure_equals("query y", query["y"].asURI().asString(), "https://lindenlab.com/");
}
template<> template<>
void URITestObject::test<2>()
{
// empty string
checkParts("", "", "", "", "", "");
}
template<> template<>
void URITestObject::test<3>()
{
// no scheme
checkParts("foo", "", "foo", "", "", "");
checkParts("foo%3A", "", "foo:", "", "", "");
}
template<> template<>
void URITestObject::test<4>()
{
// scheme w/o paths
checkParts("mailto:zero@ll.com", "mailto", "zero@ll.com", "", "", "");
checkParts("silly://abc/def?foo", "silly", "//abc/def?foo", "", "", "");
}
template<> template<>
void URITestObject::test<5>()
{
// authority section
checkParts("http:///", "http", "///", "", "/", "");
checkParts("http://abc", "http", "//abc", "abc", "", "");
checkParts("http://a%2Fb/cd", "http", "//a/b/cd", "a/b", "/cd", "");
checkParts("http://host?", "http", "//host?", "host", "", "");
}
template<> template<>
void URITestObject::test<6>()
{
// path section
checkParts("http://host/a/b/", "http", "//host/a/b/",
"host", "/a/b/", "");
checkParts("http://host/a%3Fb/", "http", "//host/a?b/",
"host", "/a?b/", "");
checkParts("http://host/a:b/", "http", "//host/a:b/",
"host", "/a:b/", "");
}
template<> template<>
void URITestObject::test<7>()
{
// query string
checkParts("http://host/?", "http", "//host/?",
"host", "/", "");
checkParts("http://host/?x", "http", "//host/?x",
"host", "/", "x");
checkParts("http://host/??", "http", "//host/??",
"host", "/", "?");
checkParts("http://host/?%3F", "http", "//host/??",
"host", "/", "?");
}
template<> template<>
void URITestObject::test<8>()
{
LLSD path;
path.append("x");
path.append("123");
checkPartsHTTP("host", path, "//host/x/123", "//host", "/x/123");
LLSD query;
query["123"] = "12";
query["abcd"] = "abc";
checkPartsHTTP("host", path, query, "//host/x/123?123=12&abcd=abc&", "//host", "/x/123", "123=12&abcd=abc&");
}
template<> template<>
void URITestObject::test<9>()
{
// test unescaped path components
LLSD path;
path.append("x@*//*$&^");
path.append("123");
checkPartsHTTP("host", path, "//host/x@*//*$&^/123", "//host", "/x@*//*$&^/123");
}
template<> template<>
void URITestObject::test<10>()
{
// test unescaped query components
LLSD path;
path.append("x");
path.append("123");
LLSD query;
query["123"] = "?&*#//";
query["**@&?//"] = "abc";
checkPartsHTTP("host", path, query, "//host/x/123?**@&?//=abc&123=?&*#//&", "//host", "/x/123", "**@&?//=abc&123=?&*#//&");
}
template<> template<>
void URITestObject::test<11>()
{
// test unescaped host components
LLSD path;
path.append("x");
path.append("123");
LLSD query;
query["123"] = "12";
query["abcd"] = "abc";
checkPartsHTTP("hi123*33--}{:portstuffs", path, query, "//hi123*33--}{:portstuffs/x/123?123=12&abcd=abc&", "//hi123*33--}{:portstuffs", "/x/123", "123=12&abcd=abc&");
}
}
|