~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib-http/test-http-date.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "test-lib.h"
 
4
#include "test-common.h"
 
5
#include "http-date.h"
 
6
 
 
7
#include <time.h>
 
8
 
 
9
struct http_date_test {
 
10
        const char *date_in;
 
11
        const char *date_out;
 
12
 
 
13
        struct tm tm;
 
14
};
 
15
 
 
16
/* Valid date tests */
 
17
struct http_date_test valid_date_tests[] = {
 
18
        /* Preferred format: */
 
19
        { 
 
20
                .date_in = "Sun, 11 Nov 2007 09:42:43 GMT",
 
21
                .tm = {
 
22
                        .tm_year = 107, .tm_mon = 10, .tm_mday = 11,
 
23
                        .tm_hour = 9, .tm_min = 42, .tm_sec = 43 },
 
24
        },{ 
 
25
                .date_in = "Mon, 17 Aug 1992 13:06:27 GMT",
 
26
                .tm = {
 
27
                        .tm_year = 92, .tm_mon = 7, .tm_mday = 17,
 
28
                        .tm_hour = 13, .tm_min = 06, .tm_sec = 27 },
 
29
        },{ 
 
30
                .date_in = "Tue, 03 Sep 1974 04:38:08 GMT",
 
31
                .tm = {
 
32
                        .tm_year = 74, .tm_mon = 8, .tm_mday = 3,
 
33
                        .tm_hour = 4, .tm_min = 38, .tm_sec = 8 },
 
34
        },{ 
 
35
                .date_in = "Wed, 07 May 1980 06:20:42 GMT",
 
36
                .tm = {
 
37
                        .tm_year = 80, .tm_mon = 4, .tm_mday = 7,
 
38
                        .tm_hour = 6, .tm_min = 20, .tm_sec = 42 },
 
39
        },{ 
 
40
                .date_in = "Thu, 15 Oct 1987 18:30:14 GMT",
 
41
                .tm = {
 
42
                        .tm_year = 87, .tm_mon = 9, .tm_mday = 15,
 
43
                        .tm_hour = 18, .tm_min = 30, .tm_sec = 14 },
 
44
        },{ 
 
45
                .date_in = "Fri, 20 Dec 1996 00:20:07 GMT",
 
46
                .tm = {
 
47
                        .tm_year = 96, .tm_mon = 11, .tm_mday = 20,
 
48
                        .tm_hour = 0, .tm_min = 20, .tm_sec = 7 },
 
49
        },{ 
 
50
                .date_in = "Sat, 19 Jan 2036 19:52:18 GMT",
 
51
                .tm = {
 
52
                        .tm_year = 136, .tm_mon = 0, .tm_mday = 19,
 
53
                        .tm_hour = 19, .tm_min = 52, .tm_sec = 18 },
 
54
        },{ 
 
55
                .date_in = "Mon, 17 Apr 2006 14:41:45 GMT",
 
56
                .tm = {
 
57
                        .tm_year = 106, .tm_mon = 3, .tm_mday = 17,
 
58
                        .tm_hour = 14, .tm_min = 41, .tm_sec = 45 },
 
59
        },{ 
 
60
                .date_in = "Sun, 06 Mar 2011 16:18:41 GMT",
 
61
                .tm = {
 
62
                        .tm_year = 111, .tm_mon = 2, .tm_mday = 6,
 
63
                        .tm_hour = 16, .tm_min = 18, .tm_sec = 41 },
 
64
        },{ 
 
65
                .date_in = "Sat, 14 Jun 1975 16:09:30 GMT",
 
66
                .tm = {
 
67
                        .tm_year = 75, .tm_mon = 5, .tm_mday = 14,
 
68
                        .tm_hour = 16, .tm_min = 9, .tm_sec = 30 },
 
69
        },{ 
 
70
                .date_in = "Fri, 05 Feb 2027 06:53:58 GMT",
 
71
                .tm = {
 
72
                        .tm_year = 127, .tm_mon = 1, .tm_mday = 5,
 
73
                        .tm_hour = 6, .tm_min = 53, .tm_sec = 58 },
 
74
        },{ 
 
75
                .date_in = "Mon, 09 Jul 2018 02:24:29 GMT",
 
76
                .tm = {
 
77
                        .tm_year = 118, .tm_mon = 6, .tm_mday = 9,
 
78
                        .tm_hour = 2, .tm_min = 24, .tm_sec = 29 },
 
79
 
 
80
        /* Obsolete formats: */
 
81
        },{
 
82
                .date_in = "Wednesday, 02-Jun-82 16:06:23 GMT",
 
83
                .date_out = "Wed, 02 Jun 1982 16:06:23 GMT",
 
84
                .tm = {
 
85
                        .tm_year = 82, .tm_mon = 5, .tm_mday = 2,
 
86
                        .tm_hour = 16, .tm_min = 6, .tm_sec = 23 },
 
87
        },{
 
88
                .date_in = "Thursday, 23-May-02 12:16:24 GMT",
 
89
                .date_out = "Thu, 23 May 2002 12:16:24 GMT",
 
90
                .tm = {
 
91
                        .tm_year = 102, .tm_mon = 4, .tm_mday = 23,
 
92
                        .tm_hour = 12, .tm_min = 16, .tm_sec = 24 },
 
93
        },{
 
94
                .date_in = "Sun Nov  6 08:49:37 1994",
 
95
                .date_out = "Sun, 06 Nov 1994 08:49:37 GMT",
 
96
                .tm = {
 
97
                        .tm_year = 94, .tm_mon = 10, .tm_mday = 6,
 
98
                        .tm_hour = 8, .tm_min = 49, .tm_sec = 37 },
 
99
        },{
 
100
                .date_in = "Mon Apr 30 02:45:01 2012",
 
101
                .date_out = "Mon, 30 Apr 2012 02:45:01 GMT",
 
102
                .tm = {
 
103
                        .tm_year = 112, .tm_mon = 3, .tm_mday = 30,
 
104
                        .tm_hour = 2, .tm_min = 45, .tm_sec = 01 },
 
105
        }
 
106
};
 
