Re: [FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
Hello, Same patch with corrected name. Thanks in advance. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
Signed-off-by: Micah Galizia --- libavformat/Makefile | 1 + libavformat/tests/http.c | 186 + tests/fate/libavformat.mak | 5 ++ tests/ref/fate/http| 30 4 files changed, 222 insertions(+) create mode 100644 libavformat/tests/http.c create mode 100644 tests/ref/fate/http diff --git a/libavformat/Makefile b/libavformat/Makefile index f56ef16..a4abd1b 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -597,6 +597,7 @@ SKIPHEADERS-$(CONFIG_NETWORK)+= network.h rtsp.h TESTPROGS = seek\ url \ +http\ # async \ FIFO-MUXER-TESTPROGS-$(CONFIG_NETWORK) += fifo_muxer diff --git a/libavformat/tests/http.c b/libavformat/tests/http.c new file mode 100644 index 000..76a70ae --- /dev/null +++ b/libavformat/tests/http.c @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2017 Micah Galizia + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/http.c" +#include "libavformat/avio.h" + +typedef struct GetCookiesTestCase { +const char *set_cookie; +const char *cookie_str; +const char *path; +const char *domain; +} GetCookiesTestCase; + +// Don't go past Tue, 19 Jan 2038 03:14:07 GMT or 32-bit time_t overflows +GetCookiesTestCase get_cookies_tests[] = { +/* Test good and expired cookie. Should be acceptable */ +{"first=\"good\"; Domain=.test.com; Path=/\nsecond=great; domain=.test.com; path=/; HttpOnly", + "first=\"good\"; second=great", "/hello", "cookie.test.com"}, + + /* Test good and expired cookie. Should be acceptable */ +{"expired=\"really_old\"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/\ngood=not_expired; domain=.test.com; path=/; expires=Tue, 19 Jan 2038 03:14:07 GMT; HttpOnly", + "good=not_expired", "/hello", "cookie.test.com"}, + +/* Test a good and expired cookie in the neulion format. + * Should be acceptable */ +{"expired=\"really_old\"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/\nneulion=not_expired; domain=.test.com; path=/; expires=Tue, 19-Jan-2038 03:14:07 GMT; HttpOnly", + "neulion=not_expired", "/hello", "cookie.test.com"}, + +/* Test an expiry date without the day of week specified */ +{"no_day=still_ok; domain=.test.com; path=/; expires=19 Jan 2038 03:14:07 GMT; HttpOnly", + "no_day=still_ok", "/hello", "cookie.test.com"}, + +/* Test a date that cannot be parsed. Allow the cookie */ +{"unparsable_date=allow_cookie; domain=.test.com; path=/; expires=19 Jon 2038 03:14:07 GMT; HttpOnly", + "unparsable_date=allow_cookie", "/hello", "cookie.test.com"}, + +/* Test a cookie that has a different domain. Do not use the cookie */ +{"different_domain=exclude; domain=.nottest.com; path=/; expires=19 Jan 2038 03:14:07 GMT; HttpOnly", + NULL, "/hello", "cookie.test.com"}, + +/* Test a set-cookie that has no spaces */ + {"no_spaces=no_big_deal;domain=.test.com;path=/;expires=Tue,19Jan203803:14:07GMT;HttpOnly", + "no_spaces=no_big_deal", "/hello", "cookie.test.com"}, + +/* Test a set-cookie that has no spaces and is expired. Excluded */ + {"no_spaces_expired=not_ok;domain=.test.com;path=/;expires=Thu01Jan197010GMT;HttpOnly", + NULL, "/hello", "cookie.test.com"}, + +/* Test a set-cookie with a date that is too long. */ +{"long=handled;domain=.test.com;path=/;expires=Tue, 19 Jan 2038 03:14:07GMTGMTGMTGMTGMTGMT;HttpOnly", + "long=handled", "/hello", "cookie.test.com"}, + +/* Test a set-cookie with a date that starts with too many characters */ +{"bad_start=ok;domain=.test.com;path=/;expires=BooBooBooTue, 19 Jan 2038 03:14:07;HttpOnly", + "bad_start=ok", "/hello", "cookie.test.com"}, + +{NULL} +}; + + +static int test_get_cookies(void) +{ +URLContext *c = NULL; +char *cookies = NULL; +HTTPContext http; + +if (ffurl_alloc(&c, "http://test.com";, AVIO_FLAG_READ, NULL) < 0) { +printf("Unable to allocate HTTP URL pro
[FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
Hi, I didn't realize there was a year 2038 problem -- dates beyond it overflow a 32-bit time_t -- I've made the unit tests 32-bit compatible now. Thank you! ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
On Sun, Apr 02, 2017 at 04:26:07PM -0400, Micah Galizia wrote: > Signed-off-by: Micah Galizia > --- > libavformat/Makefile | 1 + > libavformat/tests/http.c | 185 > + > tests/fate/libavformat.mak | 5 ++ > tests/ref/fate/http| 30 > 4 files changed, 221 insertions(+) > create mode 100644 libavformat/tests/http.c > create mode 100644 tests/ref/fate/http crashes on x86-32 'good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly'->'expires'|'Fri, 12 Mar 2117 02:53:03 GMT' 'good=great'->'good'|'great' 0) 'first="good"; Domain=.test.com; Path=/ second=great; domain=.test.com; path=/; HttpOnly'=>'first="good"; second=great' Unable to parse 'expired="really_old"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/' Unable to parse 'good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly' 1) 'expired="really_old"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/ good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly'=>'(null)' ERROR: test case 1 failed NULL check Unable to parse 'expired="really_old"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/' Unable to parse 'neulion=not_expired; domain=.test.com; path=/; expires=Fri, 12-Mar-2117 02:53:03 GMT; HttpOnly' 2) 'expired="really_old"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ neulion=not_expired; domain=.test.com; path=/; expires=Fri, 12-Mar-2117 02:53:03 GMT; HttpOnly'=>'(null)' ERROR: test case 2 failed NULL check Unable to parse 'no_day=still_ok; domain=.test.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly' 3) 'no_day=still_ok; domain=.test.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly'=>'(null)' ERROR: test case 3 failed NULL check 4) 'unparsable_date=allow_cookie; domain=.test.com; path=/; expires=12-Mur-2117 02:53:03 GMT; HttpOnly'=>'unparsable_date=allow_cookie' Unable to parse 'different_domain=exclude; domain=.nottest.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly' 5) 'different_domain=exclude; domain=.nottest.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly'=>'(null)' Unable to parse 'no_spaces=no_big_deal;domain=.test.com;path=/;expires=Fri,12Mar211702:53:03GMT;HttpOnly' 6) 'no_spaces=no_big_deal;domain=.test.com;path=/;expires=Fri,12Mar211702:53:03GMT;HttpOnly'=>'(null)' ERROR: test case 6 failed NULL check Unable to parse 'no_spaces_expired=not_ok;domain=.test.com;path=/;expires=Thu01Jan197010GMT;HttpOnly' 7) 'no_spaces_expired=not_ok;domain=.test.com;path=/;expires=Thu01Jan197010GMT;HttpOnly'=>'(null)' Unable to parse 'long=handled;domain=.test.com;path=/;expires=Fri, 12 Mar 2117 02:53:03GMTGMTGMTGMTGMTGMT;HttpOnly' 8) 'long=handled;domain=.test.com;path=/;expires=Fri, 12 Mar 2117 02:53:03GMTGMTGMTGMTGMTGMT;HttpOnly'=>'(null)' ERROR: test case 8 failed NULL check 9) 'bad_start=ok;domain=.test.com;path=/;expires=BooBooBooFri, 12 Mar 2117 02:53:03;HttpOnly'=>'bad_start=ok' Program received signal SIGSEGV, Segmentation fault. test_parse_cookie () at src/libavformat/tests/http.c:146 146 printf("'%s'->'%s'|'%s'\n", new, e->key, e->value); (gdb) bt Python Exception No module named gdb.frames: #0 test_parse_cookie () at src/libavformat/tests/http.c:146 #1 main () at src/libavformat/tests/http.c:180 (gdb) print e $1 = (AVDictionaryEntry *) 0x0 (gdb) [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The worst form of inequality is to try to make unequal things equal. -- Aristotle signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
Hi, No more passing null to strcmp -- hopefully this addresses the crash. Thanks in advance. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
Signed-off-by: Micah Galizia --- libavformat/Makefile | 1 + libavformat/tests/http.c | 185 + tests/fate/libavformat.mak | 5 ++ tests/ref/fate/http| 30 4 files changed, 221 insertions(+) create mode 100644 libavformat/tests/http.c create mode 100644 tests/ref/fate/http diff --git a/libavformat/Makefile b/libavformat/Makefile index f56ef16..a4abd1b 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -597,6 +597,7 @@ SKIPHEADERS-$(CONFIG_NETWORK)+= network.h rtsp.h TESTPROGS = seek\ url \ +http\ # async \ FIFO-MUXER-TESTPROGS-$(CONFIG_NETWORK) += fifo_muxer diff --git a/libavformat/tests/http.c b/libavformat/tests/http.c new file mode 100644 index 000..9652e71 --- /dev/null +++ b/libavformat/tests/http.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2017 Micah Galizia + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/http.c" +#include "libavformat/avio.h" + +typedef struct GetCookiesTestCase { +const char *set_cookie; +const char *cookie_str; +const char *path; +const char *domain; +} GetCookiesTestCase; + +GetCookiesTestCase get_cookies_tests[] = { +/* Test good and expired cookie. Should be acceptable */ +{"first=\"good\"; Domain=.test.com; Path=/\nsecond=great; domain=.test.com; path=/; HttpOnly", + "first=\"good\"; second=great", "/hello", "cookie.test.com"}, + + /* Test good and expired cookie. Should be acceptable */ +{"expired=\"really_old\"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/\ngood=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly", + "good=not_expired", "/hello", "cookie.test.com"}, + +/* Test a good and expired cookie in the neulion format. + * Should be acceptable */ +{"expired=\"really_old\"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/\nneulion=not_expired; domain=.test.com; path=/; expires=Fri, 12-Mar-2117 02:53:03 GMT; HttpOnly", + "neulion=not_expired", "/hello", "cookie.test.com"}, + +/* Test an expiry date without the day of week specified */ +{"no_day=still_ok; domain=.test.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly", + "no_day=still_ok", "/hello", "cookie.test.com"}, + +/* Test a date that cannot be parsed. Allow the cookie */ +{"unparsable_date=allow_cookie; domain=.test.com; path=/; expires=12-Mur-2117 02:53:03 GMT; HttpOnly", + "unparsable_date=allow_cookie", "/hello", "cookie.test.com"}, + +/* Test a cookie that has a different domain. Do not use the cookie */ +{"different_domain=exclude; domain=.nottest.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly", + NULL, "/hello", "cookie.test.com"}, + +/* Test a set-cookie that has no spaces */ + {"no_spaces=no_big_deal;domain=.test.com;path=/;expires=Fri,12Mar211702:53:03GMT;HttpOnly", + "no_spaces=no_big_deal", "/hello", "cookie.test.com"}, + +/* Test a set-cookie that has no spaces and is expired. Excluded */ + {"no_spaces_expired=not_ok;domain=.test.com;path=/;expires=Thu01Jan197010GMT;HttpOnly", + NULL, "/hello", "cookie.test.com"}, + +/* Test a set-cookie with a date that is too long. */ +{"long=handled;domain=.test.com;path=/;expires=Fri, 12 Mar 2117 02:53:03GMTGMTGMTGMTGMTGMT;HttpOnly", + "long=handled", "/hello", "cookie.test.com"}, + +/* Test a set-cookie with a date that starts with too many characters */ +{"bad_start=ok;domain=.test.com;path=/;expires=BooBooBooFri, 12 Mar 2117 02:53:03;HttpOnly", + "bad_start=ok", "/hello", "cookie.test.com"}, + +{NULL} +}; + + +static int test_get_cookies(void) +{ +URLContext *c = NULL; +char *cookies = NULL; +HTTPContext http; + +if (ffurl_alloc(&c, "http://test.com";, AVIO_FLAG_READ, NULL) < 0) { +printf("Unable to allocate HTTP URL protocol\n"); +return -1; +} +http.cookie_dict = NULL; + +
Re: [FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
On 2017-03-31 06:10 AM, Michael Niedermayer wrote: On Thu, Mar 30, 2017 at 09:33:48PM -0400, Micah Galizia wrote: Signed-off-by: Micah Galizia --- libavformat/Makefile | 1 + libavformat/tests/http.c | 182 + tests/fate/libavformat.mak | 5 ++ tests/ref/fate/http| 30 4 files changed, 218 insertions(+) create mode 100644 libavformat/tests/http.c create mode 100644 tests/ref/fate/http the test segfaults 'good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly'->'expires'|'Fri, 12 Mar 2117 02:53:03 GMT' 'good=great'->'good'|'great' 0) 'first="good"; Domain=.test.com; Path=/ second=great; domain=.test.com; path=/; HttpOnly'=>'first="good"; second=great' Unable to parse 'expired="really_old"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/' 1) 'expired="really_old"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/ good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly'=>'good=not_expired' Unable to parse 'expired="really_old"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/' 2) 'expired="really_old"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ neulion=not_expired; domain=.test.com; path=/; expires=Fri, 12-Mar-2117 02:53:03 GMT; HttpOnly'=>'neulion=not_expired' 3) 'no_day=still_ok; domain=.test.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly'=>'no_day=still_ok' 4) 'unparsable_date=allow_cookie; domain=.test.com; path=/; expires=12-Mur-2117 02:53:03 GMT; HttpOnly'=>'unparsable_date=allow_cookie' 5) 'different_domain=exclude; domain=.nottest.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly'=>'(null)' Program received signal SIGSEGV, Segmentation fault. 0x75851166 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) bt #0 0x75851166 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x0041197c in test_get_cookies () at libavformat/tests/http.c:97 #2 0x0041056b in main () at libavformat/tests/http.c:173 [...] Thanks, I'm trying to reproduce your results here without success -- I can't get it to crash on my system. I'm on the same architecture as you are (x86_64) too... based on the backtrace I'm guessing maybe strcmp doesn't like s2 being null, even though it works on my system -- I'll add an explicit case for when they're both null so we're not comparing two null strings and resubmit. Thanks for running it/sorry for the crash. I'll try to send a fix today some time. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
On Thu, Mar 30, 2017 at 09:33:48PM -0400, Micah Galizia wrote: > Signed-off-by: Micah Galizia > --- > libavformat/Makefile | 1 + > libavformat/tests/http.c | 182 > + > tests/fate/libavformat.mak | 5 ++ > tests/ref/fate/http| 30 > 4 files changed, 218 insertions(+) > create mode 100644 libavformat/tests/http.c > create mode 100644 tests/ref/fate/http the test segfaults 'good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly'->'expires'|'Fri, 12 Mar 2117 02:53:03 GMT' 'good=great'->'good'|'great' 0) 'first="good"; Domain=.test.com; Path=/ second=great; domain=.test.com; path=/; HttpOnly'=>'first="good"; second=great' Unable to parse 'expired="really_old"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/' 1) 'expired="really_old"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/ good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly'=>'good=not_expired' Unable to parse 'expired="really_old"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/' 2) 'expired="really_old"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ neulion=not_expired; domain=.test.com; path=/; expires=Fri, 12-Mar-2117 02:53:03 GMT; HttpOnly'=>'neulion=not_expired' 3) 'no_day=still_ok; domain=.test.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly'=>'no_day=still_ok' 4) 'unparsable_date=allow_cookie; domain=.test.com; path=/; expires=12-Mur-2117 02:53:03 GMT; HttpOnly'=>'unparsable_date=allow_cookie' 5) 'different_domain=exclude; domain=.nottest.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly'=>'(null)' Program received signal SIGSEGV, Segmentation fault. 0x75851166 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) bt #0 0x75851166 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x0041197c in test_get_cookies () at libavformat/tests/http.c:97 #2 0x0041056b in main () at libavformat/tests/http.c:173 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate
Signed-off-by: Micah Galizia --- libavformat/Makefile | 1 + libavformat/tests/http.c | 182 + tests/fate/libavformat.mak | 5 ++ tests/ref/fate/http| 30 4 files changed, 218 insertions(+) create mode 100644 libavformat/tests/http.c create mode 100644 tests/ref/fate/http diff --git a/libavformat/Makefile b/libavformat/Makefile index f56ef16..a4abd1b 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -597,6 +597,7 @@ SKIPHEADERS-$(CONFIG_NETWORK)+= network.h rtsp.h TESTPROGS = seek\ url \ +http\ # async \ FIFO-MUXER-TESTPROGS-$(CONFIG_NETWORK) += fifo_muxer diff --git a/libavformat/tests/http.c b/libavformat/tests/http.c new file mode 100644 index 000..702cc86 --- /dev/null +++ b/libavformat/tests/http.c @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2017 Micah Galizia + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/http.c" +#include "libavformat/avio.h" + +typedef struct GetCookiesTestCase { +const char *set_cookie; +const char *cookie_str; +const char *path; +const char *domain; +} GetCookiesTestCase; + +GetCookiesTestCase get_cookies_tests[] = { +/* Test good and expired cookie. Should be acceptable */ +{"first=\"good\"; Domain=.test.com; Path=/\nsecond=great; domain=.test.com; path=/; HttpOnly", + "first=\"good\"; second=great", "/hello", "cookie.test.com"}, + + /* Test good and expired cookie. Should be acceptable */ +{"expired=\"really_old\"; Domain=.test.com; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/\ngood=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly", + "good=not_expired", "/hello", "cookie.test.com"}, + +/* Test a good and expired cookie in the neulion format. + * Should be acceptable */ +{"expired=\"really_old\"; Domain=.test.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/\nneulion=not_expired; domain=.test.com; path=/; expires=Fri, 12-Mar-2117 02:53:03 GMT; HttpOnly", + "neulion=not_expired", "/hello", "cookie.test.com"}, + +/* Test an expiry date without the day of week specified */ +{"no_day=still_ok; domain=.test.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly", + "no_day=still_ok", "/hello", "cookie.test.com"}, + +/* Test a date that cannot be parsed. Allow the cookie */ +{"unparsable_date=allow_cookie; domain=.test.com; path=/; expires=12-Mur-2117 02:53:03 GMT; HttpOnly", + "unparsable_date=allow_cookie", "/hello", "cookie.test.com"}, + +/* Test a cookie that has a different domain. Do not use the cookie */ +{"different_domain=exclude; domain=.nottest.com; path=/; expires=12-Mar-2117 02:53:03 GMT; HttpOnly", + NULL, "/hello", "cookie.test.com"}, + +/* Test a set-cookie that has no spaces */ + {"no_spaces=no_big_deal;domain=.test.com;path=/;expires=Fri,12Mar211702:53:03GMT;HttpOnly", + "no_spaces=no_big_deal", "/hello", "cookie.test.com"}, + +/* Test a set-cookie that has no spaces and is expired. Excluded */ + {"no_spaces_expired=not_ok;domain=.test.com;path=/;expires=Thu01Jan197010GMT;HttpOnly", + NULL, "/hello", "cookie.test.com"}, + +/* Test a set-cookie with a date that is too long. */ +{"long=handled;domain=.test.com;path=/;expires=Fri, 12 Mar 2117 02:53:03GMTGMTGMTGMTGMTGMT;HttpOnly", + "long=handled", "/hello", "cookie.test.com"}, + +/* Test a set-cookie with a date that starts with too many characters */ +{"bad_start=ok;domain=.test.com;path=/;expires=BooBooBooFri, 12 Mar 2117 02:53:03;HttpOnly", + "bad_start=ok", "/hello", "cookie.test.com"}, + +{NULL} +}; + + +static int test_get_cookies(void) +{ +URLContext *c = NULL; +char *cookies = NULL; +HTTPContext http; + +if (ffurl_alloc(&c, "http://test.com";, AVIO_FLAG_READ, NULL) < 0) { +printf("Unable to allocate HTTP URL protocol\n"); +return -1; +} +http.cookie_dict = NULL; + +