From patchwork Wed May 3 00:29:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 3562 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp2137477vsd; Tue, 2 May 2017 17:30:14 -0700 (PDT) X-Received: by 10.28.47.202 with SMTP id v193mr6088894wmv.131.1493771414784; Tue, 02 May 2017 17:30:14 -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 i37si23257195wra.68.2017.05.02.17.30.14; Tue, 02 May 2017 17:30:14 -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 C6AB7688263; Wed, 3 May 2017 03:30:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f194.google.com (mail-io0-f194.google.com [209.85.223.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0970B68071F for ; Wed, 3 May 2017 03:29:55 +0300 (EEST) Received: by mail-io0-f194.google.com with SMTP id o22so9173155iod.0 for ; Tue, 02 May 2017 17:29:59 -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=wsB2YBNpjOjrP850SDkt9Fi7mGrWJk5V6G1oS1yiZjg=; b=fQ9juGVZw7QgiXBvVV6k4peYGS9mNQ3L0gjWCVjSdJT6zu19g0vIzHmmNn5OT4bXMX GML3LOH1yhsXjZrO8Prf+hUpu7gNVJZXJLCVzt+BhTJoC2dLizrT7ElWAGhkvgRlbQ+b +ujxaO+o7Z3J/IgGkkOZSPxbpM8OffM+NziswI4ax5mnIMdFacL8Jkmfr7w+eaWz1szm 5+E5/SjcYRm9nQuCZejA2478O3fmwSoVDfwdsBhyIM35XM5lSJTku1eqvfMCJBBOEfIt 7TIUZGy03liAJfAKRSjTHG9zdm0nyYwCEGf2aIA3ndNMdIExSWVilfTYflzwTx7eyL25 Qi/A== 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=wsB2YBNpjOjrP850SDkt9Fi7mGrWJk5V6G1oS1yiZjg=; b=Aw351lSz24sYmcUboDqAdvjYQ7fFnu8+DP8UMRQ/I7mNF6ZgjB9DoEWRQ4aV78qu0/ 99FPsArZ3A8fvs767iISQaqx2OEOoszVgSbFvoJhJXYLmQrguzElWU1ttw7yE39MTU0n xrpCMJHeU6jynpxecGXlvudK5ErkBnpTMf1dhrkTsTCAZ7xynrN2Tp5JEKjpUSVNeq4l D03/30PckD3WFmLSuVUBDHlcyxhoN+FmFxcvDmnqqqc8tndJMGHc4IWILkKZuZEAK2T2 OCg+gX0SFAgF3JQdBZpDl9biFpjKYjUHwtdhwlRXGywQSQ0ReHW4JbziqrPHkUIJgILd S8Pg== X-Gm-Message-State: AN3rC/5OiFF6qMooEGEWIU0hT7U6NGrhzb0ijF+MGz6zlJ39bOu9w2wY ScO8q8RYZ41ivQ== X-Received: by 10.107.153.82 with SMTP id b79mr29346231ioe.200.1493771397772; Tue, 02 May 2017 17:29:57 -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 c62sm3485itd.11.2017.05.02.17.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 May 2017 17:29:57 -0700 (PDT) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 May 2017 20:29:25 -0400 Message-Id: <20170503002925.18118-2-micahgalizia@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170503002925.18118-1-micahgalizia@gmail.com> References: <20170403000047.GV4714@nb4> <20170503002925.18118-1-micahgalizia@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] libavformat/tests: 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 | 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 6bdfbe6789..640a348c2f 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -598,6 +598,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 0000000000..76a70ae814 --- /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=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=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 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) { + if (cookies != NULL) + printf("ERROR: test case %d failed NULL check\n", i); + } else if (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=Tue, 19 Jan 2038 03:14:07 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=Tue, 19 Jan 2038 03:14:00 GMT"; + const char *old = "name=bad_value; Expires=Thu, 01 Jan 1970 00:00:10 GMT"; + const char *newer = "name=new_value; Expires=Tue, 19 Jan 2038 03:14:07 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 cf1ba189dd..3d211bd53e 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 0000000000..c6d01fd7c5 --- /dev/null +++ b/tests/ref/fate/http @@ -0,0 +1,30 @@ +'good=not_expired; domain=.test.com; path=/; expires=Tue, 19 Jan 2038 03:14:07 GMT; HttpOnly'->'expires'|'Tue, 19 Jan 2038 03:14:07 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=Tue, 19 Jan 2038 03:14:07 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=Tue, 19-Jan-2038 03:14:07 GMT; HttpOnly'=>'neulion=not_expired' + +3) 'no_day=still_ok; domain=.test.com; path=/; expires=19 Jan 2038 03:14:07 GMT; HttpOnly'=>'no_day=still_ok' + +4) 'unparsable_date=allow_cookie; domain=.test.com; path=/; expires=19 Jon 2038 03:14:07 GMT; HttpOnly'=>'unparsable_date=allow_cookie' + +5) 'different_domain=exclude; domain=.nottest.com; path=/; expires=19 Jan 2038 03:14:07 GMT; HttpOnly'=>'(null)' + +6) 'no_spaces=no_big_deal;domain=.test.com;path=/;expires=Tue,19Jan203803:14:07GMT;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=Tue, 19 Jan 2038 03:14:07GMTGMTGMTGMTGMTGMT;HttpOnly'=>'long=handled' + +9) 'bad_start=ok;domain=.test.com;path=/;expires=BooBooBooTue, 19 Jan 2038 03:14:07;HttpOnly'=>'bad_start=ok' + +'name=value; Expires=Tue, 19 Jan 2038 03:14:00 GMT'->'name'|'=value; Expires=Tue, 19 Jan 2038 03:14:00 GMT' +'name=bad_value; Expires=Thu, 01 Jan 1970 00:00:10 GMT'->'name'|'=value; Expires=Tue, 19 Jan 2038 03:14:00 GMT' +'name=new_value; Expires=Tue, 19 Jan 2038 03:14:07 GMT'->'name'|'=new_value; Expires=Tue, 19 Jan 2038 03:14:07 GMT' +'name=timeless'->'name'|'=timeless' +'name=timeless'->'name'|'=value; Expires=Tue, 19 Jan 2038 03:14:00 GMT'