107
 
 
108
unsigned int valid_date_test_count = N_ELEMENTS(valid_date_tests);
 
109
 
 
110
static void test_http_date_valid(void)
 
111
{
 
112
        unsigned int i;
 
113
 
 
114
        for (i = 0; i < valid_date_test_count; i++) T_BEGIN {
 
115
                const char *date_in, *date_out, *pdate_out;
 
116
                struct tm *tm = &valid_date_tests[i].tm, ptm;
 
117
                bool result;
 
118
 
 
119
                date_in = valid_date_tests[i].date_in;
 
120
                date_out = valid_date_tests[i].date_out == NULL ?
 
121
                        date_in : valid_date_tests[i].date_out;
 
122
 
 
123
                test_begin(t_strdup_printf("http date valid [%d]", i));
 
124
 
 
125
                result = http_date_parse_tm
 
126
                        ((const unsigned char *)date_in, strlen(date_in), &ptm);
 
127
                test_out(t_strdup_printf("parse %s", date_in), result);
 
128
                if (result) {
 
129
                        bool equal = tm->tm_year == ptm.tm_year && tm->tm_mon == ptm.tm_mon &&
 
130
                                tm->tm_mday == ptm.tm_mday && tm->tm_hour == ptm.tm_hour &&
 
131
                                tm->tm_min == ptm.tm_min && tm->tm_sec == ptm.tm_sec;
 
132
 
 
133
                        test_out("valid timestamp", equal);
 
134
 
 
135
                        pdate_out = http_date_create_tm(&ptm);
 
136
                        test_out_reason("valid create", strcmp(date_out, pdate_out) == 0,
 
137
                                pdate_out);
 
138
                }
 
139
 
 
140
                test_end();
 
141
        } T_END;
 
142
}
 
143
 
 
144
/* Invalid date tests */
 
