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

source code of qtbase/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp