xref: /lighttpd1.4/src/t/test_http_header.c (revision 71317bc9)
1*71317bc9SGlenn Strauss #include "first.h"
2*71317bc9SGlenn Strauss 
3*71317bc9SGlenn Strauss #undef NDEBUG
4*71317bc9SGlenn Strauss #include <assert.h>
5*71317bc9SGlenn Strauss #include <stdio.h>
6*71317bc9SGlenn Strauss #include <stdlib.h>
7*71317bc9SGlenn Strauss 
8*71317bc9SGlenn Strauss #include "http_header.c"
9*71317bc9SGlenn Strauss 
test_http_header_tables(void)10*71317bc9SGlenn Strauss static void test_http_header_tables (void) {
11*71317bc9SGlenn Strauss     /* verify enum http_header_e presence in http_headers[] */
12*71317bc9SGlenn Strauss     unsigned int u;
13*71317bc9SGlenn Strauss     for (int i = 0; i < 64; ++i) {
14*71317bc9SGlenn Strauss         /* Note: must be kept in sync http_headers[] and http_headers_off[] */
15*71317bc9SGlenn Strauss         /* Note: must be kept in sync with http_header.h enum http_header_e */
16*71317bc9SGlenn Strauss         /* Note: must be kept in sync with http_header.c http_headers[] */
17*71317bc9SGlenn Strauss         /* Note: must be kept in sync h2.c:http_header_lc[] */
18*71317bc9SGlenn Strauss         /* Note: must be kept in sync h2.c:http_header_lshpack_idx[] */
19*71317bc9SGlenn Strauss         /* Note: must be kept in sync h2.c:lshpack_idx_http_header[] */
20*71317bc9SGlenn Strauss         /* switch() statement with each entry in enum http_header_e;
21*71317bc9SGlenn Strauss          * no 'default' case to trigger warning if entry is added */
22*71317bc9SGlenn Strauss         enum http_header_e x = (enum http_header_e)i;
23*71317bc9SGlenn Strauss         switch (x) {
24*71317bc9SGlenn Strauss           case HTTP_HEADER_OTHER:
25*71317bc9SGlenn Strauss           case HTTP_HEADER_ACCEPT:
26*71317bc9SGlenn Strauss           case HTTP_HEADER_ACCEPT_ENCODING:
27*71317bc9SGlenn Strauss           case HTTP_HEADER_ACCEPT_LANGUAGE:
28*71317bc9SGlenn Strauss           case HTTP_HEADER_ACCEPT_RANGES:
29*71317bc9SGlenn Strauss           case HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN:
30*71317bc9SGlenn Strauss           case HTTP_HEADER_AGE:
31*71317bc9SGlenn Strauss           case HTTP_HEADER_ALLOW:
32*71317bc9SGlenn Strauss           case HTTP_HEADER_ALT_SVC:
33*71317bc9SGlenn Strauss           case HTTP_HEADER_ALT_USED:
34*71317bc9SGlenn Strauss           case HTTP_HEADER_AUTHORIZATION:
35*71317bc9SGlenn Strauss           case HTTP_HEADER_CACHE_CONTROL:
36*71317bc9SGlenn Strauss           case HTTP_HEADER_CONNECTION:
37*71317bc9SGlenn Strauss           case HTTP_HEADER_CONTENT_ENCODING:
38*71317bc9SGlenn Strauss           case HTTP_HEADER_CONTENT_LENGTH:
39*71317bc9SGlenn Strauss           case HTTP_HEADER_CONTENT_LOCATION:
40*71317bc9SGlenn Strauss           case HTTP_HEADER_CONTENT_RANGE:
41*71317bc9SGlenn Strauss           case HTTP_HEADER_CONTENT_SECURITY_POLICY:
42*71317bc9SGlenn Strauss           case HTTP_HEADER_CONTENT_TYPE:
43*71317bc9SGlenn Strauss           case HTTP_HEADER_COOKIE:
44*71317bc9SGlenn Strauss           case HTTP_HEADER_DATE:
45*71317bc9SGlenn Strauss           case HTTP_HEADER_DNT:
46*71317bc9SGlenn Strauss           case HTTP_HEADER_ETAG:
47*71317bc9SGlenn Strauss           case HTTP_HEADER_EXPECT:
48*71317bc9SGlenn Strauss           case HTTP_HEADER_EXPECT_CT:
49*71317bc9SGlenn Strauss           case HTTP_HEADER_EXPIRES:
50*71317bc9SGlenn Strauss           case HTTP_HEADER_FORWARDED:
51*71317bc9SGlenn Strauss           case HTTP_HEADER_HOST:
52*71317bc9SGlenn Strauss           case HTTP_HEADER_HTTP2_SETTINGS:
53*71317bc9SGlenn Strauss           case HTTP_HEADER_IF_MATCH:
54*71317bc9SGlenn Strauss           case HTTP_HEADER_IF_MODIFIED_SINCE:
55*71317bc9SGlenn Strauss           case HTTP_HEADER_IF_NONE_MATCH:
56*71317bc9SGlenn Strauss           case HTTP_HEADER_IF_RANGE:
57*71317bc9SGlenn Strauss           case HTTP_HEADER_IF_UNMODIFIED_SINCE:
58*71317bc9SGlenn Strauss           case HTTP_HEADER_LAST_MODIFIED:
59*71317bc9SGlenn Strauss           case HTTP_HEADER_LINK:
60*71317bc9SGlenn Strauss           case HTTP_HEADER_LOCATION:
61*71317bc9SGlenn Strauss           case HTTP_HEADER_ONION_LOCATION:
62*71317bc9SGlenn Strauss           case HTTP_HEADER_P3P:
63*71317bc9SGlenn Strauss           case HTTP_HEADER_PRAGMA:
64*71317bc9SGlenn Strauss           case HTTP_HEADER_PRIORITY:
65*71317bc9SGlenn Strauss           case HTTP_HEADER_RANGE:
66*71317bc9SGlenn Strauss           case HTTP_HEADER_REFERER:
67*71317bc9SGlenn Strauss           case HTTP_HEADER_REFERRER_POLICY:
68*71317bc9SGlenn Strauss           case HTTP_HEADER_SERVER:
69*71317bc9SGlenn Strauss           case HTTP_HEADER_SET_COOKIE:
70*71317bc9SGlenn Strauss           case HTTP_HEADER_STATUS:
71*71317bc9SGlenn Strauss           case HTTP_HEADER_STRICT_TRANSPORT_SECURITY:
72*71317bc9SGlenn Strauss           case HTTP_HEADER_TE:
73*71317bc9SGlenn Strauss           case HTTP_HEADER_TRANSFER_ENCODING:
74*71317bc9SGlenn Strauss           case HTTP_HEADER_UPGRADE:
75*71317bc9SGlenn Strauss           case HTTP_HEADER_UPGRADE_INSECURE_REQUESTS:
76*71317bc9SGlenn Strauss           case HTTP_HEADER_USER_AGENT:
77*71317bc9SGlenn Strauss           case HTTP_HEADER_VARY:
78*71317bc9SGlenn Strauss           case HTTP_HEADER_WWW_AUTHENTICATE:
79*71317bc9SGlenn Strauss           case HTTP_HEADER_X_CONTENT_TYPE_OPTIONS:
80*71317bc9SGlenn Strauss           case HTTP_HEADER_X_FORWARDED_FOR:
81*71317bc9SGlenn Strauss           case HTTP_HEADER_X_FORWARDED_PROTO:
82*71317bc9SGlenn Strauss           case HTTP_HEADER_X_FRAME_OPTIONS:
83*71317bc9SGlenn Strauss           case HTTP_HEADER_X_XSS_PROTECTION:
84*71317bc9SGlenn Strauss             for (u = 0; u < sizeof(http_headers)/sizeof(*http_headers); ++u) {
85*71317bc9SGlenn Strauss                 if (i == http_headers[u].key) {
86*71317bc9SGlenn Strauss                     assert(x == http_header_hkey_get(http_headers[u].value,
87*71317bc9SGlenn Strauss                                                      http_headers[u].vlen));
88*71317bc9SGlenn Strauss                     assert(x == http_header_hkey_get_lc(http_headers[u].value,
89*71317bc9SGlenn Strauss                                                         http_headers[u].vlen));
90*71317bc9SGlenn Strauss                     break;
91*71317bc9SGlenn Strauss                 }
92*71317bc9SGlenn Strauss             }
93*71317bc9SGlenn Strauss             assert(u < sizeof(http_headers)/sizeof(*http_headers));
94*71317bc9SGlenn Strauss             break;
95*71317bc9SGlenn Strauss         }
96*71317bc9SGlenn Strauss     }
97*71317bc9SGlenn Strauss 
98*71317bc9SGlenn Strauss     /* verify http_headers_off[] */
99*71317bc9SGlenn Strauss     for (u = 0; u < sizeof(http_headers)/sizeof(*http_headers); ++u) {
100*71317bc9SGlenn Strauss         if (http_headers[u].vlen == 0) break;
101*71317bc9SGlenn Strauss         int8_t x = http_headers_off[http_headers[u].vlen];
102*71317bc9SGlenn Strauss         assert((unsigned int)x <= u);
103*71317bc9SGlenn Strauss         assert(http_headers[x].vlen == http_headers[u].vlen);
104*71317bc9SGlenn Strauss     }
105*71317bc9SGlenn Strauss }
106*71317bc9SGlenn Strauss 
107*71317bc9SGlenn Strauss void test_http_header (void);
test_http_header(void)108*71317bc9SGlenn Strauss void test_http_header (void)
109*71317bc9SGlenn Strauss {
110*71317bc9SGlenn Strauss     test_http_header_tables();
111*71317bc9SGlenn Strauss }
112