145
const char *invalid_date_tests[] = {
 
146
        "Mom, 09 Jul 2018 02:24:29 GMT",
 
147
        "Mon; 09 Jul 2018 02:24:29 GMT",
 
148
        "Mon,  09 Jul 2018 02:24:29 GMT",
 
149
        "Mon, 90 Jul 2018 02:24:29 GMT",
 
150
        "Mon, 090 Jul 2018 02:24:29 GMT",
 
151
        "Mon, 09  Jul 2018 02:24:29 GMT",
 
152
        "Mon, 09 Lul 2018 02:24:29 GMT",
 
153
        "Mon, 09 July 2018 02:24:29 GMT",
 
154
        "Mon, 09 Jul  2018 02:24:29 GMT",
 
155
        "Mon, 09 Jul 22018 02:24:29 GMT",
 
156
        "Mon, 09 Jul 2018  02:24:29 GMT",
 
157
        "Mon, 09 Jul 2018 032:24:29 GMT",
 
158
        "Mon, 09 Jul 2018 02:224:29 GMT",
 
159
        "Mon, 09 Jul 2018 02:24:239 GMT",
 
160
        "Mon, 09 Jul 2018 02;24:29 GMT",
 
161
        "Mon, 09 Jul 2018 02:24;29 GMT",
 
162
        "Mon, 09 Jul 2018 45:24:29 GMT",
 
163
        "Mon, 09 Jul 2018 02:90:29 GMT",
 
164
        "Mon, 09 Jul 2018 02:24:84 GMT",
 
165
        "Mon, 09 Jul 2018 02:24:29  GMT",
 
166
        "Mon, 09 Jul 2018 02:24:29 UTC",
 
167
        "Mon, 09 Jul 2018 02:24:29 GM",
 
168
        "Mon, 09 Jul 2018 02:24:29 GMTREE",
 
169
        "Thu, 23-May-02 12:16:24 GMT",
 
170
        "Thursday; 23-May-02 12:16:24 GMT",
 
171
        "Thursday, 223-May-02 12:16:24 GMT",
 
172
        "Thursday, 23-Mays-02 12:16:24 GMT",
 
173
        "Thursday, 23-May-2002 12:16:24 GMT",
 
174
        "Thursday, 23-May-02 122:16:24 GMT",
 
175
        "Thursday, 23-May-02 12:164:24 GMT",
 
176
        "Thursday, 23-May-02 12:16:244 GMT",
 
177
        "Thursday, 23-May-02 12:16:24 EET",
 
178
        "Sunday Nov  6 08:49:37 1994",
 
179
        "Sun  Nov  6 08:49:37 1994",
 
180
        "Sun November  6 08:49:37 1994",
 
181
        "Sun Nov 6 08:49:37 1994",
 
182
        "Sun Nov  16 08:49:37 1994",
 
183
        "Sun Nov 16  08:49:37 1994",
 
184
        "Sun Nov  6 082:49:37 1994",
 
185
        "Sun Nov  6 08:492:37 1994",
 
186
        "Sun Nov  6 08:49:137 1994",
 
187
        "Sun Nov  6 08:49:37 19914",
 
188
        "Sun Nov  6 08:49:37 0000",
 
189
};
 
190
 
 
191
unsigned int invalid_date_test_count = N_ELEMENTS(invalid_date_tests);
 
192
 
 
193
static void test_http_date_invalid(void)
 
194
{
 
195
        unsigned int i;
 
196
 
 
197
        for (i = 0; i < invalid_date_test_count; i++) T_BEGIN {
 
198
                const char *date_in;
 
199
                struct tm tm;
 
200
                bool result;
 
201
 
 
202
                date_in = invalid_date_tests[i];
 
203
 
 
204
                test_begin(t_strdup_printf("http date invalid [%d]", i));
 
205
 
 
206
                result = http_date_parse_tm
 
207
                        ((const unsigned char *)date_in, strlen(date_in), &tm);
 
208
                test_out(t_strdup_printf("parse %s", date_in), !result);
 
209
 
 
210
                test_end();
 
211
        } T_END;
 
212
}
 
213
 
 
214
int main(void)
 
215
{
 
216
        static void (*test_functions[])(void) = {
 
217
                test_http_date_valid,
 
218
                test_http_date_invalid,
 
219
                NULL
 
220
        };
 
221
        return test_run(test_functions);
 
222
}