test-http-date.c revision ba592dc74a004ad47dfe58edcfc1ca7297551e39
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2013-2014 Dovecot authors, see the included COPYING file */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Valid date tests */
4ead43ecc06d10047998966c4dc0b142ecce4b66Timo Sirainenstatic const struct http_date_test valid_date_tests[] = {
1d4f710106fb498750456724628da6063e012e6dTimo Sirainen /* Preferred format: */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Obsolete formats: */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen .date_in = "Wednesday, 02-Jun-82 16:06:23 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen .date_in = "Thursday, 23-May-02 12:16:24 GMT",
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainenstatic const unsigned int valid_date_test_count = N_ELEMENTS(valid_date_tests);
d3d769026fae5d21c2d29614d3bc4579e8d79e81Timo Sirainen unsigned int i;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen for (i = 0; i < valid_date_test_count; i++) T_BEGIN {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const struct tm *tm = &valid_date_tests[i].tm;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen date_out = valid_date_tests[i].date_out == NULL ?
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen test_begin(t_strdup_printf("http date valid [%d]", i));
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ((const unsigned char *)date_in, strlen(date_in), &ptm);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen test_out(t_strdup_printf("parse %s", date_in), result);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen bool equal = tm->tm_year == ptm.tm_year && tm->tm_mon == ptm.tm_mon &&
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen tm->tm_mday == ptm.tm_mday && tm->tm_hour == ptm.tm_hour &&
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen tm->tm_min == ptm.tm_min && tm->tm_sec == ptm.tm_sec;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen test_out_reason("valid create", strcmp(date_out, pdate_out) == 0,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Invalid date tests */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic const char *invalid_date_tests[] = {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mom, 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon; 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 90 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 090 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Lul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 July 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 22018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 032:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:224:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:239 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02;24:29 GMT",
05e55893a799de645fc8cd2203d6013f0e0f1b79Timo Sirainen "Mon, 09 Jul 2018 02:24;29 GMT",
ec23e16ed879e289d12c6e1a5f9745dd3979004aTimo Sirainen "Mon, 09 Jul 2018 45:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:90:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:84 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 UTC",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GM",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Mon, 09 Jul 2018 02:24:29 GMTREE",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thu, 23-May-02 12:16:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday; 23-May-02 12:16:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 223-May-02 12:16:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 23-Mays-02 12:16:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 23-May-2002 12:16:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 23-May-02 122:16:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 23-May-02 12:164:24 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 23-May-02 12:16:244 GMT",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Thursday, 23-May-02 12:16:24 EET",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sunday Nov 6 08:49:37 1994",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun Nov 6 08:49:37 1994",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun November 6 08:49:37 1994",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun Nov 6 08:49:37 1994",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun Nov 16 08:49:37 1994",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun Nov 16 08:49:37 1994",
ec23e16ed879e289d12c6e1a5f9745dd3979004aTimo Sirainen "Sun Nov 6 082:49:37 1994",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun Nov 6 08:492:37 1994",
ec23e16ed879e289d12c6e1a5f9745dd3979004aTimo Sirainen "Sun Nov 6 08:49:137 1994",
ec23e16ed879e289d12c6e1a5f9745dd3979004aTimo Sirainen "Sun Nov 6 08:49:37 19914",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Sun Nov 6 08:49:37 0000",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic const unsigned int invalid_date_test_count = N_ELEMENTS(invalid_date_tests);
ec23e16ed879e289d12c6e1a5f9745dd3979004aTimo Sirainen unsigned int i;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen for (i = 0; i < invalid_date_test_count; i++) T_BEGIN {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen test_begin(t_strdup_printf("http date invalid [%d]", i));
ec23e16ed879e289d12c6e1a5f9745dd3979004aTimo Sirainen ((const unsigned char *)date_in, strlen(date_in), &tm);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen test_out(t_strdup_printf("parse %s", date_in), !result);
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen static void (*test_functions[])(void) = {