0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <QtCore/QUrl>
|
|
45 |
#include <QtNetwork/QNetworkCookie>
|
|
46 |
|
|
47 |
|
|
48 |
class tst_QNetworkCookie: public QObject
|
|
49 |
{
|
|
50 |
Q_OBJECT
|
|
51 |
|
|
52 |
private slots:
|
|
53 |
void getterSetter();
|
|
54 |
|
|
55 |
void parseSingleCookie_data();
|
|
56 |
void parseSingleCookie();
|
|
57 |
|
|
58 |
void parseMultipleCookies_data();
|
|
59 |
void parseMultipleCookies();
|
|
60 |
};
|
|
61 |
|
|
62 |
QT_BEGIN_NAMESPACE
|
|
63 |
|
|
64 |
namespace QTest {
|
|
65 |
template<>
|
|
66 |
char *toString(const QNetworkCookie &cookie)
|
|
67 |
{
|
|
68 |
return qstrdup(cookie.toRawForm());
|
|
69 |
}
|
|
70 |
|
|
71 |
template<>
|
|
72 |
char *toString(const QList<QNetworkCookie> &list)
|
|
73 |
{
|
|
74 |
QString result = "QList(";
|
|
75 |
bool first = true;
|
|
76 |
foreach (QNetworkCookie cookie, list) {
|
|
77 |
if (!first)
|
|
78 |
result += ", ";
|
|
79 |
first = false;
|
|
80 |
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm()));
|
|
81 |
}
|
|
82 |
|
|
83 |
return qstrdup(result.append(')').toLocal8Bit());
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
QT_END_NAMESPACE
|
|
88 |
|
|
89 |
void tst_QNetworkCookie::getterSetter()
|
|
90 |
{
|
|
91 |
QNetworkCookie cookie;
|
|
92 |
QNetworkCookie otherCookie;
|
|
93 |
|
|
94 |
QVERIFY(cookie == otherCookie);
|
|
95 |
QCOMPARE(cookie, otherCookie);
|
|
96 |
QVERIFY(!(cookie != otherCookie));
|
|
97 |
|
|
98 |
QVERIFY(!cookie.isSecure());
|
|
99 |
QVERIFY(cookie.isSessionCookie());
|
|
100 |
QVERIFY(!cookie.expirationDate().isValid());
|
|
101 |
QVERIFY(cookie.domain().isEmpty());
|
|
102 |
QVERIFY(cookie.path().isEmpty());
|
|
103 |
QVERIFY(cookie.name().isEmpty());
|
|
104 |
QVERIFY(cookie.value().isEmpty());
|
|
105 |
|
|
106 |
// change something
|
|
107 |
cookie.setName("foo");
|
|
108 |
QVERIFY(!(cookie == otherCookie));
|
|
109 |
QVERIFY(cookie != otherCookie);
|
|
110 |
|
|
111 |
// test getters and setters:
|
|
112 |
QCOMPARE(cookie.name(), QByteArray("foo"));
|
|
113 |
cookie.setName(0);
|
|
114 |
QVERIFY(cookie.name().isEmpty());
|
|
115 |
|
|
116 |
cookie.setValue("bar");
|
|
117 |
QCOMPARE(cookie.value(), QByteArray("bar"));
|
|
118 |
cookie.setValue(0);
|
|
119 |
QVERIFY(cookie.value().isEmpty());
|
|
120 |
|
|
121 |
cookie.setPath("/");
|
|
122 |
QCOMPARE(cookie.path(), QString("/"));
|
|
123 |
cookie.setPath(QString());
|
|
124 |
QVERIFY(cookie.path().isEmpty());
|
|
125 |
|
|
126 |
cookie.setDomain(".tld");
|
|
127 |
QCOMPARE(cookie.domain(), QString(".tld"));
|
|
128 |
cookie.setDomain(QString());
|
|
129 |
QVERIFY(cookie.domain().isEmpty());
|
|
130 |
|
|
131 |
QDateTime now = QDateTime::currentDateTime();
|
|
132 |
cookie.setExpirationDate(now);
|
|
133 |
QCOMPARE(cookie.expirationDate(), now);
|
|
134 |
QVERIFY(!cookie.isSessionCookie());
|
|
135 |
cookie.setExpirationDate(QDateTime());
|
|
136 |
QVERIFY(!cookie.expirationDate().isValid());
|
|
137 |
QVERIFY(cookie.isSessionCookie());
|
|
138 |
|
|
139 |
cookie.setSecure(true);
|
|
140 |
QVERIFY(cookie.isSecure());
|
|
141 |
cookie.setSecure(false);
|
|
142 |
QVERIFY(!cookie.isSecure());
|
|
143 |
|
|
144 |
QVERIFY(cookie == otherCookie);
|
|
145 |
}
|
|
146 |
|
|
147 |
void tst_QNetworkCookie::parseSingleCookie_data()
|
|
148 |
{
|
|
149 |
QTest::addColumn<QString>("cookieString");
|
|
150 |
QTest::addColumn<QNetworkCookie>("expectedCookie");
|
|
151 |
|
|
152 |
QNetworkCookie cookie;
|
|
153 |
cookie.setName("a");
|
|
154 |
QTest::newRow("basic") << "a=" << cookie;
|
|
155 |
QTest::newRow("basic2") << " a=" << cookie;
|
|
156 |
QTest::newRow("basic3") << "a= " << cookie;
|
|
157 |
QTest::newRow("basic4") << " a= " << cookie;
|
|
158 |
QTest::newRow("basic5") << " a= ;" << cookie;
|
|
159 |
QTest::newRow("basic6") << " a=; " << cookie;
|
|
160 |
QTest::newRow("basic7") << " a =" << cookie;
|
|
161 |
QTest::newRow("basic8") << " a = " << cookie;
|
|
162 |
|
|
163 |
cookie.setValue("b");
|
|
164 |
QTest::newRow("with-value") << "a=b" << cookie;
|
|
165 |
QTest::newRow("with-value2") << " a=b" << cookie;
|
|
166 |
QTest::newRow("with-value3") << "a=b " << cookie;
|
|
167 |
QTest::newRow("with-value4") << " a=b " << cookie;
|
|
168 |
QTest::newRow("with-value4") << " a=b ;" << cookie;
|
|
169 |
QTest::newRow("with-value5") << "a =b" << cookie;
|
|
170 |
QTest::newRow("with-value6") << "a= b" << cookie;
|
|
171 |
QTest::newRow("with-value7") << "a = b" << cookie;
|
|
172 |
QTest::newRow("with-value8") << "a = b " << cookie;
|
|
173 |
|
|
174 |
cookie.setValue(",");
|
|
175 |
QTest::newRow("with-value-with-special1") << "a = \",\" " << cookie;
|
|
176 |
cookie.setValue(";");
|
|
177 |
QTest::newRow("with-value-with-special2") << "a = \";\" " << cookie;
|
|
178 |
cookie.setValue(" ");
|
|
179 |
QTest::newRow("with-value-with-special3") << "a = \" \" " << cookie;
|
|
180 |
cookie.setValue("\"");
|
|
181 |
QTest::newRow("with-value-with-special3") << "a = \"\\\"\" " << cookie;
|
|
182 |
cookie.setValue("\"a, b; c\"");
|
|
183 |
QTest::newRow("with-value-with-special4") << "a = \"\\\"a, b; c\\\"\"" << cookie;
|
|
184 |
|
|
185 |
cookie.setValue("b");
|
|
186 |
cookie.setSecure(true);
|
|
187 |
QTest::newRow("secure") << "a=b;secure" << cookie;
|
|
188 |
QTest::newRow("secure2") << "a=b;secure " << cookie;
|
|
189 |
QTest::newRow("secure3") << "a=b; secure" << cookie;
|
|
190 |
QTest::newRow("secure4") << "a=b; secure " << cookie;
|
|
191 |
QTest::newRow("secure5") << "a=b ;secure" << cookie;
|
|
192 |
QTest::newRow("secure6") << "a=b ;secure " << cookie;
|
|
193 |
QTest::newRow("secure7") << "a=b ; secure " << cookie;
|
|
194 |
QTest::newRow("secure8") << "a=b; Secure" << cookie;
|
|
195 |
|
|
196 |
cookie.setSecure(false);
|
|
197 |
cookie.setHttpOnly(true);
|
|
198 |
QTest::newRow("httponly") << "a=b;httponly" << cookie;
|
|
199 |
QTest::newRow("httponly2") << "a=b;HttpOnly " << cookie;
|
|
200 |
QTest::newRow("httponly3") << "a=b; httpOnly" << cookie;
|
|
201 |
QTest::newRow("httponly4") << "a=b; HttpOnly " << cookie;
|
|
202 |
QTest::newRow("httponly5") << "a=b ;HttpOnly" << cookie;
|
|
203 |
QTest::newRow("httponly6") << "a=b ;httponly " << cookie;
|
|
204 |
QTest::newRow("httponly7") << "a=b ; HttpOnly " << cookie;
|
|
205 |
QTest::newRow("httponly8") << "a=b; Httponly" << cookie;
|
|
206 |
|
|
207 |
cookie.setHttpOnly(false);
|
|
208 |
cookie.setPath("/");
|
|
209 |
QTest::newRow("path1") << "a=b;path=/" << cookie;
|
|
210 |
QTest::newRow("path2") << "a=b; path=/" << cookie;
|
|
211 |
QTest::newRow("path3") << "a=b;path=/ " << cookie;
|
|
212 |
QTest::newRow("path4") << "a=b;path =/ " << cookie;
|
|
213 |
QTest::newRow("path5") << "a=b;path= / " << cookie;
|
|
214 |
QTest::newRow("path6") << "a=b;path = / " << cookie;
|
|
215 |
QTest::newRow("path7") << "a=b;Path = / " << cookie;
|
|
216 |
QTest::newRow("path8") << "a=b; PATH = / " << cookie;
|
|
217 |
|
|
218 |
cookie.setPath("/foo");
|
|
219 |
QTest::newRow("path9") << "a=b;path=/foo" << cookie;
|
|
220 |
|
|
221 |
// some weird paths:
|
|
222 |
cookie.setPath("/with spaces");
|
|
223 |
QTest::newRow("path-with-spaces") << "a=b;path=/with%20spaces" << cookie;
|
|
224 |
QTest::newRow("path-with-spaces2") << "a=b; path=/with%20spaces " << cookie;
|
|
225 |
QTest::newRow("path-with-spaces3") << "a=b; path=\"/with spaces\"" << cookie;
|
|
226 |
QTest::newRow("path-with-spaces4") << "a=b; path = \"/with spaces\" " << cookie;
|
|
227 |
|
|
228 |
cookie.setPath("/with\"Quotes");
|
|
229 |
QTest::newRow("path-with-quotes") << "a=b; path = /with%22Quotes" << cookie;
|
|
230 |
QTest::newRow("path-with-quotes2") << "a=b; path = \"/with\\\"Quotes\"" << cookie;
|
|
231 |
|
|
232 |
cookie.setPath(QString::fromUtf8("/R\303\251sum\303\251"));
|
|
233 |
QTest::newRow("path-with-utf8") << "a=b;path=/R\303\251sum\303\251" << cookie;
|
|
234 |
QTest::newRow("path-with-utf8-2") << "a=b;path=/R%C3%A9sum%C3%A9" << cookie;
|
|
235 |
|
|
236 |
cookie.setPath(QString());
|
|
237 |
cookie.setDomain(".qt.nokia.com");
|
|
238 |
QTest::newRow("plain-domain1") << "a=b;domain=qt.nokia.com" << cookie;
|
|
239 |
QTest::newRow("plain-domain2") << "a=b; domain=qt.nokia.com " << cookie;
|
|
240 |
QTest::newRow("plain-domain3") << "a=b;domain=QT.NOKIA.COM" << cookie;
|
|
241 |
QTest::newRow("plain-domain4") << "a=b;DOMAIN = QT.NOKIA.COM" << cookie;
|
|
242 |
|
|
243 |
cookie.setDomain(".qt.nokia.com");
|
|
244 |
QTest::newRow("dot-domain1") << "a=b;domain=.qt.nokia.com" << cookie;
|
|
245 |
QTest::newRow("dot-domain2") << "a=b; domain=.qt.nokia.com" << cookie;
|
|
246 |
QTest::newRow("dot-domain3") << "a=b; domain=.QT.NOKIA.COM" << cookie;
|
|
247 |
QTest::newRow("dot-domain4") << "a=b; Domain = .QT.NOKIA.COM" << cookie;
|
|
248 |
|
|
249 |
cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no"));
|
|
250 |
QTest::newRow("idn-domain1") << "a=b;domain=xn--dgnpent-gxa2o.troll.no" << cookie;
|
|
251 |
QTest::newRow("idn-domain2") << "a=b;domain=d\303\270gn\303\245pent.troll.no" << cookie;
|
|
252 |
QTest::newRow("idn-domain3") << "a=b;domain=XN--DGNPENT-GXA2O.TROLL.NO" << cookie;
|
|
253 |
QTest::newRow("idn-domain4") << "a=b;domain=D\303\230GN\303\205PENT.troll.NO" << cookie;
|
|
254 |
QTest::newRow("idn-domain5") << "a=b;domain = D\303\230GN\303\205PENT.troll.NO" << cookie;
|
|
255 |
|
|
256 |
cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no"));
|
|
257 |
QTest::newRow("dot-idn-domain1") << "a=b;domain=.xn--dgnpent-gxa2o.troll.no" << cookie;
|
|
258 |
QTest::newRow("dot-idn-domain2") << "a=b;domain=.d\303\270gn\303\245pent.troll.no" << cookie;
|
|
259 |
QTest::newRow("dot-idn-domain3") << "a=b;domain=.XN--DGNPENT-GXA2O.TROLL.NO" << cookie;
|
|
260 |
QTest::newRow("dot-idn-domain4") << "a=b;domain=.D\303\230GN\303\205PENT.troll.NO" << cookie;
|
|
261 |
|
|
262 |
cookie.setDomain(".qt.nokia.com");
|
|
263 |
cookie.setPath("/");
|
|
264 |
QTest::newRow("two-fields") << "a=b;domain=qt.nokia.com;path=/" << cookie;
|
|
265 |
QTest::newRow("two-fields2") << "a=b; domain=qt.nokia.com; path=/" << cookie;
|
|
266 |
QTest::newRow("two-fields3") << "a=b; domain=qt.nokia.com ; path=/ " << cookie;
|
|
267 |
QTest::newRow("two-fields4") << "a=b;path=/; domain=qt.nokia.com" << cookie;
|
|
268 |
QTest::newRow("two-fields5") << "a=b; path=/ ; domain=qt.nokia.com" << cookie;
|
|
269 |
QTest::newRow("two-fields6") << "a=b; path= / ; domain =qt.nokia.com" << cookie;
|
|
270 |
|
|
271 |
cookie.setSecure(true);
|
|
272 |
QTest::newRow("three-fields") << "a=b;domain=qt.nokia.com;path=/;secure" << cookie;
|
|
273 |
QTest::newRow("three-fields2") << "a=b;secure;path=/;domain=qt.nokia.com" << cookie;
|
|
274 |
QTest::newRow("three-fields3") << "a=b;secure;domain=qt.nokia.com; path=/" << cookie;
|
|
275 |
QTest::newRow("three-fields4") << "a = b;secure;domain=qt.nokia.com; path=/" << cookie;
|
|
276 |
|
|
277 |
cookie = QNetworkCookie();
|
|
278 |
cookie.setName("a");
|
|
279 |
cookie.setValue("b");
|
|
280 |
cookie.setExpirationDate(QDateTime(QDate(2012, 1, 29), QTime(23, 59, 59), Qt::UTC));
|
|
281 |
QTest::newRow("broken-expiration1") << "a=b; expires=Sun, 29-Jan-2012 23:59:59;" << cookie;
|
|
282 |
|
|
283 |
cookie.setExpirationDate(QDateTime(QDate(1999, 11, 9), QTime(23, 12, 40), Qt::UTC));
|
|
284 |
QTest::newRow("expiration1") << "a=b;expires=Wednesday, 09-Nov-1999 23:12:40 GMT" << cookie;
|
|
285 |
QTest::newRow("expiration2") << "a=b;expires=Wed, 09-Nov-1999 23:12:40 GMT" << cookie;
|
|
286 |
QTest::newRow("expiration3") << "a=b; expires=Wednesday, 09-Nov-1999 23:12:40 GMT " << cookie;
|
|
287 |
QTest::newRow("expiration-utc") << "a=b;expires=Wednesday, 09-Nov-1999 23:12:40 UTC" << cookie;
|
|
288 |
|
|
289 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 0, 0), Qt::UTC));
|
|
290 |
QTest::newRow("time-0") << "a=b;expires=14 Apr 89 03:20" << cookie;
|
|
291 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 0), Qt::UTC));
|
|
292 |
QTest::newRow("time-1") << "a=b;expires=14 Apr 89 03:20:12" << cookie;
|
|
293 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 88), Qt::UTC));
|
|
294 |
QTest::newRow("time-2") << "a=b;expires=14 Apr 89 03:20:12.88" << cookie;
|
|
295 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 88), Qt::UTC));
|
|
296 |
QTest::newRow("time-3") << "a=b;expires=14 Apr 89 03:20:12.88am" << cookie;
|
|
297 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(15, 20, 12, 88), Qt::UTC));
|
|
298 |
QTest::newRow("time-4") << "a=b;expires=14 Apr 89 03:20:12.88pm" << cookie;
|
|
299 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 88), Qt::UTC));
|
|
300 |
QTest::newRow("time-5") << "a=b;expires=14 Apr 89 03:20:12.88 Am" << cookie;
|
|
301 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(15, 20, 12, 88), Qt::UTC));
|
|
302 |
QTest::newRow("time-6") << "a=b;expires=14 Apr 89 03:20:12.88 PM" << cookie;
|
|
303 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(15, 20, 12, 88), Qt::UTC));
|
|
304 |
QTest::newRow("time-7") << "a=b;expires=14 Apr 89 3:20:12.88 PM" << cookie;
|
|
305 |
|
|
306 |
// normal months
|
|
307 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 1), Qt::UTC));
|
|
308 |
QTest::newRow("months-1") << "a=b;expires=Jan 1 89 1:1" << cookie;
|
|
309 |
cookie.setExpirationDate(QDateTime(QDate(1989, 2, 1), QTime(1, 1), Qt::UTC));
|
|
310 |
QTest::newRow("months-2") << "a=b;expires=Feb 1 89 1:1" << cookie;
|
|
311 |
cookie.setExpirationDate(QDateTime(QDate(1989, 3, 1), QTime(1, 1), Qt::UTC));
|
|
312 |
QTest::newRow("months-3") << "a=b;expires=mar 1 89 1:1" << cookie;
|
|
313 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 1), QTime(1, 1), Qt::UTC));
|
|
314 |
QTest::newRow("months-4") << "a=b;expires=Apr 1 89 1:1" << cookie;
|
|
315 |
cookie.setExpirationDate(QDateTime(QDate(1989, 5, 1), QTime(1, 1), Qt::UTC));
|
|
316 |
QTest::newRow("months-5") << "a=b;expires=May 1 89 1:1" << cookie;
|
|
317 |
cookie.setExpirationDate(QDateTime(QDate(1989, 6, 1), QTime(1, 1), Qt::UTC));
|
|
318 |
QTest::newRow("months-6") << "a=b;expires=Jun 1 89 1:1" << cookie;
|
|
319 |
cookie.setExpirationDate(QDateTime(QDate(1989, 7, 1), QTime(1, 1), Qt::UTC));
|
|
320 |
QTest::newRow("months-7") << "a=b;expires=Jul 1 89 1:1" << cookie;
|
|
321 |
cookie.setExpirationDate(QDateTime(QDate(1989, 8, 1), QTime(1, 1), Qt::UTC));
|
|
322 |
QTest::newRow("months-8") << "a=b;expires=Aug 1 89 1:1" << cookie;
|
|
323 |
cookie.setExpirationDate(QDateTime(QDate(1989, 9, 1), QTime(1, 1), Qt::UTC));
|
|
324 |
QTest::newRow("months-9") << "a=b;expires=Sep 1 89 1:1" << cookie;
|
|
325 |
cookie.setExpirationDate(QDateTime(QDate(1989, 10, 1), QTime(1, 1), Qt::UTC));
|
|
326 |
QTest::newRow("months-10") << "a=b;expires=Oct 1 89 1:1" << cookie;
|
|
327 |
cookie.setExpirationDate(QDateTime(QDate(1989, 11, 1), QTime(1, 1), Qt::UTC));
|
|
328 |
QTest::newRow("months-11") << "a=b;expires=Nov 1 89 1:1" << cookie;
|
|
329 |
cookie.setExpirationDate(QDateTime(QDate(1989, 12, 1), QTime(1, 1), Qt::UTC));
|
|
330 |
QTest::newRow("months-12") << "a=b;expires=Dec 1 89 1:1" << cookie;
|
|
331 |
|
|
332 |
// extra months
|
|
333 |
cookie.setExpirationDate(QDateTime(QDate(1989, 12, 1), QTime(1, 1), Qt::UTC));
|
|
334 |
QTest::newRow("months-13") << "a=b;expires=December 1 89 1:1" << cookie;
|
|
335 |
QTest::newRow("months-14") << "a=b;expires=1 89 1:1 Dec" << cookie;
|
|
336 |
//cookie.setExpirationDate(QDateTime());
|
|
337 |
//QTest::newRow("months-15") << "a=b;expires=1 89 1:1 De" << cookie;
|
|
338 |
cookie.setExpirationDate(QDateTime(QDate(2024, 2, 29), QTime(1, 1), Qt::UTC));
|
|
339 |
QTest::newRow("months-16") << "a=b;expires=2024 29 Feb 1:1" << cookie;
|
|
340 |
cookie.setExpirationDate(QDateTime(QDate(2024, 2, 29), QTime(1, 1), Qt::UTC));
|
|
341 |
QTest::newRow("months-17") << "a=b;expires=Fri, 29-Feb-2024 01:01:00 GMT" << cookie;
|
|
342 |
QTest::newRow("months-18") << "a=b;expires=2024 29 Feb 1:1 GMT" << cookie;
|
|
343 |
|
|
344 |
// normal offsets
|
|
345 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
346 |
QTest::newRow("zoneoffset-0") << "a=b;expires=Jan 1 89 8:0 PST" << cookie;
|
|
347 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
348 |
QTest::newRow("zoneoffset-1") << "a=b;expires=Jan 1 89 8:0 PDT" << cookie;
|
|
349 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
350 |
QTest::newRow("zoneoffset-2") << "a=b;expires=Jan 1 89 7:0 MST" << cookie;
|
|
351 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
352 |
QTest::newRow("zoneoffset-3") << "a=b;expires=Jan 1 89 7:0 MDT" << cookie;
|
|
353 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
354 |
QTest::newRow("zoneoffset-4") << "a=b;expires=Jan 1 89 6:0 CST" << cookie;
|
|
355 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
356 |
QTest::newRow("zoneoffset-5") << "a=b;expires=Jan 1 89 6:0 CDT" << cookie;
|
|
357 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
358 |
QTest::newRow("zoneoffset-6") << "a=b;expires=Jan 1 89 5:0 EST" << cookie;
|
|
359 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
360 |
QTest::newRow("zoneoffset-7") << "a=b;expires=Jan 1 89 5:0 EDT" << cookie;
|
|
361 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
362 |
QTest::newRow("zoneoffset-8") << "a=b;expires=Jan 1 89 4:0 AST" << cookie;
|
|
363 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
364 |
QTest::newRow("zoneoffset-9") << "a=b;expires=Jan 1 89 3:0 NST" << cookie;
|
|
365 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
366 |
QTest::newRow("zoneoffset-10") << "a=b;expires=Jan 1 89 0:0 GMT" << cookie;
|
|
367 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
368 |
QTest::newRow("zoneoffset-11") << "a=b;expires=Jan 1 89 0:0 BST" << cookie;
|
|
369 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC));
|
|
370 |
QTest::newRow("zoneoffset-12") << "a=b;expires=Jan 1 89 23:0 MET" << cookie;
|
|
371 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC));
|
|
372 |
QTest::newRow("zoneoffset-13") << "a=b;expires=Jan 1 89 22:0 EET" << cookie;
|
|
373 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC));
|
|
374 |
QTest::newRow("zoneoffset-14") << "a=b;expires=Jan 1 89 15:0 JST" << cookie;
|
|
375 |
|
|
376 |
// extra offsets
|
|
377 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC));
|
|
378 |
QTest::newRow("zoneoffset-14") << "a=b;expires=Jan 1 89 15:0 JST+1" << cookie;
|
|
379 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC));
|
|
380 |
QTest::newRow("zoneoffset-15") << "a=b;expires=Jan 1 89 0:0 GMT+1" << cookie;
|
|
381 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
382 |
QTest::newRow("zoneoffset-15b") << "a=b;expires=Jan 1 89 1:0 GMT-1" << cookie;
|
|
383 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC));
|
|
384 |
QTest::newRow("zoneoffset-16") << "a=b;expires=Jan 1 89 0:0 GMT+01" << cookie;
|
|
385 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 5), Qt::UTC));
|
|
386 |
QTest::newRow("zoneoffset-17") << "a=b;expires=Jan 1 89 0:0 GMT+0105" << cookie;
|
|
387 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
388 |
QTest::newRow("zoneoffset-18") << "a=b;expires=Jan 1 89 0:0 GMT+015" << cookie;
|
|
389 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
390 |
QTest::newRow("zoneoffset-19") << "a=b;expires=Jan 1 89 0:0 GM" << cookie;
|
|
391 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
392 |
QTest::newRow("zoneoffset-19b") << "a=b;expires=Jan 1 89 0:0 GMT" << cookie;
|
|
393 |
|
|
394 |
// offsets from gmt
|
|
395 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC));
|
|
396 |
QTest::newRow("zoneoffset-20") << "a=b;expires=Jan 1 89 0:0 +1" << cookie;
|
|
397 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC));
|
|
398 |
QTest::newRow("zoneoffset-21") << "a=b;expires=Jan 1 89 0:0 +01" << cookie;
|
|
399 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 1), Qt::UTC));
|
|
400 |
QTest::newRow("zoneoffset-22") << "a=b;expires=Jan 1 89 0:0 +0101" << cookie;
|
|
401 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC));
|
|
402 |
QTest::newRow("zoneoffset-23") << "a=b;expires=Jan 1 89 1:0 -1" << cookie;
|
|
403 |
|
|
404 |
// Y2k
|
|
405 |
cookie.setExpirationDate(QDateTime(QDate(2000, 1, 1), QTime(0, 0), Qt::UTC));
|
|
406 |
QTest::newRow("year-0") << "a=b;expires=Jan 1 00 0:0" << cookie;
|
|
407 |
cookie.setExpirationDate(QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC));
|
|
408 |
QTest::newRow("year-1") << "a=b;expires=Jan 1 70 0:0" << cookie;
|
|
409 |
cookie.setExpirationDate(QDateTime(QDate(1971, 1, 1), QTime(0, 0), Qt::UTC));
|
|
410 |
QTest::newRow("year-2") << "a=b;expires=Jan 1 71 0:0" << cookie;
|
|
411 |
|
|
412 |
// Day, month, year
|
|
413 |
cookie.setExpirationDate(QDateTime(QDate(2013, 1, 2), QTime(0, 0), Qt::UTC));
|
|
414 |
QTest::newRow("date-0") << "a=b;expires=Jan 2 13 0:0" << cookie;
|
|
415 |
QTest::newRow("date-1") << "a=b;expires=1-2-13 0:0" << cookie;
|
|
416 |
QTest::newRow("date-2") << "a=b;expires=1/2/13 0:0" << cookie;
|
|
417 |
QTest::newRow("date-3") << "a=b;expires=Jan 2 13 0:0" << cookie;
|
|
418 |
QTest::newRow("date-4") << "a=b;expires=Jan 2, 13 0:0" << cookie;
|
|
419 |
QTest::newRow("date-5") << "a=b;expires=1-2-13 0:0" << cookie;
|
|
420 |
QTest::newRow("date-6") << "a=b;expires=1/2/13 0:0" << cookie;
|
|
421 |
|
|
422 |
// Known Year, determine month and day
|
|
423 |
cookie.setExpirationDate(QDateTime(QDate(1995, 1, 13), QTime(0, 0), Qt::UTC));
|
|
424 |
QTest::newRow("knownyear-0") << "a=b;expires=13/1/95 0:0" << cookie;
|
|
425 |
QTest::newRow("knownyear-1") << "a=b;expires=95/13/1 0:0" << cookie;
|
|
426 |
QTest::newRow("knownyear-2") << "a=b;expires=1995/1/13 0:0" << cookie;
|
|
427 |
QTest::newRow("knownyear-3") << "a=b;expires=1995/13/1 0:0" << cookie;
|
|
428 |
cookie.setExpirationDate(QDateTime(QDate(1995, 1, 2), QTime(0, 0), Qt::UTC));
|
|
429 |
QTest::newRow("knownyear-4") << "a=b;expires=1/2/95 0:0" << cookie;
|
|
430 |
QTest::newRow("knownyear-5") << "a=b;expires=95/1/2 0:0" << cookie;
|
|
431 |
|
|
432 |
// Known Year, Known day, determining month
|
|
433 |
cookie.setExpirationDate(QDateTime(QDate(1995, 1, 13), QTime(0, 0), Qt::UTC));
|
|
434 |
QTest::newRow("knownYD-0") << "a=b;expires=13/1/95 0:0" << cookie;
|
|
435 |
QTest::newRow("knownYD-1") << "a=b;expires=1/13/95 0:0" << cookie;
|
|
436 |
QTest::newRow("knownYD-2") << "a=b;expires=95/13/1 0:0" << cookie;
|
|
437 |
QTest::newRow("knownYD-3") << "a=b;expires=95/1/13 0:0" << cookie;
|
|
438 |
|
|
439 |
// Month comes before Year
|
|
440 |
cookie.setExpirationDate(QDateTime(QDate(2021, 03, 26), QTime(0, 0), Qt::UTC));
|
|
441 |
QTest::newRow("month-0") << "a=b;expires=26/03/21 0:0" << cookie;
|
|
442 |
cookie.setExpirationDate(QDateTime(QDate(2015, 12, 30), QTime(16, 25, 0, 0), Qt::UTC));
|
|
443 |
QTest::newRow("month-1") << "a=b;expires=wed 16:25pm December 2015 30" << cookie;
|
|
444 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 11), QTime(16, 25, 0, 0), Qt::UTC));
|
|
445 |
QTest::newRow("month-2") << "a=b;expires=16:25 11 31 11" << cookie;
|
|
446 |
|
|
447 |
// The very ambiguous cases
|
|
448 |
// Matching Firefox's behavior of guessing month, day, year in those cases
|
|
449 |
cookie.setExpirationDate(QDateTime(QDate(2013, 10, 2), QTime(0, 0), Qt::UTC));
|
|
450 |
QTest::newRow("ambiguousd-0") << "a=b;expires=10/2/13 0:0" << cookie;
|
|
451 |
cookie.setExpirationDate(QDateTime(QDate(2013, 2, 10), QTime(0, 0), Qt::UTC));
|
|
452 |
QTest::newRow("ambiguousd-1") << "a=b;expires=2/10/13 0:0" << cookie;
|
|
453 |
cookie.setExpirationDate(QDateTime(QDate(2010, 2, 3), QTime(0, 0), Qt::UTC));
|
|
454 |
QTest::newRow("ambiguousd-2") << "a=b;expires=2/3/10 0:0" << cookie;
|
|
455 |
|
|
456 |
// FYI If you try these in Firefox it wont set a cookie for the following two string
|
|
457 |
// because 03 is turned into the year at which point it is expired
|
|
458 |
cookie.setExpirationDate(QDateTime(QDate(2003, 2, 10), QTime(0, 0), Qt::UTC));
|
|
459 |
QTest::newRow("ambiguousd-3") << "a=b;expires=2/10/3 0:0" << cookie;
|
|
460 |
cookie.setExpirationDate(QDateTime(QDate(2003, 10, 2), QTime(0, 0), Qt::UTC));
|
|
461 |
QTest::newRow("ambiguousd-4") << "a=b;expires=10/2/3 0:0" << cookie;
|
|
462 |
|
|
463 |
// These are the cookies that firefox's source says it can parse
|
|
464 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 0, 0), Qt::UTC));
|
|
465 |
QTest::newRow("firefox-0") << "a=b;expires=14 Apr 89 03:20" << cookie;
|
|
466 |
|
|
467 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 0, 0), Qt::UTC));
|
|
468 |
QTest::newRow("firefox-1") << "a=b;expires=14 Apr 89 03:20 GMT" << cookie;
|
|
469 |
|
|
470 |
cookie.setExpirationDate(QDateTime(QDate(1989, 3, 17), QTime(4, 1, 33, 0), Qt::UTC));
|
|
471 |
QTest::newRow("firefox-2") << "a=b;expires=Fri, 17 Mar 89 4:01:33" << cookie;
|
|
472 |
|
|
473 |
cookie.setExpirationDate(QDateTime(QDate(1989, 3, 17), QTime(4, 1, 0, 0), Qt::UTC));
|
|
474 |
QTest::newRow("firefox-3") << "a=b;expires=Fri, 17 Mar 89 4:01 GMT" << cookie;
|
|
475 |
|
|
476 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 16), QTime(16-8, 12, 0, 0), Qt::UTC));
|
|
477 |
QTest::newRow("firefox-4") << "a=b;expires=Mon Jan 16 16:12 PDT 1989" << cookie;
|
|
478 |
|
|
479 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 16), QTime(17, 42, 0, 0), Qt::UTC));
|
|
480 |
QTest::newRow("firefox-5") << "a=b;expires=Mon Jan 16 16:12 +0130 1989" << cookie;
|
|
481 |
|
|
482 |
cookie.setExpirationDate(QDateTime(QDate(1992, 5, 6), QTime(16-9, 41, 0, 0), Qt::UTC));
|
|
483 |
QTest::newRow("firefox-6") << "a=b;expires=6 May 1992 16:41-JST (Wednesday)" << cookie;
|
|
484 |
|
|
485 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(10, 59, 12, 82), Qt::UTC));
|
|
486 |
QTest::newRow("firefox-7") << "a=b;expires=22-AUG-1993 10:59:12.82" << cookie;
|
|
487 |
|
|
488 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(22, 59, 0, 0), Qt::UTC));
|
|
489 |
QTest::newRow("firefox-8") << "a=b;expires=22-AUG-1993 10:59pm" << cookie;
|
|
490 |
|
|
491 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(12, 59, 0, 0), Qt::UTC));
|
|
492 |
QTest::newRow("firefox-9") << "a=b;expires=22-AUG-1993 12:59am" << cookie;
|
|
493 |
|
|
494 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(12, 59, 0, 0), Qt::UTC));
|
|
495 |
QTest::newRow("firefox-10") << "a=b;expires=22-AUG-1993 12:59 PM" << cookie;
|
|
496 |
|
|
497 |
cookie.setExpirationDate(QDateTime(QDate(1995, 8, 4), QTime(15, 54, 0, 0), Qt::UTC));
|
|
498 |
QTest::newRow("firefox-11") << "a=b;expires=Friday, August 04, 1995 3:54 PM" << cookie;
|
|
499 |
|
|
500 |
cookie.setExpirationDate(QDateTime(QDate(1995, 6, 21), QTime(16, 24, 34, 0), Qt::UTC));
|
|
501 |
QTest::newRow("firefox-12") << "a=b;expires=06/21/95 04:24:34 PM" << cookie;
|
|
502 |
|
|
503 |
cookie.setExpirationDate(QDateTime(QDate(1995, 6, 20), QTime(21, 7, 0, 0), Qt::UTC));
|
|
504 |
QTest::newRow("firefox-13") << "a=b;expires=20/06/95 21:07" << cookie;
|
|
505 |
|
|
506 |
cookie.setExpirationDate(QDateTime(QDate(1995, 6, 8), QTime(19-5, 32, 48, 0), Qt::UTC));
|
|
507 |
QTest::newRow("firefox-14") << "a=b;expires=95-06-08 19:32:48 EDT" << cookie;
|
|
508 |
|
|
509 |
// Edge cases caught by fuzzing
|
|
510 |
// These are about the default cause creates dates that don't exits
|
|
511 |
cookie.setExpirationDate(QDateTime(QDate(2030, 2, 25), QTime(1, 1, 0, 0), Qt::UTC));
|
|
512 |
QTest::newRow("fuzz-0") << "a=b; expires=30 -000002 1:1 25;" << cookie;
|
|
513 |
|
|
514 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 20), QTime(1, 1, 0, 0), Qt::UTC));
|
|
515 |
QTest::newRow("fuzz-1") << "a=b; expires=31 11 20 1:1;" << cookie;
|
|
516 |
|
|
517 |
// April only has 30 days
|
|
518 |
cookie.setExpirationDate(QDateTime(QDate(2031, 4, 30), QTime(1, 1, 0, 0), Qt::UTC));
|
|
519 |
QTest::newRow("fuzz-2") << "a=b; expires=31 30 4 1:1" << cookie;
|
|
520 |
|
|
521 |
// 9 must be the month so 31 can't be the day
|
|
522 |
cookie.setExpirationDate(QDateTime(QDate(2031, 9, 21), QTime(1, 1, 0, 0), Qt::UTC));
|
|
523 |
QTest::newRow("fuzz-3") << "a=b; expires=31 21 9 1:1" << cookie;
|
|
524 |
|
|
525 |
// Year is known, then fallback to defaults of filling in month and day
|
|
526 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 1), QTime(1, 1, 0, 0), Qt::UTC));
|
|
527 |
QTest::newRow("fuzz-4") << "a=b; expires=31 11 01 1:1" << cookie;
|
|
528 |
|
|
529 |
// 2 must be the month so 30 can't be the day
|
|
530 |
cookie.setExpirationDate(QDateTime(QDate(2030, 2, 20), QTime(1, 1, 0, 0), Qt::UTC));
|
|
531 |
QTest::newRow("fuzz-5") << "a=b; expires=30 02 20 1:1" << cookie;
|
|
532 |
|
|
533 |
cookie.setExpirationDate(QDateTime(QDate(2021, 12, 22), QTime(1, 1, 0, 0), Qt::UTC));
|
|
534 |
QTest::newRow("fuzz-6") << "a=b; expires=2021 12 22 1:1" << cookie;
|
|
535 |
|
|
536 |
cookie.setExpirationDate(QDateTime(QDate(2029, 2, 23), QTime(1, 1, 0, 0), Qt::UTC));
|
|
537 |
QTest::newRow("fuzz-7") << "a=b; expires=29 23 Feb 1:1" << cookie;
|
|
538 |
|
|
539 |
// 11 and 6 don't have 31 days
|
|
540 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 06), QTime(1, 1, 0, 0), Qt::UTC));
|
|
541 |
QTest::newRow("fuzz-8") << "a=b; expires=31 11 06 1:1" << cookie;
|
|
542 |
|
|
543 |
// two-digit years:
|
|
544 |
// from 70 until 99, we assume 20th century
|
|
545 |
cookie.setExpirationDate(QDateTime(QDate(1999, 11, 9), QTime(23, 12, 40), Qt::UTC));
|
|
546 |
QTest::newRow("expiration-2digit1") << "a=b; expires=Wednesday, 09-Nov-99 23:12:40 GMT " << cookie;
|
|
547 |
cookie.setExpirationDate(QDateTime(QDate(1970, 1, 1), QTime(23, 12, 40), Qt::UTC));
|
|
548 |
QTest::newRow("expiration-2digit2") << "a=b; expires=Thursday, 01-Jan-70 23:12:40 GMT " << cookie;
|
|
549 |
// from 00 until 69, we assume 21st century
|
|
550 |
cookie.setExpirationDate(QDateTime(QDate(2000, 1, 1), QTime(23, 12, 40), Qt::UTC));
|
|
551 |
QTest::newRow("expiration-2digit3") << "a=b; expires=Saturday, 01-Jan-00 23:12:40 GMT " << cookie;
|
|
552 |
cookie.setExpirationDate(QDateTime(QDate(2020, 1, 1), QTime(23, 12, 40), Qt::UTC));
|
|
553 |
QTest::newRow("expiration-2digit4") << "a=b; expires=Wednesday, 01-Jan-20 23:12:40 GMT " << cookie;
|
|
554 |
cookie.setExpirationDate(QDateTime(QDate(2069, 1, 1), QTime(23, 12, 40), Qt::UTC));
|
|
555 |
QTest::newRow("expiration-2digit5") << "a=b; expires=Wednesday, 01-Jan-69 23:12:40 GMT " << cookie;
|
|
556 |
|
|
557 |
cookie.setExpirationDate(QDateTime(QDate(1999, 11, 9), QTime(23, 12, 40), Qt::UTC));
|
|
558 |
|
|
559 |
cookie.setPath("/");
|
|
560 |
QTest::newRow("expires+path") << "a=b; expires=Wed, 09-Nov-1999 23:12:40 GMT; path=/" << cookie;
|
|
561 |
QTest::newRow("path+expires") << "a=b; path=/;expires=Wed, 09-Nov-1999 23:12:40 GMT " << cookie;
|
|
562 |
|
|
563 |
cookie.setDomain(".qt.nokia.com");
|
|
564 |
QTest::newRow("full") << "a=b; domain=.qt.nokia.com;expires=Wed, 09-Nov-1999 23:12:40 GMT;path=/" << cookie;
|
|
565 |
QTest::newRow("full2") << "a=b;path=/; expires=Wed, 09-Nov-1999 23:12:40 GMT ;domain=.qt.nokia.com" << cookie;
|
|
566 |
|
|
567 |
// cookies obtained from the network:
|
|
568 |
cookie = QNetworkCookie("__siteid", "1");
|
|
569 |
cookie.setPath("/");
|
|
570 |
cookie.setExpirationDate(QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59), Qt::UTC));
|
|
571 |
QTest::newRow("network2") << "__siteid=1; expires=Fri, 31-Dec-9999 23:59:59 GMT; path=/" << cookie;
|
|
572 |
|
|
573 |
cookie = QNetworkCookie("YM.LC", "v=2&m=9993_262838_159_1558_1063_0_5649_4012_3776161073,9426_260205_549_1295_1336_0_5141_4738_3922731647,6733_258196_952_1364_643_0_3560_-1_0,3677_237633_1294_1294_19267_0_3244_29483_4102206176,1315_235149_1693_1541_941_0_3224_1691_1861378060,1858_214311_2100_1298_19538_0_2873_30900_716411652,6258_212007_2506_1285_1017_0_2868_3606_4288540264,3743_207884_2895_1362_2759_0_2545_7114_3388520216,2654_205253_3257_1297_1332_0_2504_4682_3048534803,1891_184881_3660_1291_19079_0_978_29178_2592538685&f=1&n=20&s=date&o=down&e=1196548712&b=Inbox&u=removed");
|
|
574 |
cookie.setPath("/");
|
|
575 |
cookie.setDomain("mail.yahoo.com");
|
|
576 |
QTest::newRow("network3") << "YM.LC=v=2&m=9993_262838_159_1558_1063_0_5649_4012_3776161073,9426_260205_549_1295_1336_0_5141_4738_3922731647,6733_258196_952_1364_643_0_3560_-1_0,3677_237633_1294_1294_19267_0_3244_29483_4102206176,1315_235149_1693_1541_941_0_3224_1691_1861378060,1858_214311_2100_1298_19538_0_2873_30900_716411652,6258_212007_2506_1285_1017_0_2868_3606_4288540264,3743_207884_2895_1362_2759_0_2545_7114_3388520216,2654_205253_3257_1297_1332_0_2504_4682_3048534803,1891_184881_3660_1291_19079_0_978_29178_2592538685&f=1&n=20&s=date&o=down&e=1196548712&b=Inbox&u=removed; path=/; domain=mail.yahoo.com" << cookie;
|
|
577 |
|
|
578 |
cookie = QNetworkCookie("__ac", "c2hhdXNtYW46U2FTYW80Wm8%3D");
|
|
579 |
cookie.setPath("/");
|
|
580 |
cookie.setExpirationDate(QDateTime(QDate(2008, 8, 30), QTime(20, 21, 49), Qt::UTC));
|
|
581 |
QTest::newRow("network4") << "__ac=\"c2hhdXNtYW46U2FTYW80Wm8%3D\"; Path=/; Expires=Sat, 30 Aug 2008 20:21:49 +0000" << cookie;
|
|
582 |
}
|
|
583 |
|
|
584 |
void tst_QNetworkCookie::parseSingleCookie()
|
|
585 |
{
|
|
586 |
QFETCH(QString, cookieString);
|
|
587 |
QFETCH(QNetworkCookie, expectedCookie);
|
|
588 |
|
|
589 |
QList<QNetworkCookie> result = QNetworkCookie::parseCookies(cookieString.toLatin1());
|
|
590 |
|
|
591 |
//QEXPECT_FAIL("network2", "QDateTime parsing problem: the date is beyond year 8000", Abort);
|
|
592 |
QCOMPARE(result.count(), 1);
|
|
593 |
QEXPECT_FAIL("network3", "Cookie value contains commas, violating the HTTP spec", Abort);
|
|
594 |
QCOMPARE(result.at(0), expectedCookie);
|
|
595 |
|
|
596 |
result = QNetworkCookie::parseCookies(result.at(0).toRawForm());
|
|
597 |
QCOMPARE(result.count(), 1);
|
|
598 |
|
|
599 |
// Drop any millisecond information, if there's any
|
|
600 |
QDateTime dt = expectedCookie.expirationDate();
|
|
601 |
if (dt.isValid()) {
|
|
602 |
QTime t = dt.time();
|
|
603 |
dt.setTime(t.addMSecs(-t.msec()));
|
|
604 |
expectedCookie.setExpirationDate(dt);
|
|
605 |
}
|
|
606 |
|
|
607 |
QCOMPARE(result.at(0), expectedCookie);
|
|
608 |
}
|
|
609 |
|
|
610 |
void tst_QNetworkCookie::parseMultipleCookies_data()
|
|
611 |
{
|
|
612 |
QTest::addColumn<QString>("cookieString");
|
|
613 |
QTest::addColumn<QList<QNetworkCookie> >("expectedCookies");
|
|
614 |
|
|
615 |
QList<QNetworkCookie> list;
|
|
616 |
QTest::newRow("empty") << "" << list;
|
|
617 |
|
|
618 |
// these are technically empty cookies:
|
|
619 |
QTest::newRow("invalid-01") << ";" << list;
|
|
620 |
QTest::newRow("invalid-02") << " " << list;
|
|
621 |
QTest::newRow("invalid-03") << " ," << list;
|
|
622 |
QTest::newRow("invalid-04") << ";;,, ; ; , , ; , ;" << list;
|
|
623 |
|
|
624 |
// these are really invalid:
|
|
625 |
// reason: malformed NAME=VALUE pair
|
|
626 |
QTest::newRow("invalid-05") << "foo" << list;
|
|
627 |
QTest::newRow("invalid-06") << "=b" << list;
|
|
628 |
QTest::newRow("invalid-09") << "foo,a=b" << list;
|
|
629 |
QTest::newRow("invalid-11") << ";path=/" << list;
|
|
630 |
|
|
631 |
// reason: malformed expiration date string
|
|
632 |
QTest::newRow("invalid-12") << "a=b;expires=" << list;
|
|
633 |
QTest::newRow("invalid-13") << "a=b;expires=foobar" << list;
|
|
634 |
QTest::newRow("invalid-14") << "a=b;expires=foobar, abc" << list;
|
|
635 |
QTest::newRow("invalid-15") << "a=b;expires=foobar, dd-mmm-yyyy hh:mm:ss GMT; path=/" << list;
|
|
636 |
QTest::newRow("invalid-16") << "a=b;expires=foobar, 32-Caz-1999 24:01:60 GMT; path=/" << list;
|
|
637 |
|
|
638 |
QNetworkCookie cookie;
|
|
639 |
cookie.setName("a");
|
|
640 |
list += cookie;
|
|
641 |
cookie.setName("c");
|
|
642 |
cookie.setValue("d");
|
|
643 |
list += cookie;
|
|
644 |
QTest::newRow("two-1") << "a=,c=d" << list;
|
|
645 |
QTest::newRow("two-2") << "a=, c=d" << list;
|
|
646 |
QTest::newRow("two-3") << "a= ,c=d" << list;
|
|
647 |
QTest::newRow("two-4") << "a= , c=d" << list;
|
|
648 |
|
|
649 |
list.clear();
|
|
650 |
list += cookie;
|
|
651 |
cookie.setName("a");
|
|
652 |
cookie.setValue(QByteArray());
|
|
653 |
list += cookie;
|
|
654 |
QTest::newRow("two-5") << "c=d,a=" << list;
|
|
655 |
QTest::newRow("two-6") << "c=d, a=" << list;
|
|
656 |
QTest::newRow("two-7") << "c=d , a=" << list;
|
|
657 |
|
|
658 |
cookie.setName("foo");
|
|
659 |
cookie.setValue("bar");
|
|
660 |
cookie.setPath("/");
|
|
661 |
list += cookie;
|
|
662 |
QTest::newRow("complex-1") << "c=d, a=, foo=bar; path=/" << list;
|
|
663 |
|
|
664 |
cookie.setName("baz");
|
|
665 |
cookie.setDomain(".qt.nokia.com");
|
|
666 |
list.prepend(cookie);
|
|
667 |
QTest::newRow("complex-2") << "baz=bar; path=/; domain=qt.nokia.com, c=d,a=,foo=bar; path=/" << list;
|
|
668 |
|
|
669 |
// cookies obtained from the network:
|
|
670 |
cookie = QNetworkCookie("id", "51706646077999719");
|
|
671 |
cookie.setDomain(".bluestreak.com");
|
|
672 |
cookie.setPath("/");
|
|
673 |
cookie.setExpirationDate(QDateTime(QDate(2017, 12, 05), QTime(9, 11, 7), Qt::UTC));
|
|
674 |
list << cookie;
|
|
675 |
cookie.setName("bb");
|
|
676 |
cookie.setValue("\\\"K14144t\\\"_AAQ\\\"ototrK_A_ttot44AQ4KwoRQtoto|");
|
|
677 |
list << cookie;
|
|
678 |
cookie.setName("adv");
|
|
679 |
cookie.setValue(QByteArray());
|
|
680 |
list << cookie;
|
|
681 |
QTest::newRow("network1") << "id=51706646077999719 bb=\"K14144t\"_AAQ\"ototrK_A_ttot44AQ4KwoRQtoto| adv=; Domain=.bluestreak.com; expires=Tuesday 05-Dec-2017 09:11:07 GMT; path=/;" << list;
|
|
682 |
|
|
683 |
QNetworkCookie cookieA;
|
|
684 |
cookieA.setName("a");
|
|
685 |
cookieA.setValue("b");
|
|
686 |
|
|
687 |
QNetworkCookie cookieB;
|
|
688 |
cookieB.setName("c");
|
|
689 |
cookieB.setValue("d");
|
|
690 |
|
|
691 |
// NewLine
|
|
692 |
cookieA.setExpirationDate(QDateTime(QDate(2009, 3, 10), QTime(7, 0, 0, 0), Qt::UTC));
|
|
693 |
cookieB.setExpirationDate(QDateTime(QDate(2009, 3, 20), QTime(7, 0, 0, 0), Qt::UTC));
|
|
694 |
list = QList<QNetworkCookie>() << cookieA << cookieB;
|
|
695 |
QTest::newRow("real-0") << "a=b; expires=Tue Mar 10 07:00:00 2009 GMT\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list;
|
|
696 |
QTest::newRow("real-1") << "a=b; expires=Tue Mar 10 07:00:00 2009 GMT\n\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list;
|
|
697 |
QTest::newRow("real-2") << "a=b; expires=Mar 10 07:00:00 2009 GMT, Tue\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list;
|
|
698 |
|
|
699 |
// Match firefox's behavior
|
|
700 |
cookieA.setPath("/foo");
|
|
701 |
list = QList<QNetworkCookie>() << cookieA << cookieB;
|
|
702 |
QTest::newRow("real-3") << "a=b; expires=Mar 10 07:00:00 2009 GMT, Tue; path=/foo\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list;
|
|
703 |
}
|
|
704 |
|
|
705 |
void tst_QNetworkCookie::parseMultipleCookies()
|
|
706 |
{
|
|
707 |
QFETCH(QString, cookieString);
|
|
708 |
QFETCH(QList<QNetworkCookie>, expectedCookies);
|
|
709 |
|
|
710 |
QList<QNetworkCookie> result = QNetworkCookie::parseCookies(cookieString.toLatin1());
|
|
711 |
|
|
712 |
QEXPECT_FAIL("network1", "Apparently multiple cookies set in one request (and an invalid date)", Abort);
|
|
713 |
QCOMPARE(result, expectedCookies);
|
|
714 |
}
|
|
715 |
|
|
716 |
QTEST_MAIN(tst_QNetworkCookie)
|
|
717 |
#include "tst_qnetworkcookie.moc"
|