From patchwork Fri Mar 31 01:33:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 3208 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp1823798vss; Thu, 30 Mar 2017 18:34:49 -0700 (PDT) X-Received: by 10.223.128.202 with SMTP id 68mr348806wrl.108.1490924089276; Thu, 30 Mar 2017 18:34:49 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b128si1171045wmb.79.2017.03.30.18.34.48; Thu, 30 Mar 2017 18:34:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 615A3689895; Fri, 31 Mar 2017 04:34:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f43.google.com (mail-it0-f43.google.com [209.85.214.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B56468055B for ; Fri, 31 Mar 2017 04:34:39 +0300 (EEST) Received: by mail-it0-f43.google.com with SMTP id e75so4854546itd.1 for ; Thu, 30 Mar 2017 18:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rNS0jV5woSrw6qyyOXSB3rmMtAMrXoiCycN4zbTIMpw=; b=ZjRVtV8qQU2P6ofohiALCn+lIndRk9y2GSJ+sef+SG7Z5Fhfjvj5DEi+MN5s/7YsA6 pjc1FxKQbeIhW9CNZqQW1RY4Vk6XkdKWbNHUXxLUwE7cxmBzyaKJ5Me6EJcp6Z9znRo4 mZ5QxMJ1nq147p512FEmFvpKPhYKKLr+ss421+QZ0FSlvFE93KtOilaB0EaJza4WggYR rdmzAT+oMmYbK2rLkrI/dZsCqQIgxAmgOc1QuiQbC6CrO6YH5HEypjquOIeei/RvlBqX Kl+L+Cn6kY9L7aSJi/XKiKuT83vqTtZsqrN+MjgHz0GiHcqimhbm4RNIJ0ocD/IRpPaF LYrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rNS0jV5woSrw6qyyOXSB3rmMtAMrXoiCycN4zbTIMpw=; b=d8ywuauMVOvroJ849x2SVNIfUfMrpLxsOg/lqFh53qRj/+XXH/dw4aOQ9VL6sUOnb/ R7UXeE8Ow063My7m0YRr9Yvm1euJU2/KjlKyCb/Xh7q2RIQ3pFrCZAGpuei8OR+VUgJ4 19ylxurC30D2UGjfk8e3Dy/aPCcFL+dMJ0CBA+1tZbyCo+4Ps6K/DW6L2EpWk83iRP2Z sRcJJXquFgxXu9+tgD7/DAImTvKZvjMxt+X6a8TWW45X7MxK8dy6H9ult4iRSauld6Pa 4Wg1ugqTZ46Jv2RIh/ppBguRZlN3KAw+lwXn6OJZHILDimKKaO6cwQTh6eIB/CZM0/mJ 09JQ== X-Gm-Message-State: AFeK/H1AV3JQwumOT5uczXHow8qUc5mc3JxFkuWP5NOES05HfCG5lxNPKsv5TjncVuKBSQ== X-Received: by 10.36.47.78 with SMTP id j75mr728078itj.72.1490924078218; Thu, 30 Mar 2017 18:34:38 -0700 (PDT) Received: from localhost.localdomain (ip-24-54-73-138.user.start.ca. [24.54.73.138]) by smtp.gmail.com with ESMTPSA id f63sm505825ita.26.2017.03.30.18.34.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:34:37 -0700 (PDT) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Mar 2017 21:33:48 -0400 Message-Id: <20170331013348.12504-3-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170331013348.12504-1-micahgalizia@gmail.com> References: <20170331013348.12504-1-micahgalizia@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] Add http cookie tests cases to fate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Micah Galizia MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 0000000..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=Thu01Jan1970000010GMT;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; + + for (int i = 0; get_cookies_tests[i].set_cookie; i++) { + http.cookies = av_strdup(get_cookies_tests[i].set_cookie); + av_dict_free(&http.cookie_dict); + get_cookies(&http, &cookies, get_cookies_tests[i].path, get_cookies_tests[i].domain); + printf("%d) '%s'=>'%s'\n\n", i, http.cookies, cookies); + + if (get_cookies_tests[i].cookie_str == NULL && cookies != NULL) + printf("ERROR: test case %d failed NULL check\n", i); + else if (strcmp(cookies, get_cookies_tests[i].cookie_str)) + printf("ERROR: test case %d failed\n", i); + + av_freep(&http.cookies); + av_free(cookies); + } + + return 0; +} + +static int test_parse_set_cookie(void) { + AVDictionary *d = NULL; + AVDictionaryEntry *e; + const char *set_cookie; + + set_cookie = "good=not_expired; domain=.test.com; path=/; expires=Fri, 12 Mar 2117 02:53:03 GMT; HttpOnly"; + parse_set_cookie(set_cookie, &d); + if (!(e = av_dict_get(d, "expires", NULL, 0))) { + printf("Unable to get expiry\n"); + return -1; + } + printf("'%s'->'%s'|'%s'\n", set_cookie, e->key, e->value); + av_dict_free(&d); + + set_cookie = "good=great"; + parse_set_cookie(set_cookie, &d); + if (!(e = av_dict_get(d, "good", NULL, 0))) { + printf("Unable to get expiry\n"); + return -1; + } + printf("'%s'->'%s'|'%s'\n", set_cookie, e->key, e->value); + av_dict_free(&d); + + return 0; +} + +static int test_parse_cookie(void) { + AVDictionaryEntry *e; + AVDictionary *dict = NULL; + const char *timeless = "name=timeless"; + const char *new = "name=value; Expires=Fri, 12 Mar 2117 02:53:03 GMT"; + const char *old = "name=bad_value; Expires=Thu, 01 Jan 1970 00:00:10 GMT"; + const char *newer = "name=new_value; Expires=Fri, 12 Mar 2117 02:53:04 GMT"; + + parse_cookie(NULL, new, &dict); + e = av_dict_get(dict, "name", NULL, 0); + printf("'%s'->'%s'|'%s'\n", new, e->key, e->value); + + + parse_cookie(NULL, old, &dict); + e = av_dict_get(dict, "name", NULL, 0); + printf("'%s'->'%s'|'%s'\n", old, e->key, e->value); + + parse_cookie(NULL, newer, &dict); + e = av_dict_get(dict, "name", NULL, 0); + printf("'%s'->'%s'|'%s'\n", newer, e->key, e->value); + + av_dict_free(&dict); + parse_cookie(NULL, timeless, &dict); + e = av_dict_get(dict, "name", NULL, 0); + printf("'%s'->'%s'|'%s'\n", timeless, e->key, e->value); + + parse_cookie(NULL, new, &dict); + e = av_dict_get(dict, "name", NULL, 0); + printf("'%s'->'%s'|'%s'\n", timeless, e->key, e->value); + + return 0; +} + +int main(void) { + avformat_network_init(); + + if (test_parse_set_cookie()) { + return 1; + } + + if (test_get_cookies()) { + return 1; + } + + if (test_parse_cookie()) { + return 1; + } + + return 0; +} diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak index cf1ba18..3d211bd 100644 --- a/tests/fate/libavformat.mak +++ b/tests/fate/libavformat.mak @@ -14,6 +14,10 @@ FATE_LIBAVFORMAT-$(CONFIG_SRTP) += fate-srtp fate-srtp: libavformat/tests/srtp$(EXESUF) fate-srtp: CMD = run libavformat/tests/srtp +FATE_LIBAVFORMAT-$(CONFIG_HTTP_PROTOCOL) += fate-http +fate-http: libavformat/tests/http$(EXESUF) +fate-http: CMD = run libavformat/tests/http + FATE_LIBAVFORMAT-yes += fate-url fate-url: libavformat/tests/url$(EXESUF) fate-url: CMD = run libavformat/tests/url @@ -25,3 +29,4 @@ fate-movenc: CMD = run libavformat/tests/movenc FATE_LIBAVFORMAT += $(FATE_LIBAVFORMAT-yes) FATE-$(CONFIG_AVFORMAT) += $(FATE_LIBAVFORMAT) fate-libavformat: $(FATE_LIBAVFORMAT) + diff --git a/tests/ref/fate/http b/tests/ref/fate/http new file mode 100644 index 0000000..82da375 --- /dev/null +++ b/tests/ref/fate/http @@ -0,0 +1,30 @@ +'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' + +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' + +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)' + +6) 'no_spaces=no_big_deal;domain=.test.com;path=/;expires=Fri,12Mar211702:53:03GMT;HttpOnly'=>'no_spaces=no_big_deal' + +7) 'no_spaces_expired=not_ok;domain=.test.com;path=/;expires=Thu01Jan1970000010GMT;HttpOnly'=>'(null)' + +8) 'long=handled;domain=.test.com;path=/;expires=Fri, 12 Mar 2117 02:53:03GMTGMTGMTGMTGMTGMT;HttpOnly'=>'long=handled' + +9) 'bad_start=ok;domain=.test.com;path=/;expires=BooBooBooFri, 12 Mar 2117 02:53:03;HttpOnly'=>'bad_start=ok' + +'name=value; Expires=Fri, 12 Mar 2117 02:53:03 GMT'->'name'|'=value; Expires=Fri, 12 Mar 2117 02:53:03 GMT' +'name=bad_value; Expires=Thu, 01 Jan 1970 00:00:10 GMT'->'name'|'=value; Expires=Fri, 12 Mar 2117 02:53:03 GMT' +'name=new_value; Expires=Fri, 12 Mar 2117 02:53:04 GMT'->'name'|'=new_value; Expires=Fri, 12 Mar 2117 02:53:04 GMT' +'name=timeless'->'name'|'=timeless' +'name=timeless'->'name'|'=value; Expires=Fri, 12 Mar 2117 02:53:03 GMT'